Combining two video from ffmpeg

Astha picture Astha · Sep 27, 2011 · Viewed 29.6k times · Source

I want to combine two mp4 videos to form a single mp4 video using ffmpeg.

what i tried so far is

ffmpeg -i input1.mp4 -i input2.mp4 output.mp4

But, every time i get the video with video codec of first input and not the other. How can i combine them? Any idea on this will be highly appreciated.

Answer

user1592546 picture user1592546 · Dec 4, 2014

As previous answers show, you need to convert first to an intermediate format. If the mp4 contains h264 bitstream, you can use:

ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input1.ts
ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input2.ts
ffmpeg -i "concat:input1.ts|input2.ts" -c copy output.mp4

A more detailed answer you can find here.