ffmpeg start_time 为负 [英] ffmpeg start_time is negative

查看:123
本文介绍了ffmpeg start_time 为负的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ffmpeg 按开始/结束时间分割视频.例如,我有一组时间 [[0,2],[2,4],[4,6]],我会在这里调用 ffmpeg 3 次以在时间 0、2 创建三个 2 秒的视频, 和 4.

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.

我的问题是这些时间(正确)没有正确分割视频.当我使用 ffprobe -i test.mov -show_format 检查视频的统计信息时,我注意到 start_time=-0.381044.我也知道这似乎是由于在 QuickTime 中修剪视频以制作此视频所致.为了纠正这个问题,我必须在我的代码中的某处添加 (start + 0.381044),并且输出很好.

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.

那么,为什么通过 quicktime 修整将 start_time 设置为负值?如何设置 start_time=0,以便我的代码可以在没有 + 0.381044 的情况下工作?

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?

推荐答案

视频流通常是帧间编码的,即大多数帧依赖于其他帧进行解码.因此,当修剪此类流时,无需转码,即使不在修剪的时间范围内,也必须将这些参考帧包含在输出中,以便视频可播放.现在,修剪软件可以通过两种方式处理这些参考帧的时间戳:为它们分配一个负 PTS,以便它们可用于解码,但不显示.或者从零(或任何正值)开始所有时间戳,以便它们也显示出来.在这种情况下,视频修剪不精确并且包含额外的帧.

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.

如果主视频是使用 FFmpeg 修剪的,您可以通过将 -avoid_negative_ts make_zero 添加到修剪命令来强制第二行为.但不知道如何使用 QT 设置.

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.

这篇关于ffmpeg start_time 为负的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