Timeline for How to concatenate two MP4 files using FFmpeg?
Current License: CC BY-SA 4.0
31 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 13, 2023 at 5:13 | comment | added | Ed999 | @minseong One reason why you might get such an error is, possibly, that the source (input) files are not all of identical duration. In such a case, a workaround is to only concatenate two files at a time. This is feasible if you only have three or four files to process. It may sound impractical if you are processing dozens (or hundreds) of segments, but a stream containing so many segments will normally be carefully prepared at its source to make the segment durations identical, so the problem should not arise. | |
Jun 26, 2023 at 6:22 | comment | added | vee |
%% doesn't work on command line. Use % works fine.
|
|
Apr 24, 2022 at 23:02 | comment | added | Ed999 | @minseong There are many reasons why you might get such an error. My script only works for mp4 files, and only if they are compatible with each other (i.e. are identical in every property, because they all had the same source file originally). | |
Mar 2, 2022 at 22:29 | comment | added | user3310334 | This removed the first second of the second video | |
Nov 9, 2021 at 0:23 | comment | added | Nils Riga |
To create the file list of mp4 files from . directory, use: for /f "tokens=1 delims=." %a in ('dir /B *.mp4') do echo file '%a.mp4'>> mylist.txt
|
|
Jun 3, 2021 at 0:10 | comment | added | Ed999 | @NimeCloud - Yes, if you intend to run the script more than once, it would be useful to start by deleting 'mylist.txt', I suggest this: IF EXIST MYLIST.TXT DEL MYLIST.TXT | |
Jun 3, 2021 at 0:06 | comment | added | Ed999 | @Jags. You can do it the hard way if you wish. But I reckon what you'd find least trouble is to temporarily move the files you want to concatenate into a new directory and run my code there. There are lots of other ways to do what you ask, all of them rife with snags. My approach is to put in the working directory only those 5 files that are to be concatenated, and then run my unmodified code. Trust me, save yourself the headaches that come with the more sophisticated solutions, and do it the low tech but easy way -- move the goddam files! :) | |
Jun 2, 2021 at 16:44 | comment | added | Nime Cloud | del mylist.txt should be added at the top | |
Jun 1, 2021 at 18:08 | comment | added | Jags |
@ed999 I have a directory with 100 MP4 files with exact same resolution, audio and video codecs. Is it possible to modify the command you've posted, to concat 01 to 05, 06 to 10, and so on, and create 01_05.mp4, 06_10.mp4 etc., WITHOUT using mylist.txt ? I like to create 20 files out of 100, instead of just 1. Thanks alot.
|
|
Apr 21, 2021 at 22:15 | comment | added | Nimitz14 | Did not work for me, second file was 3 extra, instead of that get a minute of a frozen frame added. | |
Feb 22, 2021 at 3:07 | comment | added | Ed999 | That proposal would be a disaster. It will populate the file myfile.txt with every non-mp4 file in the current directory. But, worse, it will also populate that file with the name of every folder in the current directory. | |
Feb 17, 2021 at 10:38 | comment | added | user151496 |
to create the list on windows you may use dir /B >mylist.txt , just check the order of the file afterwards and prepend string file on each line in any editor that can mass replace newlines
|
|
Dec 13, 2020 at 16:48 | comment | added | Ed999 | @chovy There are many, many reasons why you might get such an error. My script only works for mp4 files that are compatible with each other (i.e. that are identical in every particular because they all had the same source file originally). You can easily find two or more mp4 files that do not have identical codecs, bitrates, framerates, sample rates and timebases, which therefore can't be concatenated by ANY method. My script can't resolve such cases, because no script can. | |
Dec 4, 2020 at 7:47 | comment | added | chovy | i get an eror with second file in list. | |
Sep 6, 2020 at 12:33 | comment | added | Ed999 | I do not want to add unnecessary complexity to this straightforward solution. It would be just too easy to over-complicate the script, because if you run it a second time in the same folder not only do you need to provide for removing the mylist.txt file but you also need to remove or rename the output.mp4 file, else it will be deleted, or perhaps its presence will prevent the script running a second time. Those decisions are, IMHO, better left to the good sense and needs of the person using the script. | |
Sep 6, 2020 at 12:26 | comment | added | Ed999 | It's unnecessary, because my script concatenates ALL the mp4 files in the folder from which the script is run. There are no mp4 files left over to need a second run. The intent of the script is to move it to the next folder containing mp4 files before running it again. | |
Sep 5, 2020 at 10:20 | comment | added | Nexarius | You should include a "DEL mylist.txt" at the end for people who just copy your code into a batch file. Otherwise running the batch file a second time will be messed up because of the old mylist.txt still in the folder. | |
Mar 6, 2019 at 17:07 | comment | added | Ed999 | @kakyo Try using the latest build of ffmpeg from ffmpeg.zeranoe.com/builds but I regret I can't troubleshoot a problem on a Mac, my code is only intended to run on Windows. I myself only run it on Windows 7, but it should work okay on Windows Vista/7/8/10. | |
Mar 2, 2019 at 14:07 | comment | added | kakyo | With my mp4 files, there is no audio at all in the output file after running your concat code on a Mac, using ffmpeg v3.2.2. | |
Dec 6, 2018 at 12:36 | history | edited | Ed999 | CC BY-SA 4.0 |
added 142 characters in body
|
Dec 6, 2018 at 12:01 | history | edited | Ed999 | CC BY-SA 4.0 |
Amend code to add: -safe 0
|
Dec 6, 2018 at 11:14 | history | edited | Ed999 | CC BY-SA 4.0 |
Amend code
|
Dec 6, 2018 at 10:31 | history | edited | Ed999 | CC BY-SA 4.0 |
Added an explanatory note to the Addendum
|
Dec 5, 2018 at 16:56 | review | Suggested edits | |||
Dec 6, 2018 at 6:01 | |||||
Nov 12, 2018 at 2:18 | comment | added | Ed999 | @Xam : You have posted a solution that will only work on the command line, but will fail in a batch file. I have not posted a command line solution, but a batch file solution. If you fail to double a % symbol when using your suggested code in a Windows batch file, the batch file will fail. When running my code, it must be run in a batch file, and in a batch file all % symbols must be written %%. | |
Nov 8, 2018 at 3:48 | comment | added | Xam |
Your last code doesn't work. I have to use this instead: (for %i in (*.mp4) do @echo file '%i') > mylist.txt .
|
|
Oct 21, 2018 at 14:21 | history | edited | Ed999 | CC BY-SA 4.0 |
Added Addendum
|
Oct 11, 2018 at 18:17 | comment | added | Würgspaß |
This is a very good solution cos it saves you from typing in lengthy lists of files for -i parameter. On Linux I did this: ls -1 P1041*.mp4 | sed s/"P"/" file P"/g > mylist.txt which is even cooler than coding a batch script. Anyway, -c copy performs very quickly (which I was not aware of) and this is the real magic of this answer.
|
|
Oct 10, 2018 at 1:37 | comment | added | barlop |
This is a good solution but talking about a batch file makes this sound primitive(like it was done in batch), and more complex than it is(because a batch file is completely unnecessary). It is much clearer if you simply show C:\blah>type mylist.txt<ENTER> (So they see the contents of that file) Then ffmpeg -f concat -i mylist.txt -c copy output.mp4<ENTER> Also you should include a reference trac.ffmpeg.org/wiki/Concatenate (that reference even uses the same filename, mylist.txt)
|
|
Dec 29, 2016 at 21:42 | history | edited | Ed999 | CC BY-SA 3.0 |
added 33 characters in body
|
Dec 29, 2016 at 21:36 | history | answered | Ed999 | CC BY-SA 3.0 |