Answers.Body: <p>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.</p>
  
  <pre><code>ffmpeg -i input.mp4 -c:a aac -ar 48000 -ac 2 -c:v copy -video_track_timescale 600 out.mp4
  </code></pre>
  
  <p>If the audio of a file is already 48 kHz stereo AAC-LC, then you can skip the audio encoding and just use <code>-c:a copy</code></p>
  
  <p>Run the concat with the processed files.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-03T22:13:47.717Z
Answers.Text: 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: https://pastebin.com/TPYt7NVf . The start is negative, i do not really know what it means but it might be a clue
Answers.UserDisplayName: TyLO
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T04:53:43.933Z
Answers.Text: Your ffprobe here shows `Main` profile for videos. The pastebin probe shows High. Did you re-encode the videos?
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T09:39:08.420Z
Answers.Text: 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.
Answers.UserDisplayName: TyLO
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T13:05:54.607Z
Answers.Text: They may have different number of reference frames.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T13:22:32.523Z
Answers.Text: Does this really explain why the video gets corrupted when changing the audio codec and timescale ?
Answers.UserDisplayName: TyLO
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T14:31:09.387Z
Answers.Text: The video isn't corrupted by changing the timescale or by the audio codec. If the video streams being appended don't have the same bitstream parameters then usually the player will produce a corrupted output. The timescale just takes care of preserving the speed of the visuals.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T17:53:29.460Z
Answers.Text: This is how look the first seconds of the video "out.mp4" https://gyazo.com/f596143d2a638242d3285dbb09ad8d72
Answers.UserDisplayName: TyLO
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T19:45:04.607Z
Answers.Text: I think there is a problem with my files when i do something like this `ffmpeg -i 1.mp4 -c:v copy output.mp4` (just to check the file) the output is corrupted (same output as the gyazo). I guess its an error in the files ? I just download them from twitch.tv which is i think i a reliable source
Answers.UserDisplayName: TyLO
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-03T21:12:17.413Z
Answers.LastActivityDate: 2017-04-03T21:12:17.413Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>In the current folder, covert all mp4 files to TS. Then use the Windows 'copy' command to merge every TS. Then, once you have a single ts, transmux to mp4 without re-encoding.</p>
  <pre><code>for %i in (*.mp4) do ffmpeg -i &quot;%i&quot; -c copy -bsf:v h264_mp4toannexb &quot;%~ni.ts&quot; 
  copy /b *.ts all.ts
  ffmpeg -i all.ts -c copy all.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-29T21:20:40.170Z
Answers.LastActivityDate: 2022-06-29T21:20:40.170Z
Answers.UserDisplayName: firebfm
Body: <p>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.</p>
  
  <p>To merge the files i have been using all the solutions in this <a href="https://stackoverflow.com/questions/7333232/concatenate-two-mp4-files-using-ffmpeg">post</a></p>
  
  <p>when trying this method :</p>
  
  <pre><code>:: Create File List
     echo file file1.mp4 &gt;  mylist.txt 
     echo file file2.mp4 &gt;&gt; mylist.txt
     echo file file3.mp4 &gt;&gt; mylist.txt
  :: Concatenate Files
     ffmpeg -f concat -i mylist.txt -c copy output.mp4
  </code></pre>
  
  <p>The audio and video aren't synch anymore and the video sometimes freezes.</p>
  
  <p>When trying the "mp4 to mpg then merge" :</p>
  
  <pre><code> 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
  </code></pre>
  
  <p>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 :</p>
  
  <pre><code>ffmpeg -i input.mp4 -acodec SOME_AUDIO_TYPE -vcodec copy out.mp4
  </code></pre>
  
  <p>the merge occur without any errors but the audio is still unsynch </p>
  
  <p>So in my last attempt i tried to change the fps rate of my files like this :</p>
  
  <pre><code>ffmpeg -y -i source.mp4 -r FPS -s RESOLUTION -c:v libx264 -b:v 3M -strict -2 -movflags faststart destination.mp4
  </code></pre>
  
  <p>But the result reduces the quality too much.</p>
  
  <p>There is the ffprobe of the two files : </p>
  
  <pre><code>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
  </code></pre>
  
  <p>When merging the 2 files with the first method this is what i get :</p>
  
  <pre><code>[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%
  </code></pre>
  
  <p>Is there any solution to this problem?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-03T00:34:47.650Z
Comments.Text: 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).
Comments.UserDisplayName: Michael Liebman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-03T09:17:34.423Z
Comments.Text: 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.
Comments.UserDisplayName: TyLO
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-03T16:55:27.147Z
Comments.Text: Show the complete console output of: `ffmpeg -i file1.mp4 -i file2.mp3 -i file3.mp4`
Comments.UserDisplayName: llogan
Tags: <video><ffmpeg><mp4>
Title: ffmpeg merge 60fps and 30 fps mp4 into one file
UserDisplayName: TyLO
ThreadText: # ffmpeg merge 60fps and 30 fps mp4 into one file
  
  (Asked by: username_0 on 2017-04-02)
  
  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](https://stackoverflow.com/questions/7333232/concatenate-two-mp4-files-using-ffmpeg)
  
  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?
  
  **Tags:** video, ffmpeg, mp4
  
  > **Comments:**
  > **username_1**: 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).  
  > **username_0**: 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.  
  > **username_2**: Show the complete console output of: `ffmpeg -i file1.mp4 -i file2.mp3 -i file3.mp4`  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-04-03. Score: 3
  
  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.
  
  > **Comments:**
  > **username_0**: 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: https://pastebin.com/TPYt7NVf . The start is negative, i do not really know what it means but it might be a clue  
  > **username_3**: Your ffprobe here shows `Main` profile for videos. The pastebin probe shows High. Did you re-encode the videos?  
  > **username_0**: 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.  
  > **username_3**: They may have different number of reference frames.  
  > **username_0**: Does this really explain why the video gets corrupted when changing the audio codec and timescale ?  
  > **username_3**: The video isn't corrupted by changing the timescale or by the audio codec. If the video streams being appended don't have the same bitstream parameters then usually the player will produce a corrupted output. The timescale just takes care of preserving the speed of the visuals.  
  > **username_0**: This is how look the first seconds of the video "out.mp4" https://gyazo.com/f596143d2a638242d3285dbb09ad8d72  
  > **username_0**: I think there is a problem with my files when i do something like this `ffmpeg -i 1.mp4 -c:v copy output.mp4` (just to check the file) the output is corrupted (same output as the gyazo). I guess its an error in the files ? I just download them from twitch.tv which is i think i a reliable source  
  
  ---
  
  ### Answer by username_4 on 2022-06-29. Score: 0
  
  In the current folder, covert all mp4 files to TS. Then use the Windows 'copy' command to merge every TS. Then, once you have a single ts, transmux to mp4 without re-encoding.
  
  ```
  for %i in (*.mp4) do ffmpeg -i "%i" -c copy -bsf:v h264_mp4toannexb "%~ni.ts" 
  copy /b *.ts all.ts
  ffmpeg -i all.ts -c copy all.mp4
  
  ```
  
  
  ---
  
  