Error Starting Encoding Multiple Video Streams with FFmpeg
FFmpeg is a powerful, open-source tool used for handling multimedia files, including audio, video, and images. It is widely used for transcoding, streaming, and manipulating various formats. However, when trying to encode multiple video streams using FFmpeg, you might encounter errors. This article will discuss the issue and provide solutions.
Understanding the FFmpeg Command
The following FFmpeg command is used to transcode a video file with multiple video streams:
ffmpeg -i /2160.mp4 -c:libopus -b:128k -ar48000 -c:vlibvpx-vp9 -pix_fmt yuv420p -g240 -map v:0 -vf "scale=-2:144" -map v:1 -vf "scale=-2:144" output.webmHere's a breakdown of the command:
-i /2160.mp4: specifies the input file-c:libopus -b:128k -ar48000: sets the audio codec to Opus, bitrate to 128 kbps, and audio sample rate to 48000 Hz-c:vlibvpx-vp9 -pix_fmt yuv420p -g240: sets the video codec to VP9, pixel format to yuv420p, and GOP size to 240-map v:0 -vf "scale=-2:144": maps the first video stream and scales it to a height of 144 pixels-map v:1 -vf "scale=-2:144": maps the second video stream and scales it to a height of 144 pixelsoutput.webm: specifies the output file
Error Starting Encoding Multiple Video Streams
When trying to encode multiple video streams using the aforementioned FFmpeg command, you might encounter an error similar to:
Multiple -vf/-af/-filter\_complex filters specified for the same stream. Use the 'filter\_complex' filtergraph instead of the separate filters.This error occurs because FFmpeg does not support using multiple -vf options for the same stream. To resolve this issue, you need to use the filter\_complex filtergraph instead.
Using filter\_complex
To fix the error, you can modify the FFmpeg command as follows:
ffmpeg -i /2160.mp4 -c:libopus -b:128k -ar48000 -c:vlibvpx-vp9 -pix_fmt yuv420p -g240 -filter\_complex "[0:v:0]scale=-2:144[v0]; [0:v:1]scale=-2:144[v1]" -map "[v0]" -map "[v1]" -map 0:a output.webmHere's what changed:
filter\_complex "[0:v:0]scale=-2:144[v0]; [0:v:1]scale=-2:144[v1]": uses the filter\_complex to scale both video streams-map "[v0]" -map "[v1]": maps the scaled video streams to the output
When trying to encode multiple video streams using FFmpeg, you might encounter errors if you use multiple -vf options for the same stream. To resolve this issue, you can use the filter\_complex filtergraph instead. The filter\_complex filtergraph allows you to apply multiple filters to the same stream, making it possible to encode multiple video streams without encountering errors.