From patchwork Fri Feb 10 23:29:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 40361 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp1772665pzk; Fri, 10 Feb 2023 15:30:23 -0800 (PST) X-Google-Smtp-Source: AK7set//tP8VbQEHfmckEkk1NvPT02N0NowQTeTKv/AjR96sC09ltdJhrrgXNKwB8+8qf4/sm4gF X-Received: by 2002:a17:906:2851:b0:8a6:93a4:c892 with SMTP id s17-20020a170906285100b008a693a4c892mr17431585ejc.44.1676071823207; Fri, 10 Feb 2023 15:30:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676071823; cv=none; d=google.com; s=arc-20160816; b=KoWd8vzgo/9HWFwWDey8n5CRTrVL0H9Sb9/gZskEstEFjIQ0/l/d/Scsal/twt2172 7LLHxLcpKQhhi9dqV/nFNHMP75Wkh5ymiA4wyoWN2HhyKxEjmhlgI7iq7yv7rd6UEOGE geFRGIOd+13aGIwFlfDNru0GUPwjhKxlfbkEIO8uFV+5up5Mzeb4sQUN748UzB6ecZLI F1uSOxGTsQAOfwOxj3t+ZFzzeHDdj98dN8xVUyNGIFAD7H+mkBUtSGqc+T65RSgzRbk3 oENuO81tfrAX6h0aJx+eBamhXU5MVUztaYb0OAu41y+DbLdRQEVZ7qXCrYg/HXyCDxvG OYcw== 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=aToI9JxAezROBf3vY8Potbv3ziuop+WfaRu1URexnI4=; b=hqZT9zx7dgCvmnsmMWZzOhIH8ozEXxVwKwGzP4cU0vzrRU95wBNoB45zTS65KVpSlB mWyiRVrd0cGg2yYuDQkbgGqogLlA1rsutGAbPXlPzRQK6tlo5M4zS9IpKe8laR2UgecO m23LFZNUMzGRf9376QXYbxzZCbgxNctvifr+Z4Sa+moXEuGQdHg6NaNLb5eATTRjX2GH NNqnutXP+PwFPqKJsv3BuUAvW99HWPemickG1EMm1iQ9nUuDcbkg74HBXLh0NPTm2tHq BvOA3kcbg9j9ocpm5jclDUF9LKkVaVBntIOwSxVYhKw0dqRF0v6/8RlWJHTe05fVnNLm GYlA== 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 s6-20020a170906220600b0088bdef7592dsi7862438ejs.365.2023.02.10.15.30.22; Fri, 10 Feb 2023 15:30:23 -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 383D568BD12; Sat, 11 Feb 2023 01:30:10 +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 8EB0768BA8D for ; Sat, 11 Feb 2023 01:30:02 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 73E7CE8799; Sat, 11 Feb 2023 00:30:01 +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 HN6kwdWD_uRT; Sat, 11 Feb 2023 00:30:00 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 82B59E87A2; Sat, 11 Feb 2023 00:29:57 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Feb 2023 00:29:12 +0100 Message-Id: <20230210232913.8763-3-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230210232913.8763-1-cus@passwd.hu> References: <20230128181523.9837-1-cus@passwd.hu> <20230210232913.8763-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: xfgu9cAF8+gh 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 26cf33a3c6..a932b59678 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -419,10 +419,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 0e6a4c4ec5..7d3c8875f2 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; } @@ -1954,7 +1957,7 @@ vbv_retry: pkt->pts = s->current_picture.f->pts; pkt->duration = s->current_picture.f->duration; 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 17c704716d..658684c575 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)