Posted on 2 Comments

Joining videos in Xabe.FFmpeg

Joining videos in Xabe.FFmpeg

There are a lot of questions and articles how to concatenate multiple videos into one with FFmpeg. Once upon time we had to deal with that feature.
    1. FFmpeg offers few ways of concatenation:
 
  1. Concat demuxer
  2. Concat protocol
  3. Concat filters
Due to limits of each concatenation method we implemented it by “filter”. Concat demuxer requires that all files must have the same streams (same codes, time base, etc.) and we need something more flexible. However Concat protocol was easy to use but supports only MPEG based files. Concatenating by filter has restrictions too, but we adapt some features to be more elastic. Full implementation is available on GitHub. All of concatenation options can be used in Xabe.FFmpeg by Conversion.Start(string) which allows user to pass arguments directly into FFmpeg. But we will focus on our implementation of concatenation.

C# FFmpeg concatenation

Using our implementation is quite easy. Just call one method:
IConversionResult result = await Conversion.Concatenate(output, firstFile, secondFile);
Implementation of this method is a bit complicated (it is available on our GitHub repository) and it doesn’t allow to pass any additional arguments or manipulate particular streams in exchange for flexibility of passing files. Above command generate ffmpeg command like this:
ffmpeg.exe -n -threads 12 -i "C:\Users\tzmuda\Source\Xabe.FFmpeg\Xabe.FFmpeg.Test\bin\Debug\netcoreapp2.0\Resources\SampleVideo_360x240_1mb.mkv" -i "C:\Users\tzmuda\Source\Xabe.FFmpeg\Xabe.FFmpeg.Test\bin\Debug\netcoreapp2.0\Resources\mute.mp4" -t 1 -f lavfi -i anullsrc=r=48000:cl=stereo -filter_complex " [0:v]scale=1280:720,setdar=dar=16:9,setpts=PTS-STARTPTS[v0]; [1:v]scale=1280:720,setdar=dar=16:9,setpts=PTS-STARTPTS[v1]; [v0][0:a] [v1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" "C:\Users\tzmuda\AppData\Local\Temp\tmpD0BE.mp4"
More info in Xabe.FFmpeg documentation

2 thoughts on “Joining videos in Xabe.FFmpeg

  1. ffmpeg -i NEWSROOM.mp4 -i SEG-3.mxf -i NEWSROOM.mp4 -i SEG-3.mxf -filter_complex “[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0][3:v:0][3:a:0]concat=n=4:v=1:a=1[video_out][audio_out]” -map “[video_out]” -map “[audio_out]” JOKOPRING.MP4

    i already make this..
    but, i want to put the video file in txt file.
    how the command please ??

    thanks

    1. Hi jokopring,

      You could set up output file name to “jokopring.txt” and specify the “-f” parameter:

      -f fmt (input/output)
      Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.

      https://www.ffmpeg.org/ffmpeg-all.html

Comments are closed.