ffmpeg start_time is negative

时光毁灭记忆、已成空白 提交于 2020-08-09 09:26:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41032079/ffmpeg-start-time-is-negative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!