Simulating TV noise
Asked Answered
P

4

30

I have googled a bit but was never able to find an answer. What should be my first approach to simulate a video and audio noise from TV on screen? I mean, when my TV antenna is removed but the TV is still on (like they show in Japanese horror movies sometimes). I can use ffmpeg or any other technique but what is the simplest possible form of the signal?

Pattiepattin answered 3/4, 2013 at 15:53 Comment(2)
Assign each pixel in the video frame a random RGB value. Repeat for the next frame. For sound (and video), you basically want to generate white noise. See also https://mcmap.net/q/472248/-generate-white-noise-image-in-cAlarum
I’m voting to close this question because , as the ffmpeg tag states: Only questions about programmatic use of the FFmpeg libraries, API, or tools are on topic. Questions about interactive use of the command line tool should be asked on superuser.com or video.stackexchange.com. Please delete this.Conjugal
I
84

Create video and audio noise, artifacts, and errors with ffmpeg

Noise

Using filters

The geq (video "generic equation") filter (with nullsrc as its "blank canvas") can create video noise, and the aevalsrc filter can create white noise audio:

mono noise

ffmpeg -f lavfi -i nullsrc=s=1280x720 -filter_complex \
"geq=random(1)*255:128:128;aevalsrc=-2+random(0)" \
-t 5 output.mkv

Note that this will create black and white video noise.

Using /dev/urandom

Although I recommend using the geq filter you can also use /dev/urandom to generate video and audio noise (Windows users will have to use the geq filter as shown above). This is a small screeenshot, but of course the video will not be a static image:

colored noise

ffmpeg -f rawvideo -video_size 1280x720 -pixel_format yuv420p -framerate 25 \
-i /dev/urandom -ar 48000 -ac 2 -f s16le -i /dev/urandom -codec:a copy \
-t 5 output.mkv

This will create color video noise. If you just want black and white you can add the hue filter.

mono noise

ffmpeg -f rawvideo -video_size 1280x720 -pixel_format yuv420p -framerate 25 \
-i /dev/urandom -ar 48000 -ac 2 -f s16le -i /dev/urandom -codec:a copy \
-t 5 -vf hue=s=0 output.mkv

Adding random visual noise and errors to an existing video

Using the noise bitstream filter:

original imageenter image description here Original and modified versions.

ffmpeg -i input.mp4 -codec:v huffyuv -bsf:v noise -codec:a copy noise.mkv

According to the documentation:

A bitstream filter operates on the encoded stream data, and performs bitstream level modifications without performing decoding.

This bitstream filter can accept a value to increase or decrease the amount of noise. It's inverse, so a higher number is less noise, and 1 is the lowest number and therefore the most noise. You will need to experiment to see what works best for you.

This first example stream copied the audio and only glitched the video, but you can apply the filter to both audio and video by removing the stream specifier:

ffmpeg -i input.mp4 -codec:v huffyuv -c:a pcm_s16le -bsf noise=1000000 noise.mkv

Or provide separate values for video and audio:

ffmpeg -i input.mp4 -codec:v huffyuv -c:a pcm_s16le -bsf:v noise=1000000 -bsf:a noise=100 noise.mkv

This seems to work well with rawvideo or huffyuv for video, and pcm_s16le for audio, but I recommend experimenting. See lossless vs corruption (notes) for a video showing how different encoders react to noise corruption.

The output noise.mkv is damaged, but you can re-encode it so it will work in your player:

ffmpeg -i noise.mkv -codec:v libx264 -pix_fmt yuv420p output.mkv

See the H.264 and AAC encoding guides on the FFmpeg Wiki for more encoding info.

Macroblock effect

There are several methods to do this, but in this example the noise bitstream filter will be used. Output to MPEG-2 video in TS as this will be more susceptible to the desired effect:

ffmpeg -i input.mp4 -bsf:v noise -c:v mpeg2video -q:v 2 -c:a copy macroblock.ts

Increase -q:v value to ~20 if you want a more "encoded" look. Add a noise value as shown in the section above if you want more noise.

The output macroblock.ts is damaged, but you can re-encode it so it will work in your player:

ffmpeg -i macroblock.ts -codec:v libx264 -pix_fmt yuv420p output.mp4

See the section above for more info on the noise bitstream filter.

Results may vary, so you may not get what you're looking for. See hex editor method below.

Using a hex editor

