From patchwork Sat Jan 28 18:15:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 40163 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp2290680pzj; Sat, 28 Jan 2023 10:15:59 -0800 (PST) X-Google-Smtp-Source: AK7set9km80lByPU1YnBaGm0aRlhPYA4QSY6f0XDuuKesxL/Sng7ZpOQTqcYSLcw8Sddyn709sc3 X-Received: by 2002:a17:906:6a0c:b0:82e:a57b:cc9b with SMTP id qw12-20020a1709066a0c00b0082ea57bcc9bmr4305801ejc.24.1674929759195; Sat, 28 Jan 2023 10:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674929759; cv=none; d=google.com; s=arc-20160816; b=k5WYKfDTlAlWlVz6RFbcBlKwivcWCDaSFsurdWvJ4BLHGByyjFH26zKkzn9/WBhzE2 x5Jx2xYCg5uf5qzxUWJwcHs7oaobErnLUE9Syh7UZKAXFbY6HuunvqTvUCZScVPWW+1X aRl9nbcPzvV/RdYPJZRtTsxkpw0PLd9HRShgia/7V8VOgSrFbBaU65rSFss48AdeOyWq Pe8ICd13I9e55lF9dsrk8Td59k6/x/4tgkmLvai9309INI5az/paG+J53ndC9sNC9MZb 7oivaV5BZwqZznU+rczc1arcD1qgSjf0HokWLayw6ABE7mK+rfBmztds3yNKFeNKyn9X 7pKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=XQevy+YMhxLw/QjG75oWQubqrHYzuCRczJuxTjo5C0k=; b=z3tkQ7i+21/bN3c9WlgCG5ClWqoLCONRLZo5i+YXtRTGm261IISlJPVqCSsNOC0STi XPLaVhlJjsFjsB6OSWH7RnuDrqlvo/aS/CjhfD0+Q+ojFv4Mf+Li2KZ5X5+eMgYlVfAp tw+uhXJoYlZ4W10Yslrlq8T9Sy2TIsOIkjcpi+REsqdHEAUSHLnElPRIGQS/TWA6xkhQ r1h7oR8vFwkn0NKjm2iKbOguSZkkWB8eYSeOUHfIk4a7gWeyTUrdiXZPhpN2VE2ibxYu bGIK2UK3PKxtjB7pWuT5U1FfuxlmUg9YcY5kSBoObZR8DVnv0rPhMa1LvM5QYOqrCKVM Cp6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gi15-20020a1709070c8f00b007bc93454b3fsi8177584ejc.953.2023.01.28.10.15.58; Sat, 28 Jan 2023 10:15:59 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 90FBF68BEBA; Sat, 28 Jan 2023 20:15:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C57B968BEB0 for ; Sat, 28 Jan 2023 20:15:36 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 76E48E85C4; Sat, 28 Jan 2023 19:15:35 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z9_JtNj62VEq; Sat, 28 Jan 2023 19:15:33 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D66FEE8668; Sat, 28 Jan 2023 19:15:32 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Jan 2023 19:15:22 +0100 Message-Id: <20230128181523.9837-3-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230128181523.9837-1-cus@passwd.hu> References: <20230128181523.9837-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/mpegvideo_enc: do not use AVFrame.*_picture_number for encoding X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: W+O9oHsA/7Dm Move these fields to MPEGPicture instead and use that. Signed-off-by: Marton Balint --- libavcodec/mpeg12enc.c | 4 ++-- libavcodec/mpegpicture.c | 4 ++++ libavcodec/mpegpicture.h | 3 +++ libavcodec/mpegvideo_enc.c | 17 ++++++++++------- libavcodec/ratecontrol.c | 4 ++-- libavcodec/snowenc.c | 5 ++--- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index a6663a158b..00a8085d12 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -420,10 +420,10 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) /* time code: we must convert from the real frame rate to a * fake MPEG frame rate in case of low frame rate */ fps = (framerate.num + framerate.den / 2) / framerate.den; - time_code = s->current_picture_ptr->f->coded_picture_number + + time_code = s->current_picture_ptr->coded_picture_number + mpeg12->timecode_frame_start; - mpeg12->gop_picture_number = s->current_picture_ptr->f->coded_picture_number; + mpeg12->gop_picture_number = s->current_picture_ptr->coded_picture_number; av_assert0(mpeg12->drop_frame_timecode == !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME)); if (mpeg12->drop_frame_timecode) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index 977bc65191..3204a70578 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -332,6 +332,8 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic) pic->needs_realloc = 0; pic->reference = 0; pic->shared = 0; + pic->display_picture_number = 0; + pic->coded_picture_number = 0; } int ff_update_picture_tables(Picture *dst, const Picture *src) @@ -397,6 +399,8 @@ int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src) dst->needs_realloc = src->needs_realloc; dst->reference = src->reference; dst->shared = src->shared; + dst->display_picture_number = src->display_picture_number; + dst->coded_picture_number = src->coded_picture_number; return 0; fail: diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index a1455ee13c..7919aa402c 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -76,6 +76,9 @@ typedef struct Picture { int reference; int shared; + + int display_picture_number; + int coded_picture_number; } Picture; /** diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index bb101612e5..4e49a103e1 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1219,7 +1219,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) if (ret < 0) return ret; - pic->f->display_picture_number = display_picture_number; + pic->display_picture_number = display_picture_number; pic->f->pts = pts; // we set this here to avoid modifying pic_arg } else { /* Flushing: When we have not received enough input frames, @@ -1477,14 +1477,14 @@ static int select_input_picture(MpegEncContext *s) !s->next_picture_ptr || s->intra_only) { s->reordered_input_picture[0] = s->input_picture[0]; s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; - s->reordered_input_picture[0]->f->coded_picture_number = + s->reordered_input_picture[0]->coded_picture_number = s->coded_picture_number++; } else { int b_frames = 0; if (s->avctx->flags & AV_CODEC_FLAG_PASS2) { for (i = 0; i < s->max_b_frames + 1; i++) { - int pict_num = s->input_picture[0]->f->display_picture_number + i; + int pict_num = s->input_picture[0]->display_picture_number + i; if (pict_num >= s->rc_context.num_entries) break; @@ -1563,13 +1563,13 @@ static int select_input_picture(MpegEncContext *s) s->reordered_input_picture[0] = s->input_picture[b_frames]; if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; - s->reordered_input_picture[0]->f->coded_picture_number = + s->reordered_input_picture[0]->coded_picture_number = s->coded_picture_number++; for (i = 0; i < b_frames; i++) { s->reordered_input_picture[i + 1] = s->input_picture[i]; s->reordered_input_picture[i + 1]->f->pict_type = AV_PICTURE_TYPE_B; - s->reordered_input_picture[i + 1]->f->coded_picture_number = + s->reordered_input_picture[i + 1]->coded_picture_number = s->coded_picture_number++; } } @@ -1604,6 +1604,8 @@ no_output_pic: ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f); if (ret < 0) return ret; + pic->coded_picture_number = s->reordered_input_picture[0]->coded_picture_number; + pic->display_picture_number = s->reordered_input_picture[0]->display_picture_number; /* mark us unused / free shared pic */ av_frame_unref(s->reordered_input_picture[0]->f); @@ -1618,7 +1620,8 @@ no_output_pic: s->new_picture->data[i] += INPLACE_OFFSET; } } - s->picture_number = s->new_picture->display_picture_number; + s->picture_number = s->current_picture_ptr->display_picture_number; + } return 0; } @@ -1953,7 +1956,7 @@ vbv_retry: pkt->pts = s->current_picture.f->pts; if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) { - if (!s->current_picture.f->coded_picture_number) + if (!s->current_picture.coded_picture_number) pkt->dts = pkt->pts - s->dts_delta; else pkt->dts = s->reordered_pts; diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 4829172c2c..6a40f9cbdc 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -39,8 +39,8 @@ void ff_write_pass1_stats(MpegEncContext *s) snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d " "fcode:%d bcode:%d mc-var:%"PRId64" var:%"PRId64" icount:%d skipcount:%d hbits:%d;\n", - s->current_picture_ptr->f->display_picture_number, - s->current_picture_ptr->f->coded_picture_number, + s->current_picture_ptr->display_picture_number, + s->current_picture_ptr->coded_picture_number, s->pict_type, s->current_picture.f->quality, s->i_tex_bits, diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 171a36ba00..d37c7fdb5a 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -1856,13 +1856,12 @@ redo_frame: ff_snow_release_buffer(avctx); - s->current_picture->coded_picture_number = avctx->frame_num; s->current_picture->pict_type = pic->pict_type; s->current_picture->quality = pic->quality; s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits; - s->m.current_picture.f->display_picture_number = - s->m.current_picture.f->coded_picture_number = avctx->frame_num; + s->m.current_picture.display_picture_number = + s->m.current_picture.coded_picture_number = avctx->frame_num; s->m.current_picture.f->quality = pic->quality; s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start); if(s->pass1_rc)