typed-ffmpeg icon indicating copy to clipboard operation
typed-ffmpeg copied to clipboard

different between -vf, -af, -filter_complex

Open lucemia opened this issue 1 year ago • 0 comments

In FFmpeg, the commands -filter (or its aliases -vf for video filters and -af for audio filters) and -filter_complex are used to apply filters to media streams, but they serve different purposes and have different capabilities.

  1. -filter / -vf / -af:

    • These options are used to apply simple filters to individual streams within a file.
    • -vf is short for "video filters", and it's used to apply filters to video streams.
    • -af stands for "audio filters", and it's used for audio streams.
    • These options are simpler to use but are limited to operations on a single stream (one video or one audio) at a time.
    • You can chain multiple filters together in a single -vf or -af command to process a stream in several ways.
    • Example: ffmpeg -i input.mp4 -vf "scale=1280:720, fps=25" -af "volume=0.5" output.mp4
  2. -filter_complex:

    • This option is more advanced and powerful. It is used to apply complex filtergraphs, which can involve multiple input streams (video, audio, or both) and produce multiple output streams.
    • It allows for sophisticated operations like combining multiple video or audio streams into one (e.g., picture-in-picture effect), complex transitions, or synchronizing audio and video from different sources.
    • With -filter_complex, you can create a series of filters that pass their outputs to other filters, enabling the construction of complex processing graphs.
    • It is necessary to use -filter_complex when your filtering involves more than one input stream or produces more than one output stream.
    • Example: ffmpeg -i input1.mp4 -i input2.mp3 -filter_complex "[0:v]scale=1280:720[v]; [0:a][1:a]amix=inputs=2[a]" -map "[v]" -map "[a]" output.mp4

In summary, -vf and -af are for simpler, single-stream operations, while -filter_complex is for more complex scenarios involving multiple streams and more intricate filtering chains.

lucemia avatar Dec 22 '23 15:12 lucemia