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

问题描述

我想使用libavcodec将视频编码为H264



ffmpeg :: avcodec_encode_video(codec,output,size,avframe) / code>



返回一个错误,我没有正确设置avframe-> pts值。

我试过设置它到0,1,AV_NOPTS_VALUE和90khz * framenumber,但仍然得到错误非严格单调的PTS



ffmpeg.c示例使用ffmpeg :: av_rescale_q()设置packet.pts,但这只有在编码帧后才会调用!



与MP4V编解码器我有同样的问题,解决它通过计算pts之前调用avcodec_encode_video()。如下:

  //计算PTS:(1 / FPS)*采样率*帧数
// sample速率90KHz是用于h.264在30 fps
picture-> pts =(1.0 / 30)* 90 * frame_count;
out_size = avcodec_encode_video(c,video_outbuf,video_outbuf_size,picture);

解决方案从



(注意:更改采样率为khz,以hz表示长帧之间,可能需要使用这个值 - 不是一个视频编码专家在这里,只是想要的东西,工作,这样做)


I'm trying to encode video as H264 using libavcodec

ffmpeg::avcodec_encode_video(codec,output,size,avframe);

returns an error that I don't have the avframe->pts value set correctly.
I have tried setting it to 0,1, AV_NOPTS_VALUE and 90khz * framenumber but still get the error non-strictly-monotonic PTS

The ffmpeg.c example sets the packet.pts with ffmpeg::av_rescale_q() but this is only called after you have encoded the frame !

When used with the MP4V codec the avcodec_encode_video() sets the pts value correctly itself.

解决方案

I had the same problem, solved it by calculating pts before calling avcodec_encode_video as follows:

//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);

Solution stolen from this helpful blog post

(Note: Changed sample rate to khz, expressed in hz was far too long between frames, may need to play with this value - not a video encoding expert here, just wanted something that worked and this did)

这篇关于ffmpeg :: avcodec_encode_video设置PTS h264的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 07:32