Answers.Body: <p>Add <code>-video_track_timescale X</code> to manually set a timescale of X.</p>
  <p><code>ffmpeg -i org_video_1280x720.mp4 -strict -2 -vf &quot;scale=640:360&quot; -video_track_timescale 90k new_video_640x360.mp4</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-21T16:46:53.153Z
Answers.Text: Thanks @Gyan. Now with this option the `tbn` was fixed and the resulted stream was - `25 fps, 25 tbr, 30k tbn, 50 tbc`; However, here the `tbc` value was new and it didn't change back to original - `25 fps, 25 tbr, 30k tbn, 60k tbc`.
Answers.UserDisplayName: Muthu Thavamani
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-21T16:49:37.377Z
Answers.Text: so when I merge this video with others videos those has stream -  `Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 812 kb/s, 25 fps, 25 tbr, 30k tbn, 60k tbc (default)` the resulted video has the same error while playing. And while concat process in terminal i got warning says `Non-monotonous DTS in output stream 0:1; previous: 4016128, current: 3765360; changing to 4016129. This may result in incorrect timestamps in the output file`.
Answers.UserDisplayName: Muthu Thavamani
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-21T16:51:03.160Z
Answers.Text: i hope this video error and warning was due to the `tbc` mismatch.
Answers.UserDisplayName: Muthu Thavamani
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-21T14:52:25.197Z
Answers.LastActivityDate: 2021-01-21T14:52:25.197Z
Answers.UserDisplayName: Gyan
Body: <p>I have been trying to write a script to merge multiple <code>.mp4</code> videos using ffmpeg. As part of this process, while trying to alter the size found that it alters the timebase. However, for <code>ffmpeg - concat demux</code> all streams should be same or else after merge only the first part of the video plays well and stops abruptly.</p>
  <p>I have tried both terminal way and also using <code>fluent-ffmpeg</code>. But unfortunately both gives same result.</p>
  <ol>
  <li>Original video Ex, org_video_1280x720.mp4</li>
  </ol>
  <blockquote>
  <p>Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 812 kb/s, 25 fps, 25 tbr, 30k tbn, 60k tbc (default)</p>
  </blockquote>
  <ol start="2">
  <li>after scaling down to 640x360 via terminal <code>ffmpeg -i org_video_1280x720.mp4 -strict -2 -vf &quot;scale=640:360&quot; new_video_640x360.mp4</code></li>
  </ol>
  <blockquote>
  <p>Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 256 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)</p>
  </blockquote>
  <ol start="3">
  <li>The fluent-ffmpeg way of sizing</li>
  </ol>
  <pre><code>ffmpeg(`/path/to/org_video_1280x720.mp4`).size(`640x360`). autopad().output(`/path/to/new_video_640x360.mp4`)
            .on('error', function(err, stdout, stderr) {
                console.log('Error: ' + err.message);
                console.log('STD Err: ' + stderr);
           })
           .on('end', function() {
                console.log('Split &amp; Resizing Completed!');
           }).run();
  </code></pre>
  <blockquote>
  <p>Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 253 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)</p>
  </blockquote>
  <p>Notice the <code>tbn &amp; tbc</code> changes after resizing; Actually I have to merge this with other video only by changing the resolution (as they were with these <code>25 fps, 25 tbr, 30k tbn, 60k tbc</code> stream values); However as it alters the <code>time_base</code>, I was unable to do it. Hope, I am missing something in the process, as I am bit new to audio/video process. Looking for some tips/guidance to get this done!</p>
  
Tags: <video><ffmpeg>
Title: ffmpeg - resizing .mp4 changes the timebase (tbn & tbc)
UserDisplayName: Muthu Thavamani
ThreadText: # ffmpeg - resizing .mp4 changes the timebase (tbn & tbc)
  
  (Asked by: username_0 on 2021-01-21)
  
  I have been trying to write a script to merge multiple `.mp4` videos using ffmpeg. As part of this process, while trying to alter the size found that it alters the timebase. However, for `ffmpeg - concat demux` all streams should be same or else after merge only the first part of the video plays well and stops abruptly.
  
  I have tried both terminal way and also using `fluent-ffmpeg`. But unfortunately both gives same result.
  
  1. Original video Ex, org\_video\_1280x720.mp4
  
  > Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 812 kb/s, 25 fps, 25 tbr, 30k tbn, 60k tbc (default)
  
  2. after scaling down to 640x360 via terminal `ffmpeg -i org_video_1280x720.mp4 -strict -2 -vf "scale=640:360" new_video_640x360.mp4`
  
  > Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 256 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
  
  3. The fluent-ffmpeg way of sizing
  
  ```
  ffmpeg(`/path/to/org_video_1280x720.mp4`).size(`640x360`). autopad().output(`/path/to/new_video_640x360.mp4`)
            .on('error', function(err, stdout, stderr) {
                console.log('Error: ' + err.message);
                console.log('STD Err: ' + stderr);
           })
           .on('end', function() {
                console.log('Split & Resizing Completed!');
           }).run();
  
  ```
  
  > Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 253 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
  
  Notice the `tbn & tbc` changes after resizing; Actually I have to merge this with other video only by changing the resolution (as they were with these `25 fps, 25 tbr, 30k tbn, 60k tbc` stream values); However as it alters the `time_base`, I was unable to do it. Hope, I am missing something in the process, as I am bit new to audio/video process. Looking for some tips/guidance to get this done!
  
  **Tags:** video, ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-21. Score: 4
  
  Add `-video_track_timescale X` to manually set a timescale of X.
  
  `ffmpeg -i org_video_1280x720.mp4 -strict -2 -vf "scale=640:360" -video_track_timescale 90k new_video_640x360.mp4`
  
  > **Comments:**
  > **username_0**: Thanks @username_1. Now with this option the `tbn` was fixed and the resulted stream was - `25 fps, 25 tbr, 30k tbn, 50 tbc`; However, here the `tbc` value was new and it didn't change back to original - `25 fps, 25 tbr, 30k tbn, 60k tbc`.  
  > **username_0**: so when I merge this video with others videos those has stream -  `Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 812 kb/s, 25 fps, 25 tbr, 30k tbn, 60k tbc (default)` the resulted video has the same error while playing. And while concat process in terminal i got warning says `Non-monotonous DTS in output stream 0:1; previous: 4016128, current: 3765360; changing to 4016129. This may result in incorrect timestamps in the output file`.  
  > **username_0**: i hope this video error and warning was due to the `tbc` mismatch.  
  
  ---
  
  