[FFmpeg-devel] [PATCH v2] doc/examples/vaapi_transcode: fix null framerate

jianfeng.zheng ggjogh at gmail.com
Fri Apr 7 14:34:28 EEST 2023


When framerate in codec layer is null, guess from stream.

Signed-off-by: jianfeng.zheng <jianfeng.zheng at mthreads.com>
---
 doc/examples/vaapi_transcode.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c
index 8367cb3040..2277794635 100644
--- a/doc/examples/vaapi_transcode.c
+++ b/doc/examples/vaapi_transcode.c
@@ -143,6 +143,7 @@ static int dec_enc(AVPacket *pkt, const AVCodec *enc_codec)
 {
     AVFrame *frame;
     int ret = 0;
+    AVStream *video = NULL;
 
     ret = avcodec_send_packet(decoder_ctx, pkt);
     if (ret < 0) {
@@ -176,6 +177,11 @@ static int dec_enc(AVPacket *pkt, const AVCodec *enc_codec)
              * xxx: now the sample can't handle resolution change case.
              */
             encoder_ctx->time_base = av_inv_q(decoder_ctx->framerate);
+            if (decoder_ctx->framerate.num == 0) {
+                video = ifmt_ctx->streams[video_stream];
+                if (video->r_frame_rate.num > 0 && video->r_frame_rate.den > 0)
+                    encoder_ctx->time_base = av_inv_q(video->r_frame_rate);
+            }
             encoder_ctx->pix_fmt   = AV_PIX_FMT_VAAPI;
             encoder_ctx->width     = decoder_ctx->width;
             encoder_ctx->height    = decoder_ctx->height;
-- 
2.25.1



More information about the ffmpeg-devel mailing list