32
13
I want to join two mp4 files to create a single one. The video streams are encoded in h264 and the audio in aac. I can not re-encode the videos to another format due to computational reasons. Also, I cannot use any GUI programs, all processing must be performed with Linux command line utilities. FFmpeg cannot do this for mpeg4 files so instead I used MP4Box:
MP4Box -add video1.mp4 -cat video2.mp4 newvideo.mp4
Unfortunately the audio gets all mixed up. I thought that the problem was that the audio was in aac so I transcoded it in mp3 and used again MP4Box. In this case the audio is fine for the first half of newvideo.mp4
(corresponding to video1.mp4
) but then their is no audio and I cannot navigate in the video also.
My next thought was that the audio and video streams had some small discrepancies in their lengths that I should fix. So for each input video I splitted the video and audio streams and then joined them with the -shortest option in FFmpeg.
Thus for the first video I ran:
avconv -y -i video1.mp4 -c copy -map 0:0 videostream1.mp4
avconv -y -i video1.mp4 -c copy -map 0:1 audiostream1.m4a
avconv -y -i videostream1.mp4 -i audiostream1.m4a -c copy -shortest video1_aligned.mp4
Similarly for the second video and then used MP4Box as previously. Unfortunately this didn't work either. The only success I had was when I joined the video streams separately (i.e. videostream1.mp4 and videostream2.mp4) and the audio streams (i.e. audiostream1.m4a and audiostream2.m4a) and then joined the video and audio in a final file. However, the synchronization is lost for the second half of the video. Concretely, there is a 1 sec delay of audio and video. Any suggestions are really welcome.
just love those migrated questions that got later non migrated duplicates: http://stackoverflow.com/questions/18552901/how-to-merge-videos-by-avconv
– Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-12-03T19:07:43.557"FFmpeg cannot do this for mpeg4 files so instead I used MP4Box" do you mean MP4 file ? do both the audio-video streams uses same encoding parameters (width,height, SPS,PPS, framerate, samplingrate, number of channels ? – None – 2012-12-18T13:31:40.837
using ffprobe I see that the audio streams have identical attributes. The video streams have the same dimensions but different rates. For the 1st video Video: h264, 720x592, 277 kb/s, PAR 18944:12915 DAR 512:287, 24.97 fps, 45k tbr, 90k tbn, 90k tbc while for the second Video: h264, 720x592, 226 kb/s, PAR 481:330 DAR 39:22, 24.91 fps, 45k tbr, 90k tbn, 90k tbc . Do you believe that this is the source of my problems? – None – 2012-12-18T15:17:43.460
try this http://stackoverflow.com/questions/5415006/ffmpeg-combine-merge-multiple-mp4-videos-not-working
– daya – 2012-12-18T16:37:25.200Your question is already answered in ffmpeg FAQ: http://www.ffmpeg.org/faq.html#How-can-I-join-video-files_003f
– Palec – 2013-12-05T16:26:49.253MP4 supports joining video/audio with different characteristics using different track for different video, but player are not that smart. – rajneesh – 2012-12-18T16:13:27.493