I have been trying to merge some mp4 files with different frame rates without success. When I merge the files, there always seems to be a problem with the output. Most of the time the audio is not in sync with the video. I tried to modify the frame rate of the videos (30 to 60 or 60 to 30), but it reduces the quality too much.
To merge the files i have been using all the solutions in this post
when trying this method :
:: Create File List
echo file file1.mp4 > mylist.txt
echo file file2.mp4 >> mylist.txt
echo file file3.mp4 >> mylist.txt
:: Concatenate Files
ffmpeg -f concat -i mylist.txt -c copy output.mp4
The audio and video aren't synch anymore and the video sometimes freezes.
When trying the "mp4 to mpg then merge" :
ffmpeg -i 1.mp4 -qscale 0 1.mpg
ffmpeg -i 2.mp4 -qscale 0 2.mpg
cat 1.mpg 2.mpg | ffmpeg -f mpeg -i - -qscale 0 -vcodec mpeg4 output.mp4
I loose the audio on the 60 FPS files, at this point i thought it was an audio problem so i tried to "unify" the audio codec of all mp4 files like this :
ffmpeg -i input.mp4 -acodec SOME_AUDIO_TYPE -vcodec copy out.mp4
the merge occur without any errors but the audio is still unsynch
So in my last attempt i tried to change the fps rate of my files like this :
ffmpeg -y -i source.mp4 -r FPS -s RESOLUTION -c:v libx264 -b:v 3M -strict -2 -movflags faststart destination.mp4
But the result reduces the quality too much.
There is the ffprobe of the two files :
libavutil 55. 57.100 / 55. 57.100
libavcodec 57. 88.100 / 57. 88.100
libavformat 57. 70.100 / 57. 70.100
libavdevice 57. 5.100 / 57. 5.100
libavfilter 6. 81.100 / 6. 81.100
libswscale 4. 5.100 / 4. 5.100
libswresample 2. 6.100 / 2. 6.100
libpostproc 54. 4.100 / 54. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.63.100
Duration: 00:00:32.00, start: 0.000000, bitrate: 3120 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/iec61966-2-1), 1280x720, 2981 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandler
libavutil 55. 57.100 / 55. 57.100
libavcodec 57. 88.100 / 57. 88.100
libavformat 57. 70.100 / 57. 70.100
libavdevice 57. 5.100 / 57. 5.100
libavfilter 6. 81.100 / 6. 81.100
libswscale 4. 5.100 / 4. 5.100
libswresample 2. 6.100 / 2. 6.100
libpostproc 54. 4.100 / 54. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.63.100
Duration: 00:00:23.01, start: 0.000000, bitrate: 2585 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720, 2412 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 159 kb/s (default)
Metadata:
handler_name : SoundHandler
When merging the 2 files with the first method this is what i get :
[mp4 @ 0xbc5a340] Non-monotonous DTS in output stream 0:0; previous: 2872466, current: 843279; changing to 2872467. This may result in incorrect timestamps in the output file.
[mp4 @ 0xbc5a340] Non-monotonous DTS in output stream 0:0; previous: 2872467, current: 843535; changing to 2872468. This may result in incorrect timestamps in the output file.
[mp4 @ 0xbc5a340] Non-monotonous DTS in output stream 0:0; previous: 2872468, current: 843791; changing to 2872469. This may result in incorrect timestamps in the output file.
[mp4 @ 0xbc5a340] Non-monotonous DTS in output stream 0:0; previous: 2872469, current: 844047; changing to 2872470. This may result in incorrect timestamps in the output file.
frame= 2340 fps=0.0 q=-1.0 Lsize= 19428kB time=00:00:50.53 bitrate=3149.8kbits/s speed=58.7x
video:18420kB audio:949kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.304418%
Is there any solution to this problem?
ffmpeg -i file1.mp4 -i file2.mp3 -i file3.mp4