« ffmpeg filters

  • Most of the common filters come from a library inside of a ffmpeg called libavfilter.
  • Filtering back can have one or more inputs, and it can also have one or more outputs.
  • Inputs and outputs can be given custom names or labels so that those can be easily referred.

Filter Graph(-vf)

-vf is used for simple video processing graphs with a single input and a single output.

1ffmpeg -v error -y -i bullfinch.mp4 -vf "split[bg][ol];[bg]scale=width=1920:height=1080,format=gray[bg_out];[ol]scale=-1:480,hflip[ol_out];[bg_out][ol_out]overlay=x=W-w:y=(H-h)/2" anish.mp4
  • First, we split the input to get two identical video streams and we label them as bg for background and ol for overlay so that we can easily refer to them later.
  • Then we scale the background up and send it through a format filter to make it grey. we elabeled the output of this chain as bg_out.
  • On the other chain, we scaled the overlay down and fliped it horizontally to form the smaller overlay stream, we call it ol_out.
  • Finally, we combine the outputs of these two intermediate chains with an overlay filter, we refer to the previously labeled outputs to connect them as the inputs of the overlay filter.

Filter Graph(-af)

  • Similar to -vf -af is used for simple audio processing filter graphs that can have only one input and one output.
1ffmpeg -v error -y -i four_channel_stream.wav -af "asplit=2[voice][bg];[voice]volume=volume=2,pan=mono|c0=c0+c1[voice_out];[bg]volume=volume=0.5,pan=mono|c0=c2+c3[bg_out];[voice_out][bg_out]amerge=inputs=2" audio_out.wav
  • Let's assume we have a four channel audio stream with the first two channels containing voice and the third and fourth channels containing some background sounds.
  • So first, we are duplicating the input audio with a split filter.
  • Then we are doubling the volume on one chain and using the pan filter to mix the first two channels into one channel.
  • We are reducing the volume by half and mixing the third and fourth channels into one.
  • Finally, we use the amerge filter to get a single audio output with two channels, first containing the louder voice mix, and the second one has a quieter background audio.

Filter Graph(-filter_complex)

  • Multiple inputs and outputs, including both video and audio.

  • Suppose we have a background video, an image of a logo and a four channel audio as inputs. And we would like to produce two video outputs and one audio audio output from these.

  • We can call the bigger video output HD for high definition and we have named the other as as SD, which has smaller width and height.

  • Both of these videos should have the logo placed on the bottom right corner so that it is a common operation between the two video output's.

  • We would also like to produce an audio only output with the four channels from the input, down mixed into a two channel stereo.

  • So all in all, we need a filter graph with three inputs and three outputs.