]> git.sesse.net Git - ffmpeg/commitdiff
mfenc: Fall back to avctx->time_base if avctx->framerate isn't set
authorMartin Storsjö <martin@martin.st>
Wed, 20 May 2020 20:08:17 +0000 (23:08 +0300)
committerMartin Storsjö <martin@martin.st>
Fri, 22 May 2020 18:49:48 +0000 (21:49 +0300)
The framerate field is the one users are supposed to set, but not
all users might be setting it, so it might be good to fall back
time_base in that case.

Signed-off-by: Martin Storsjö <martin@martin.st>
libavcodec/mfenc.c

index edee0510b224a58de72a2c0e38f4c9e4a003b24e..83f26b3cc6a2e3d3c2305cc62cde248f7725db18 100644 (file)
@@ -637,11 +637,19 @@ static int64_t mf_encv_output_score(AVCodecContext *avctx, IMFMediaType *type)
 static int mf_encv_output_adjust(AVCodecContext *avctx, IMFMediaType *type)
 {
     MFContext *c = avctx->priv_data;
+    AVRational framerate;
 
     ff_MFSetAttributeSize((IMFAttributes *)type, &MF_MT_FRAME_SIZE, avctx->width, avctx->height);
     IMFAttributes_SetUINT32(type, &MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
 
-    ff_MFSetAttributeRatio((IMFAttributes *)type, &MF_MT_FRAME_RATE, avctx->framerate.num, avctx->framerate.den);
+    if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
+        framerate = avctx->framerate;
+    } else {
+        framerate = av_inv_q(avctx->time_base);
+        framerate.den *= avctx->ticks_per_frame;
+    }
+
+    ff_MFSetAttributeRatio((IMFAttributes *)type, &MF_MT_FRAME_RATE, framerate.num, framerate.den);
 
     // (MS HEVC supports eAVEncH265VProfile_Main_420_8 only.)
     if (avctx->codec_id == AV_CODEC_ID_H264) {