1

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?

  • How are you merging the files? How are you converting the frame rates? Please include the full ffmpeg command line and console output (if that is what you are using). – Michael Liebman Apr 3 '17 at 0:34
  • First of all, thank you for trying to help me resolve this problem. I have edited my question like you advised and included most of the steps i tried. Hope this help you figure out the potential mistakes i'm making. – TyLO Apr 3 '17 at 9:17
  • Show the complete console output of: ffmpeg -i file1.mp4 -i file2.mp3 -i file3.mp4 – llogan Apr 3 '17 at 16:55
1

The audio will have to re-encoded with the same sampling rate, if it's different across the files. The video doesn't need to be re-encoded but it needs to have the same timescale.

ffmpeg -i input.mp4 -c:a aac -ar 48000 -ac 2 -c:v copy -video_track_timescale 600 out.mp4

If the audio of a file is already 48 kHz stereo AAC-LC, then you can skip the audio encoding and just use -c:a copy

Run the concat with the processed files.

  • When applying those changes to a file (44kHz) the first seconds are corrupted. I still tried to merge the files and VLC crash when the corrupted video begins. there is the ffprobe of the file before and after the command: pastebin.com/TPYt7NVf . The start is negative, i do not really know what it means but it might be a clue – TyLO Apr 3 '17 at 22:13
  • Your ffprobe here shows Main profile for videos. The pastebin probe shows High. Did you re-encode the videos? – Gyan Apr 4 '17 at 4:53
  • Sorry, i have a lot of mp4 that i need to combine, i might have used a different ones because i assumed the only "variables" that matters were audio and frame rate. What there is about the "main" or "high" that causes a problem ? because i might have this one while merging other videos. – TyLO Apr 4 '17 at 9:39
  • They may have different number of reference frames. – Gyan Apr 4 '17 at 13:05
  • Does this really explain why the video gets corrupted when changing the audio codec and timescale ? – TyLO Apr 4 '17 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.