[英]PTS not set after decoding H264/RTSP stream
Question : What does the Libav/FFmpeg decoding pipeline need in order to produce valid presentation timestamps (PTS) in the decoded AVFrames? 问题 : 为了在解码的AVFrame中生成有效的演示时间戳(PTS),Libav / FFmpeg解码流水线需要什么?
I'm decoding an H264 stream received via RTSP. 我正在解码通过RTSP收到的H264流。 I use Live555 to parse H264 and feed the stream to my LibAV decoder.
我使用Live555解析H264并将流提供给我的LibAV解码器。 Decoding and displaying is working fine, except I'm not using timestamp info and get some stuttering.
解码和显示工作正常,除了我没有使用时间戳信息并得到一些口吃。
After getting a frame with avcodec_decode_video2
, the presentation timestamp (PTS) is not set. 使用
avcodec_decode_video2
获取帧后,未设置演示时间戳(PTS)。
I need the PTS in order to find out for how long each frame needs to be displayed, and avoid any stuttering. 我需要PTS才能找出每帧需要显示多长时间,并避免任何口吃。
AVCodecContext->extradata
. AVCodecContext->extradata
获取SPS / PPS信息,我将这些值复制到我的AVCodecContext->extradata
。 AVCodecContext->time_base
is not valid, value is 0/2. AVCodecContext->time_base
无效,值为0/2。 time_base
value not valid? time_base
值无效? Where is this information? The RTP timestamp is set to the sampling timestamp of the content.
RTP时间戳设置为内容的采样时间戳。 A 90 kHz clock rate MUST be used.
必须使用90 kHz时钟速率。
Copy the live555 pts into the avpacket pts. 将live555 pts复制到avpacket pts。 Process the packet with avcodec_decode_video2, and then retrieve the pts from avframe->pkt_pts, these will be monotonically increasing.
使用avcodec_decode_video2处理数据包,然后从avframe-> pkt_pts中检索pts,这些将单调增加。
There is no need to set anything in the codec context, apart from setting the SPS and PPS in the AVCodecContex extradata 除了在AVCodecContex extradata中设置SPS和PPS之外,无需在编解码器上下文中设置任何内容
You can find a good example in VLC's github: Setting AVPacket pts: https://github.com/videolan/vlc/blob/master/modules/codec/avcodec/video.c#L983 你可以在VLC的github中找到一个很好的例子:设置AVPacket点: https : //github.com/videolan/vlc/blob/master/modules/codec/avcodec/video.c#L983
Decoding AVPacket into AVFrame: https://github.com/videolan/vlc/blob/master/modules/codec/avcodec/video.c#L1014 将AVPacket解码为AVFrame: https : //github.com/videolan/vlc/blob/master/modules/codec/avcodec/video.c#L1014
Retrieving from AVFrame pts: https://github.com/videolan/vlc/blob/master/modules/codec/avcodec/video.c#L1078 从AVFrame中检索: https : //github.com/videolan/vlc/blob/master/modules/codec/avcodec/video.c#L1078
avcodec_decode_video2() reorders the frames so that decode order and presentation order is the same. avcodec_decode_video2()重新排序帧,使解码顺序和呈现顺序相同。 Even if you somehow convince ffmpeg to give you PTS on the decoded frame it should be the same as DTS.
即使你以某种方式说服ffmpeg在解码帧上给你PTS它应该和DTS一样。
//
// decode a video frame
//
avcodec_decode_video2
(
ctxt->video_st->codec,
frame,
&is_finished,
buffer
);
if (buffer->dts != AV_NOPTS_VALUE)
{
//
// you should end up here
//
pts = buffer->dts;
}
else
{
pts = 0;
}
//
// adjust time base
//
pts *= av_q2d(ctxt->video_st->time_base);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.