Contents

Libavfilter

Lavfi (Libavfilter) is a library used by ffmpeg to provide a virtual input device that can be used to create video and audio streams.

To use with ffmpeg, you can use the -f lavfi option to specify the input format as lavfi. For example, if you have ffmpeg installed, open a terminal and run the following command.

ffplay -f lavfi color=c=pink

This will play a video with a pink background indefinitely until you hit q or Ctrl+C to exit the command.

if you want to save the video to a file, you can use the -i option with the ffmpeg command to tell it to use lavfi as an input stream and -t option to specify the duration of the video.

For example to create a 10 second simple video with a pink background, you can use the following command.

ffmpeg -f lavfi -i color=pink -t 10 output.mp4

This will create a 10 second video with a pink background and render it without saving it into a file.

Video Sources

There is a lot of video sources that you can use with lavfi, you can see the full list in the official documentation, but here are some of the most common and useful ones.

TestSrc

You can also use the testsrc input to create a video with a test pattern.

ffmpeg -f lavfi -i testsrc -t 10 testsrc.mp4

which will create and show a video stream using a testsrc stream that is bundled with the lavfi filter. The output will be similar to the following.

You can specify the size of the video and other parameters as well.

ffplay -f lavfi -i testsrc=s=1280x720 -t 10

SmpteBars

There is also smptebars input that you can use to create a video with a smpte bars pattern.

ffplay -f lavfi -i smptebars

This will play a video with a smpte bars pattern indefinitely until you hit q or Ctrl+C to exit the command.

Again you can save this to a file (with 10-second duration) using the following command

ffmpeg -f lavfi -i smptebars -t 10 smptebars.mp4

Mandelbrot

Another cool filter is the mandelbrot filter that you can use to create a video with a mandelbrot fractal pattern.

ffplay -f lavfi -i mandelbrot

Game of Life

There is also a life filter that you can use to create a video with a Conway’s game of life pattern.

In its simplest and most boring form, you can use the following command to create a video with a game of life pattern.

ffplay -f lavfi life
ffplay -f lavfi life=s=300x200:mold=10:r=6:ratio=0.1:death_color=#C83232:life_color=#00ff00,scale=1200:800:flags=16

This will create a video with a game of life pattern with a 10% ratio of live cells, a 6 second refresh rate, a 300x200 grid, and a 1200x800 resolution resulting in a video similar to the following. You can read more about the parameters in the official documentation.

Audio Sources

There is also a lot of audio sources that you can use with lavfi, you can see the full list in the official documentation, but here are some of the most common and useful ones.

Sine

You can use the sine input to create a sine wave audio stream.

ffplay -f lavfi sine

You can specify the frequency of the sine wave as follows.

ffplay -f lavfi sine=frequency=440

You can also specify a beep to happen at specific time intervals.

ffplay -f lavfi sine=frequency=440:beep_factor=4

This will play a sine wave with a frequency of 440Hz indefinitely with beep every second with frequency = 4*440.

Conclusion

Lavfi is a powerful library that you can use to create video and audio streams with ffmpeg. You can use it to create simple test videos and audio streams for testing purposes as well as apply very advanced filters to audio and video streams. You can read more about it in the official documentation.