Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg start_time is negative

I'm using ffmpeg to segment a video by start/end times. For example, I have a set of time [[0,2],[2,4],[4,6]], and I'd call ffmpeg 3 times here to create the three 2 second videos at times 0, 2, and 4.

My problem is that these times (which are correct) are not correctly segmenting the video. When I inspect the stats of the video with ffprobe -i test.mov -show_format, I noticed start_time=-0.381044. I also know that this seems to be caused by trimming a video in QuickTime to produce this video. In order to correct this, I must add (start + 0.381044) somewhere in my code, and the output is fine.

So, why is the start_time set to a negative value by the quicktime trimming? How can I set start_time=0, so my code can work without the + 0.381044?

like image 773
Alex Bollbach Avatar asked Jul 13 '26 07:07

Alex Bollbach


1 Answers

Video streams are usually inter-coded i.e. most frames rely on other frames to be decoded. So, when such a stream is trimmed, without transcoding, those reference frames, even if not within the trimmed time range, have to be included in the output in order for the video to be playable. Now, the trimming s/w can handle the timestamps of those reference frames in two ways: Assign them a negative PTS, so that they are available for decoding, but not displayed. Or start all timestamps from zero (or any positive value), so that they are displayed as well. In which case, the video trim isn't precise and includes extra frames.

If the main video were trimmed with FFmpeg, you can force the 2nd behaviour by adding -avoid_negative_ts make_zero to the trim command. But don't know how to set that using QT.

like image 148
Gyan Avatar answered Jul 16 '26 04:07

Gyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!