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.
To merge videos using the concat demuxer, first create a text file with a list of videos you want to join. Below is an example file videos. txt . You can add comments to the file, they will be ignored by the demuxer.
ffmpeg -f concat -i mylist.txt -c copy output.mp4 This process is a way of concatenating the files and not re-encoding. Hence, it should be done speedily & conveniently. If there is no error message, you are sure to receive a final merged video named by 'output. mp4' in the MP4 folder.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With