2

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)

  1. 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)

  1. 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!

1 Answer 1

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

3
  • 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. Commented Jan 21, 2021 at 16:46
  • 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. Commented Jan 21, 2021 at 16:49
  • i hope this video error and warning was due to the tbc mismatch. Commented Jan 21, 2021 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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