Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining two video from ffmpeg

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.

like image 968
Astha Avatar asked Sep 27 '11 10:09

Astha


People also ask

How do I combine two videos in FFmpeg?

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.

How do I combine two videos in android programmatically FFmpeg?

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.


1 Answers

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.

like image 79
user1592546 Avatar answered Oct 22 '22 21:10

user1592546