scripts:ffmpeg:merge_concatenate_video_audio_files

This is useful when you need to combine multiple videos into one, either from parts above, or more likely, to make a pseudo-playlist or slideshow of videos. This method also works for audio files such as if you're going to burn a continous track on a CD, or combine interviews for a podcast or whatever.

First, get the list of files in a text file. It needs to be in the format of “file filename” in each line.

find *.mkv | sed 's:\ :\\\ :g'| sed 's/^/file /'> files

Here is a command that will make a text file called files of all mkv files in a folder. You can do this for any extension, and the sed command will append the file structure needed.

Next, run ffmpeg to merge the video or audio segments.

ffmpeg -f concat -safe 0 -i files -c copy output.mkv

This will take in all the files in the list generated above, copy the codecs without re-encoding into the output.

You may or may not want to re-encode when merging. If your inputs have different codecs, re-encode the input. If you're merging from parts you generated by splitting the video manually (see above example), then you can just copy the codecs.

  • scripts/ffmpeg/merge_concatenate_video_audio_files.txt
  • Last modified: 2022-04-06 21:52
  • by Tony