diff options
Diffstat (limited to 'libavcodec/encode.c')
-rw-r--r-- | libavcodec/encode.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/libavcodec/encode.c b/libavcodec/encode.c index da910b1b60..76eb69bba8 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -230,10 +230,13 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt) if (avpkt->pts == AV_NOPTS_VALUE) avpkt->pts = frame->pts; - if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { - if (!avpkt->duration) + if (!avpkt->duration) { + if (frame->duration) + avpkt->duration = frame->duration; + else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); + } } } @@ -424,6 +427,13 @@ FF_ENABLE_DEPRECATION_WARNINGS return ret; } + // only use the frame duration if the timebase is set; + // otherwise we cannot be sure that whatever value it has is in the right + // timebase, so we would produce an incorrect value, which is worse than + // none at all + if (!dst->time_base.num || !dst->time_base.den) + dst->duration = 0; + return 0; } |