使用ffmpeg在pts_time之前的0.000057秒出现帧 [英] frame appears 0.000057 second before pts_time using ffmpeg

查看:70
本文介绍了使用ffmpeg在pts_time之前的0.000057秒出现帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此视频是使用以下方法创建的ffmpeg命令,来自一系列带有编号和预期时间戳记的图像(假定120 fps恒定帧速率):

This video is created using ffmpeg command from a series of images with number and expected timestamp on it (assuming 120 fps constant frame rate):

ffmpeg -framerate 120 -i %03d.png -crf 0 -x264opts keyint=1:min-keyint=1 120.mp4

假定帧速率恒定,并且所有帧均为I帧.我预计第6帧将恰好在时间0.05秒[0.05,0.0583333)上显示,如ffmpeg和ffprobe中所示的pts_time:

It's supposed to be constant frame rate, and all the frames are I frames. I expect frame 6 will show up exactly at time 0.05 second [0.05, 0.0583333), as the pts_time shown in ffmpeg and ffprobe:

[Parsed_showinfo_0 @ 0x7fba11404080] n:6点:768点时间:0.05pos:36021 fmt:yuv444p sar:0/1 s:1552x878 i:P iskey:1类型:I校验和:2CDED07A plane_checksum:[A86DBAAD C4CB8EF2 DDC586CC]平均值:[163 133 121] stdev:[9.0 0.6 0.8]

[Parsed_showinfo_0 @ 0x7fba11404080] n: 6 pts: 768 pts_time:0.05 pos: 36021 fmt:yuv444p sar:0/1 s:1552x878 i:P iskey:1 type:I checksum:2CDED07A plane_checksum:[A86DBAAD C4CB8EF2 DDC586CC] mean:[163 133 121 ] stdev:[9.0 0.6 0.8 ]

[FRAME]
media_type=video
stream_index=0
key_frame=1
pkt_pts=768
pkt_pts_time=0.050000
pkt_dts=768
pkt_dts_time=0.050000
best_effort_timestamp=768
best_effort_timestamp_time=0.050000
pkt_duration=128
pkt_duration_time=0.008333
pkt_pos=36021
pkt_size=2531
width=1552
height=878
pix_fmt=yuv444p
sample_aspect_ratio=N/A
pict_type=I
coded_picture_number=6
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
color_range=unknown
color_space=unknown
color_primaries=unknown
color_transfer=unknown
chroma_location=left
[/FRAME]

但是实际上,它是从0.049943秒开始显示的.我使用ffmpeg提取时间为0.0001秒的时间

But in reality, it shows up since 0.049943 second. I use ffmpeg to extract that time with 0.0001 second duration

ffmpeg -ss 00:00:00.049943 -i 120_keyint_1.mp4 -t 00:00:00.0001 out.mp4

并获取此视频,显示第6帧.

我也尝试在chrome上播放此视频,并设置了videoNode的currentTime.它显示第5帧为0.049943,但显示第6帧为0.049968(在0.05之前)!

I also tried playing this video on chrome, and set the currentTime of videoNode. It shows frame 5 at 0.049943, but shows frame 6 since 0.049968 (before 0.05!).

但是,我尝试了另一种编码方法并获得了另一种恒定帧频视频:

However, I tried another encoding method and get another constant frame rate video:

ffmpeg -framerate 120 -i %03d.png -vcodec libx264 -f mp4 -movflags faststart 120.mp4

理论上,第6帧也应出现在时间范围[0.05,0.0583333)中,但在Chrome中,第6帧直到currentTime> = 0.051秒才显示.更有趣的是,我使用ffmpeg在0.049943秒处获得了第6帧,与上面的提取命令相同.

theoretically frame 6 should also appear in time range [0.05, 0.0583333), but in Chrome frame 6 will not show up until currentTime >= 0.051 second. More interestingly, I get frame 6 at 0.049943 second using ffmpeg, the same extraction command above.

这是否意味着在MPEG4 h.264视频中,我们不能依靠ffmpeg中的pts_time来确定特定帧及其特定视频播放器的确切显示时间?

Does this mean in MPEG4 h.264 video, we cannot rely on pts_time from ffmpeg to determine exact show time of a specific frame and it's video player specific?

推荐答案

我认为问题是文件中的Movie Header标尺为1000,这是ffmpeg的硬连线默认值.(libavformat \ movenc.h第32行: #define MOV_TIMESCALE 1000 )

I think the issue is the Movie Header scale of 1000 in your file which is the hard wired default of ffmpeg. (libavformat\movenc.h line 32: #define MOV_TIMESCALE 1000)

您的120 fps帧速率无法在1/1000秒内表示出来-因此ffm​​peg会产生舍入误差.

Your frame rate of 120 fps can't be express in 1/1000s - so ffmpeg produces rounding errors.

1000作为默认时间标度是一个糟糕的选择,如果不修改ffmpeg的源代码就无法更改它.

1000 as default time scale is a poor choice and it can't be changed without modifying ffmpeg's source code.

我会将 #define MOV_TIMESCALE 1000 更改为 #define MOV_TIMESCALE 600 或其他可被120整除的值,然后重新编译ffmpeg.

I would change #define MOV_TIMESCALE 1000 to #define MOV_TIMESCALE 600 or some other value that is divisible by 120 and recompile ffmpeg.

这篇关于使用ffmpeg在pts_time之前的0.000057秒出现帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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