Another method is to use a hex editor which you may find to be easier and more controllable and more consistent. See:


Forcing a pixel format

You can lie to ffmpeg and make it think that the colorspace and chroma subsampling is different that it actually is resulting in strange, error-like effects.

original imageenter image description here Original and modified versions.

  1. Probe your input.

    ffmpeg -i original.mp4
    

    Note the frame rate and video frame size.

  2. Refer to ffmpeg -pix_fmts and choose one of the available formats such as yuv420p16le.

  3. Create rawvideo and pipe it to another ffmpeg instance:

    ffmpeg -loglevel error -i original.mp4 -f rawvideo - | ffmpeg -y -f rawvideo -framerate 25 -video_size 1280x720 -pixel_format yuv420p16le -i - -pix_fmt yuv420p video.mp4
    

    The -framerate and -video_size values were copied from the original input file information shown in the console output of step 1. Of course you can also manipulate these for various effects.

  4. Mux audio if desired

    ffmpeg -i video.mp4 -i original.mp4 -map 0 -map 1:a -c copy output.mp4
    
Iconoduly answered 3/4, 2013 at 18:26 Comment(7)
note that /dev/urandom provides secure random data, and thus may not be able to provide data fast enough for a given picture size and frame rate. See blog.kylemanna.com/linux/simple-and-fast-random-data-generator or consider using the filter approachPlutonian
how to do the same but with just ffplay ?Hives
@Hives Which method do you want to do in ffplay?Iconoduly
simulating tv noise using /dev/urandom (or a faster program I wrote)... like dd if=/dev/urandom|ffplay -f u8 -ar 48000 -ac 1 - ## or ## dd if=/dev/urandom|ffplay -fs -f rawvideo -pixel_format gray8 -video_size 1920x1080 -framerate 30 - ### I just can't find a way to have BOTH togetherHives
@Hives Should be asked as a new question.Iconoduly
I created a tool using the macroblock effect and huffyuv video format. This method takes a few tries to get the desired effect davidclews.com/article/288.html you can see the ffmpeg code in the browsers console. The mpeg2video format is far more effective in creating a decent video file.Syndicalism
i created a tool using the geq=random(1)*255:128:128;aevalsrc=-2+random(0) but it's not a prefect loop. How can i make this nearly transparent loop, you can hear it here davidclews.com/article/289.htmlSyndicalism
J
0

yes, you can use ffmpeg:

ffmpeg -s 640x480 -t 8 \
-f rawvideo -pix_fmt gray16be -i /dev/urandom \
-f s32le -i /dev/urandom \
output.mp4
Jotham answered 15/2, 2017 at 22:54 Comment(3)
how to do the same but with just ffplay ?Hives
@Hives i have tested it right now, seems just have to replace ffmpeg with ffplayJotham
nope.. it works if I pipe ffmep to ffplay... I can't seem to find a single ffplay command... this works: cat /dev/urandom| ffmpeg -f rawvideo -pixel_format rgb24 -video_size 1920x1080 -framerate 60 -i - -f s16le -ar 48000 -ac 2 -i - -c:a pcm_s16le -c:v rawvideo -f avi -|ffplay -fs - ## but I wish to do it without the pipe using only ffplayHives
H
0

Just for comparison, I tested 3 different ways to generate pseudorandom numbers. As you can see the speed is very different. For high badwidth I suggest the first solution. You can find the source here: https://github.com/Zibri/rand

By the way, the source can be further optimized to gain ever better speeds.

$ ./rand|pv -S -s 2G >/dev/null
2,00GiB 0:00:01 [1,58GiB/s] [========================================================================>] 100%            

$ cat /dev/urandom|pv -S -s 2G >/dev/null
2,00GiB 0:00:11 [ 178MiB/s] [========================================================================>] 100%            

$ dd if=/dev/zero bs=1k count=2M 2>/dev/null | openssl enc -rc4-40 -pass pass:weak |pv -S -s 2G >/dev/null
2,00GiB 0:00:04 [ 413MiB/s] [========================================================================>] 100%            
Hives answered 17/3, 2019 at 18:26 Comment(0)
A
-2

it's white noise

create images in grayscale with a random intensity and audio with completely random samples

Abrahamsen answered 3/4, 2013 at 15:55 Comment(1)
@LordNeckbeard I got me some examples in that other question cited in a comment to my questionPattiepattin

© 2022 - 2024 — McMap. All rights reserved.