ffmpeg::avcodec_encode_video setting PTS h264

前端 未结 4 1077
执念已碎
执念已碎 2020-12-28 20:43

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 hav

4条回答
  •  臣服心动
    2020-12-28 21:34

    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)

提交回复
热议问题