ffmpeg

FFMPEG Video Multiplexer


I am a DirectShow developer, I used to build multiplexers that take 2 video inputs and generate one output, I would then use a video encoder mux to feed it the output + anothrr audio stream to generate the final video output. The multiplexer (DirectShow framework) allows me to process the input video from two sources (for example, adding effects using the two frames).

How can this can be done using FFMPEG?


Solution

  • Since your question is very vague I will provide three "solutions".

    Muxing

    Muxing streams from various inputs is easy. This example will stream copy all video streams from input0.mkv, all video streams from input1.mp4, and all audio streams from input2.oga. The resulting output file will have at least 2 video streams and at least 1 audio stream. The exact number of streams in the output depends on the number of streams present in the inputs.

    ffmpeg -i input0.mkv -i input1.mp4 -i input2.oga -map 0:v -map 1:v -map 2:a -c copy -shortest output.mkv
    

    Also see:

    Concatenating

    If you want to concatenate the video streams and add an audio stream you can use the concat filter or the concat demuxer. Here's a basic example using the concat filter:

    ffmpeg -i video0.webm -i video1.mp4 -i audio.wav -filter_complex \
    "[0:v][1:v]concat=n=2:v=1:a=0[v]" -map "[v]" -map 2:a output.mkv
    

    See FFmpeg Wiki: Concatenate for more examples.

    Concatenating with additional filtering

    ffmpeg -i video0.webm -i video1.mp4 -i audio.wav -filter_complex \
    "[0:v]scale=1280:-2,vflip,setpts=PTS-STARTPTS[v0]; \
     [1:v]fps=25,curves=preset=increase_contrast,setpts=PTS-STARTPTS[v1]; \
     [v0][v1]concat=n=2:v=1:a=0[v]" \
    -map "[v]" -map 2:a output.mkv