ffmpeg::avcodec_encode_video setting PTS h264
ffmpeg::avcodec_encode_video setting PTS h264
我正在尝试使用libavcodec将视频编码为H264
ffmpeg::avcodec_encode_video(codec,output,size,avframe);
返回一个错误,我没有正确设置avframe->pts值。
我已经尝试将其设置为0,1,AV_NOPTS_VALUE和90khz *帧数,但仍然得到错误non-strictly-monotonic PTS
ffmpeg.c示例使用ffmpeg::av_rescale_q()设置packet.pts,但这只会在编码帧后调用!
当与MP4V编解码器一起使用时,avcodec_encode_video()会正确地设置pts值。
我有同样的问题,通过在调用avcodec_encode_video之前计算pts来解决它,如下所示:
//Calculate PTS: (1 / FPS) * sample rate * frame number
//sample rate 90KHz is for h.264 at 30 fps
picture->pts = (1.0 / 30) * 90 * frame_count;
out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, picture);
从这篇有用的博客文章中偷来的解决方案
(注意:将采样率更改为khz,以hz表示帧之间的时间太长,可能需要使用此值-这里不是视频编码专家,只是想要一些有效的东西,这确实)
我也有这个问题。我用这种方法解决了这个问题:
在调用
之前ffmpeg::avcodec_encode_video(codec,output,size,avframe);
设置avframe的PTS值为整数值,初始值为0,每次加1,如下所示:
avframe->pts = nextPTS();
nextPTS()的实现是:
int nextPTS()
{
static int static_pts = 0;
return static_pts ++;
}
在给avframe的pts一个值之后,然后对它进行编码。如果编码成功。添加以下代码:
if (packet.pts != AV_NOPTS_VALUE)
packet.pts = av_rescale_q(packet.pts, mOutputCodecCtxPtr->time_base, mOutputStreamPtr->time_base);
if (packet.dts != AV_NOPTS_VALUE)
packet.dts = av_rescale_q(packet.dts, mOutputCodecCtxPtr->time_base, mOutputStreamPtr->time_base);
它将为编码的AVFrame添加正确的dts值。其中,包类型为AVPacket, mOutputCodeCtxPtr类型为AVCodecContext*, mOutputStreamPtr类型为AVStream。
avcodec_encode_video返回0表示当前帧被缓冲,您必须在所有帧被编码后刷新所有缓冲帧。代码刷新所有缓冲帧,类似于:
int ret;
while((ret = ffmpeg::avcodec_encode_video(codec,output,size,NULL)) >0)
;// place your code here.
我也有这个问题。据我所知,错误与dts
out_video_packet.dts = AV_NOPTS_VALUE;
帮我
严格递增单调函数是f(x)
- 使用源读取器从网络摄像头源获取 H264 样本
- 解码H264流时如何跳过帧?
- 从 tcp 服务器打开 8MP H264 流时出现问题
- 将帧从 h264 流解码到 OpenCV Mat
- 如何使用live555提取H264帧
- 如何正确使用 libvlc (C++) 从 h264 视频流中获取帧
- FFMPEG H264对每个图像进行编码
- 带有 H264 编解码器的 libav 错误消息。"非严格单调PTS"
- OpenCV encoding to H264
- 如何将.H264流将其保存到图像?C
- ffmpeg H264一次对帧进行编码,用于网络流传输
- 解码H264/RTSP流之后未设置PT
- 使用 FFMPEG 将每个输入图像转换为 H264 编译时出错,该图像在 MevisLab 中运行的 Visual St
- 用罗技C920捕捉H264到OpenCV
- 寻求使用 FFmpeg 在 mp4 容器中 h264 编解码器的视频帧.数据包 pts 始终为 0
- 将标准的Android H264软件编码器替换为基于ffmpeg的编码器
- h264实时视频流
- 使用 ffmpeg 和分离的 AVCodecContext 解码 h264 rtsp
- H264 编码视频流 FFMPEG C++
- ffmpeg::avcodec_encode_video setting PTS h264