LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to merge video files with ffmpeg (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-merge-video-files-with-ffmpeg-937799/)

GrepAwkSed 04-02-2012 09:54 PM

How to merge video files with ffmpeg
 
Hi,

I am trying to merge some video files together. All videos share the same attributes i.e video resolution, bitrates and etc...

I did this with mencoder and it did quite well. I want to know if ffmpeg is capable of doing it as well. I've tried these codes thus far

Code:

cat *.mp4 | ffmpeg -i - -vcodec copy -acodec copy -y out.mp4
Code:

cat *.mp4 | ffmpeg -i pipe:0 -vcodec copy -acodec copy -y out.mp4
But all I get is the first video during playback. Does anyone know if I am missing something in the syntax above?

Thanks for any help or suggestions

PS: I am using ffmpeg version 0.7.8

strungoutfan78 04-02-2012 10:35 PM

As far as I know the syntax in your first example is correct, as I've had to do this once before in the past. However, I'm in the same predicament as you because now its doing the same thing to me. I've resorted to avidemux as it appends files flawlessly, depending on the codec and container.

Sorry that really doesn't answer your question :confused:, but I'm really curious about the answer as well.

Satyaveer Arya 04-02-2012 10:40 PM

Or you can add them like this for an example:

Code:

# cat orig1.mpg orig2.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy merged.mpg

GrepAwkSed 04-02-2012 11:36 PM

@ strungoutfan78

I know what you mean. Ffmpeg is always changing and it sometimes break thigs that worked before.

@ Satyaveer Arya

The code you gave me works surprisingly with mpg files. Don't know why it wouldn't work with mp4 files :scratch:

I think I stick with mencoder when merging files and use ffmpeg for other tasks. These two programs are powerful yet they seem to have some limitations when doing certain tasks.

Thanks to both of you for the replies.

Satyaveer Arya 04-02-2012 11:51 PM

What other way you tried to merge the mp4 files?

strungoutfan78 04-03-2012 12:02 AM

I found something interesting at Stack Overflow (link) after doing a quick Google search. Maybe give it a try and see what happens, as I have no videos to merge at the moment. Pay careful attention to the "newaudio" and "newvideo" portion.

Quick disclaimer: The link is about a year old, so no guarantees it's current.

Quote:

You can put many streams of the same type in the output:

ffmpeg -i test1.avi -i test2.avi -vcodec copy -acodec copy \
-vcodec copy -acodec copy test12.avi -newvideo -newaudio

In addition to the first video and audio streams, the resulting
output file test12.avi will contain the second video and the second
audio stream found in the input streams list.

The "-newvideo", "-newaudio" and "-newsubtitle" options
have to be specified immediately after the name of the output file
to which you want to add them.

GrepAwkSed 04-03-2012 12:02 AM

Quote:

Originally Posted by Satyaveer Arya (Post 4643223)
What other way you tried to merge the mp4 files?

I did use mencoder to merge the mp4 files and it did the job quite well.

To test the code you gave me I converted two mp4 files to mpg files and then use ffmpeg to merge the mpgs files together and it work.

The only bad thing is I have to convert the mp4 files to mpg files before using the ffmpeg command to merge them.

With mencoder I don't have to do that. They are both great commands and I use them both exclusively when working with media files, but each have their ways of doing things that don't work the same way.

GrepAwkSed 04-03-2012 12:11 AM

@ strungoutfan78

Didn't work

strungoutfan78 04-03-2012 12:14 AM

Well, I tried to edit my last post rather than add a new one, but LQ is being obstinate right now, so here it goes.

Again, I know this only provides a workaround rather than a solution, but have you tried using MP4Box?
Should be available in the repos, at least it's in the Debian repos. It's written specifically for handling mp4 files in a similar fashion to what you may be familiar with using mencoder or ffmpeg. The syntax gets a little clunky, but it works.

GrepAwkSed 04-03-2012 12:48 AM

@ strungoutfan78

I heard of MP4Box but don't use it as much. I use mostly ffmpeg and mecoder and to some degree HandBrake.

Anyway, I've already merge the mp4 files with mencoder and it did a good job.

Have a good night all

Satyaveer Arya 04-03-2012 01:31 AM

GrepAwkSed,

MP4Box is also good to merge two mp4 files directly but for that first you have to install GPAC. You can download the GPAC from here: http://gpac.wp.mines-telecom.fr/downloads/

And check this link also: http://www.molotovbliss.com/combine-...box-and-ffmpeg

Good Luck!

GrepAwkSed 04-04-2012 02:20 AM

Quote:

Originally Posted by Satyaveer Arya (Post 4643284)
GrepAwkSed,

MP4Box is also good to merge two mp4 files directly but for that first you have to install GPAC. You can download the GPAC from here: http://gpac.wp.mines-telecom.fr/downloads/

And check this link also: http://www.molotovbliss.com/combine-...box-and-ffmpeg

Good Luck!

Just tried MP4Box and it worked like a charm. Thanks

Satyaveer Arya 04-04-2012 02:33 AM

Good to know that the things worked out for you. Have a nice day! :)


All times are GMT -5. The time now is 03:59 AM.