The Computer Oracle

ffmpeg join two mp4 files with ffmpeg on command line

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Quirky Dreamscape Looping

--

Chapters
00:00 Ffmpeg Join Two Mp4 Files With Ffmpeg On Command Line
00:33 Accepted Answer Score 58
01:26 Answer 2 Score 2
01:47 Answer 3 Score 11
02:02 Answer 4 Score 2
02:41 Thank you

--

Full question
https://superuser.com/questions/1059245/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#commandline #ffmpeg

#avk47



ACCEPTED ANSWER

Score 58


2019 Update:

As mentioned in the comments, Stack Overflow has a great description of the available options for concatenation, as well as a discussion of which method to use depending on the types of files you're using:

How to concatenate two MP4 files using FFmpeg?

Original 2016 Answer:

You should be able to use the concat protocol method to combine the files:

ffmpeg -i "concat:input1.mp4|input2.mp4|input3.mp4" -c copy output.mp4

In addition, the FFmpeg manual discusses a method specifically for MP4 files, in order to losslessly concatenate them, but requires that you create temporary files (or named pipes):

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



ANSWER 2

Score 11


You may replace file with list by outputting list to stdout and reading the list from stdin by ffmpeg:

(echo file 'a.mp4' & echo file 'b.mp4') | ffmpeg -protocol_whitelist file,pipe -f concat -safe 0 -i pipe: -vcodec copy -acodec copy "result.mp4"



ANSWER 3

Score 2


No, there appears to be no way to use the ffmpeg concat demuxer on a single command line without some hack. You need to create the input text file with the list of files. I thought this strange myself, maybe someone will add this to FFMpeg at a later date.

The accepted answer to this question uses the concat protocol, not the concat demuxer which is what the OP asked.




ANSWER 4

Score 2


Without external text file, one line command to merge all MP4 files in a folder:

in CMD (the Command Prompt):

(FOR /R %A IN (*.mp4) DO @ECHO file '%A') | ffmpeg -protocol_whitelist file,pipe -f concat -safe 0 -i pipe: -vcodec copy -acodec copy "Videos_Merged.mp4"

in a BATch file:

(FOR /R %%A IN (*.mp4) DO @ECHO file '%%A') | ffmpeg -protocol_whitelist file,pipe -f concat -safe 0 -i pipe: -vcodec copy -acodec copy "Videos_Merged.mp4"

P.S.: CHCP 65001 command need if the directory contains unicode characaters.

(This code based Qwertiy's one-line command. I'm again grateful to Qwertiy for the informations in his reply. So I fixed the code.