From 68413d4ee19d716205f950e3bd81ea511e2051cb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jul 2022 10:42:49 +0200 Subject: lavc/encode: combine setting no-delay pts for video/audio --- libavcodec/encode.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index d0c3903258..da910b1b60 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -209,12 +209,8 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt) * (due to the delay inherent in frame threaded encoding, it makes * no sense to use the properties of the current frame anyway). */ ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet); - else { + else ret = codec->cb.encode(avctx, avpkt, frame, &got_packet); - if (avctx->codec->type == AVMEDIA_TYPE_VIDEO && !ret && got_packet && - !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) - avpkt->pts = frame->pts; - } av_assert0(ret <= 0); @@ -227,10 +223,14 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt) goto end; } - if (frame && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) { + // set the timestamps for the simple no-delay case + // encoders with delay have to set the timestamps themselves + if (!(avctx->active_thread_type & FF_THREAD_FRAME) && + !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) { + if (avpkt->pts == AV_NOPTS_VALUE) + avpkt->pts = frame->pts; + if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { - if (avpkt->pts == AV_NOPTS_VALUE) - avpkt->pts = frame->pts; if (!avpkt->duration) avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); -- cgit v1.2.3