From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9812340759 for ; Sun, 30 Jan 2022 06:30:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0D97F68B1F6; Sun, 30 Jan 2022 08:28:44 +0200 (EET) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn2051.outbound.protection.outlook.com [40.92.90.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7823B68B1F6 for ; Sun, 30 Jan 2022 08:28:42 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fuNLqXds10MFt+oyo2B87XsDGsfBX+qdBrVAVb3Rw6B44soNlSIu0og3xZnfM3Wm6dIOiN1cvoB7QXv6IQUXPq59o0Kp9cRBIzYfwGuMN1enQgO9Fz7P3IRSrZVaTWP+OH8HzGqPKzg2KcBUwlfFnRtBTlbjafc3XlMzsropDyCEkbLLIJGRYDD7Tro9cJY+iDYCKqNkU4+ZysRVTzLwRe9L/e0HDD9LbUPJDoCQrLGY1tjdCGyVZxML6sWrNpwvraLi8cATlYOwcrwzi8KE6+GwEe45uDm6FEAXKMqJbxsIDq7BmnjyQeuulk5k0hPE8ygtwd0FRYHqj3P+si6PUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ib/G6v+Ho++EsJ3OR21EJ0DOqkx3uAqTp5I8wtBJ9T0=; b=gezq4oii+/ual1F9U4sHsEscHtIgcGUVlCLwTZyT8qXQrpE6mLvSW6ffy5XT3Jw3DEQU4NtwO79SuD6mU9TFdpqZsiW6gr3feVwuwOyHKUMZ2SC7+3iRMHSXM+zWYi4SW1J55/1Fk0SRHWHJakrHYqaZGsBfao6MoBPVADHcXCCgm1FyebkcNFSUOXBTWydobG9bP3MIfZYmwvint9GZwaZanyTbJykt+k1hfZRdG98ILM/8MnXBlem8Gpp146UhYbDOLVdnT8NJJqchbVx8RxDzNJI3mwQTTpRA17QKUQKti7bP8d442cqZ9UBZ96wBLUMGQLl/O1hKMDYhgiJVcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ib/G6v+Ho++EsJ3OR21EJ0DOqkx3uAqTp5I8wtBJ9T0=; b=T/khhghWrYQgO1mkykKBdnuhj1YaLLmXdPZHRaAADrmudWdC0Ri5d6tNHT1UgL7tW+3SQ91wojdV+/KYHZ7gG0g8hkG2WwJOrRDZJ3MdnBq4t32lREi18pzTr1hp3EN0SrKMMMnaObEnkh0ph7SCrKqLrGoZGF4/er1AD+HJ4iW45tDZFP5180PQDUfaNVOffP1qaU/PZor1l8wieJ+XNuY/EJMiPMluo21PQ0lj3Nv+hu+X1cV10mcRexQLyFRQ/b8whrIioAtNZ7m1jUHhScqRoIS7oNASwsr6WlmP/0+rWkSxlp/H/l5Z0f7+V6E8DXRCq3cZQyfV4x70X5RFGQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by PAXPR03MB7666.eurprd03.prod.outlook.com (2603:10a6:102:202::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Sun, 30 Jan 2022 06:28:41 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%6]) with mapi id 15.20.4930.021; Sun, 30 Jan 2022 06:28:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Jan 2022 07:27:27 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [LsDCflzV2hTGc+oEcRXOfoKt8JLP8z4G] X-ClientProxiedBy: AM6PR10CA0044.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::21) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220130062749.936489-18-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e2244da-df12-4936-996a-08d9e3b9c1e8 X-MS-TrafficTypeDiagnostic: PAXPR03MB7666:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QhqZe7uwQz/nyn+pM9Kr1dZaOyujpn4Mhp3Jf+nC+RUutpLakwo552C5zNp/fovpQg0KTSk+h4Ojwio38w3DE9kQytbvIT/+6f0Ri67YwQL0MuAlKEAB0aLWpKpEXFCkL8v7RIj84gCY/PQZdOPB75I90Ak48ftFOCRsGt6u/sTRsaK+fGkkpUReobgAK6NRctDB3CqF1k2EfGUDAQ9s+Al2+aog4w+uNHs8PQBeEpA/pwOFT0DHM8jzIHvbUgagguAEX+cJfPOsKjJXu1Kvqf0v0VAxZA1VZ1iQv2TY+YRq9yMH40FvIvlFXhO/oGbrP6LfLXaeCd8GUXs3E3WBLrElyKH1h9ujMVjVKRRWGf6/eFYtnYY93WOW9GJzg9yoZMfczGRMRTILIYXDQYzNblE8JXOolzk5tRUX4xAXnK42AyxsxTy5o1aN7XhbYYAsrh0g240i63btX0cyHDaT3Grst0QdrUYquC30WGg5WkBTf2meXf25Y3vuOjWX7Q0Ec17d24CaVWTXQX3H+xTRs56cPVasgM551+/3XDIn+dPROfkRacT6smZbsr0gkYhm X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?GtMrREKIeGrK824toV3SLoMfWOK0d9hvXqcwAh00zLXg+oV1AxNes4p8Ip6Y?= =?us-ascii?Q?leqTTzjItXh65rVJNTegMfxaq8CfT8JZesjrAqwLWwrk1DHn2H4b5riUNNbX?= =?us-ascii?Q?5lEtuix54KstzEJ3xPeJhDIEePZuy6wWTBrTrI1sjxh/UciAq4ouogSoPf50?= =?us-ascii?Q?IHjcBTdF7UtJbzZZ+N3R7wpdWP+kSQrmnlSA5LNBt1r+hS4HGC4e0exwDNcH?= =?us-ascii?Q?l1uSxR1kedy7WtCYr2fTsBnVj60ivSCAu9+N9T8hLDukDeSKqaw6Q3I+QsLK?= =?us-ascii?Q?ceDrOIFq7G1Zr0OL3sZZqGUjawZb0lW2hYOCfQ6yZTdiQWfAr2uUgE8W6dFe?= =?us-ascii?Q?gJyWRXO6TtImtOnATC7CtUqhZuWUMrAevV4oqrO/5KHV6s0YWjor47MGqB+k?= =?us-ascii?Q?SI9XL3xWKV2AfZKq8rUqAPZIhelKH6xYP5UO+thAKC3BcDGKmcpYwyOOaOtV?= =?us-ascii?Q?tzgC2UFcLQR6u5N+uMKZg+2KIbwjf4t+iC5OvPheiQpotT6zqQtVbz0JjUHP?= =?us-ascii?Q?bp40/TOElK5+jTNvtGwg6FHRPyI3NS4mgrk3+HSYBERTo6A4196LNGEt1jon?= =?us-ascii?Q?OkoCHU3F1u1chVcYu9UuS48G0r2U37soDy5YD5QMrJHOhhlc/joO9+MW1zxC?= =?us-ascii?Q?9jDD8uM9pVpmVAlodQ9W+uzn0+ehkYmGDmdYPMZqVP6LcIHAa6NEQIthazBD?= =?us-ascii?Q?X7drCzL62ndoJM1nnp/hopAosRm/lZ+mKMBSomDbi1D+pbl5DcPZzZsNJc0k?= =?us-ascii?Q?t8GNcIU9nzs8/ToS57BZ6lor8BUmflAg/68Ns468o8mS1jngvsLuTyZA7Fgo?= =?us-ascii?Q?PWETVRlksXVIetA+sRoE7vKUmeBP49ROBEnpTXFkWTpSgAa6vasiF+afYPC3?= =?us-ascii?Q?c9Bet+y6ILbqcaKPmNn0e51q5GG5C4KgjsRep/FE8/za8GOzgIhaP92wFMCg?= =?us-ascii?Q?OE/EZLqVVTtNO0Jb+7NxQg=3D=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e2244da-df12-4936-996a-08d9e3b9c1e8 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2022 06:28:41.2274 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR03MB7666 Subject: [FFmpeg-devel] [PATCH 19/41] avcodec/mpegvideoenc: Move tmp bframes to MPVMainEncContext 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: Andreas Rheinhardt Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Also move b_frame_strategy and b_sensitivity; they are all only used by an encoder's main thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 5 ---- libavcodec/mpegvideo_enc.c | 55 +++++++++++++++++++------------------- libavcodec/mpegvideoenc.h | 13 ++++++--- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 1bad288ea5..e83061fa92 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -530,11 +530,6 @@ typedef struct MPVContext { int error_rate; - /* temporary frames used by b_frame_strategy = 2 */ - AVFrame *tmp_frames[MAX_B_FRAMES + 2]; - int b_frame_strategy; - int b_sensitivity; - /* frame skip options for encoding */ int frame_skip_threshold; int frame_skip_factor; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index a42cc0fa51..bbff65ef41 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -610,10 +610,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (s->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) { + if (m->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) { av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n"); - s->b_frame_strategy = 0; + m->b_frame_strategy = 0; } i = av_gcd(avctx->time_base.den, avctx->time_base.num); @@ -902,17 +902,17 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) if ((ret = ff_rate_control_init(m)) < 0) return ret; - if (s->b_frame_strategy == 2) { + if (m->b_frame_strategy == 2) { for (i = 0; i < s->max_b_frames + 2; i++) { - s->tmp_frames[i] = av_frame_alloc(); - if (!s->tmp_frames[i]) + m->tmp_frames[i] = av_frame_alloc(); + if (!m->tmp_frames[i]) return AVERROR(ENOMEM); - s->tmp_frames[i]->format = AV_PIX_FMT_YUV420P; - s->tmp_frames[i]->width = s->width >> s->brd_scale; - s->tmp_frames[i]->height = s->height >> s->brd_scale; + m->tmp_frames[i]->format = AV_PIX_FMT_YUV420P; + m->tmp_frames[i]->width = s->width >> s->brd_scale; + m->tmp_frames[i]->height = s->height >> s->brd_scale; - ret = av_frame_get_buffer(s->tmp_frames[i], 0); + ret = av_frame_get_buffer(m->tmp_frames[i], 0); if (ret < 0) return ret; } @@ -933,14 +933,13 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) { MPVMainEncContext *const m = avctx->priv_data; MPVMainContext *const s = &m->common; - int i; ff_rate_control_uninit(m); ff_mpv_common_end(&m->common); - for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++) - av_frame_free(&s->tmp_frames[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(m->tmp_frames); i++) + av_frame_free(&m->tmp_frames[i]); ff_mpv_picture_free(avctx, &s->new_picture); @@ -1265,18 +1264,18 @@ static int estimate_best_b_count(MPVMainEncContext *m) data[2] += INPLACE_OFFSET; } - s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[0], - s->tmp_frames[i]->linesize[0], + s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[0], + m->tmp_frames[i]->linesize[0], data[0], pre_input.f->linesize[0], width, height); - s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1], - s->tmp_frames[i]->linesize[1], + s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[1], + m->tmp_frames[i]->linesize[1], data[1], pre_input.f->linesize[1], width >> 1, height >> 1); - s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[2], - s->tmp_frames[i]->linesize[2], + s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[2], + m->tmp_frames[i]->linesize[2], data[2], pre_input.f->linesize[2], width >> 1, height >> 1); @@ -1313,10 +1312,10 @@ static int estimate_best_b_count(MPVMainEncContext *m) goto fail; - s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I; - s->tmp_frames[0]->quality = 1 * FF_QP2LAMBDA; + m->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I; + m->tmp_frames[0]->quality = 1 * FF_QP2LAMBDA; - out_size = encode_frame(c, s->tmp_frames[0], pkt); + out_size = encode_frame(c, m->tmp_frames[0], pkt); if (out_size < 0) { ret = out_size; goto fail; @@ -1327,11 +1326,11 @@ static int estimate_best_b_count(MPVMainEncContext *m) for (i = 0; i < s->max_b_frames + 1; i++) { int is_p = i % (j + 1) == j || i == s->max_b_frames; - s->tmp_frames[i + 1]->pict_type = is_p ? + m->tmp_frames[i + 1]->pict_type = is_p ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B; - s->tmp_frames[i + 1]->quality = is_p ? p_lambda : b_lambda; + m->tmp_frames[i + 1]->quality = is_p ? p_lambda : b_lambda; - out_size = encode_frame(c, s->tmp_frames[i + 1], pkt); + out_size = encode_frame(c, m->tmp_frames[i + 1], pkt); if (out_size < 0) { ret = out_size; goto fail; @@ -1418,11 +1417,11 @@ static int select_input_picture(MPVMainEncContext *m) } } - if (s->b_frame_strategy == 0) { + if (m->b_frame_strategy == 0) { b_frames = s->max_b_frames; while (b_frames && !s->input_picture[b_frames]) b_frames--; - } else if (s->b_frame_strategy == 1) { + } else if (m->b_frame_strategy == 1) { for (i = 1; i < s->max_b_frames + 1; i++) { if (s->input_picture[i] && s->input_picture[i]->b_frame_score == 0) { @@ -1436,7 +1435,7 @@ static int select_input_picture(MPVMainEncContext *m) for (i = 0; i < s->max_b_frames + 1; i++) { if (!s->input_picture[i] || s->input_picture[i]->b_frame_score - 1 > - s->mb_num / s->b_sensitivity) + s->mb_num / m->b_sensitivity) break; } @@ -1446,7 +1445,7 @@ static int select_input_picture(MPVMainEncContext *m) for (i = 0; i < b_frames + 1; i++) { s->input_picture[i]->b_frame_score = 0; } - } else if (s->b_frame_strategy == 2) { + } else if (m->b_frame_strategy == 2) { b_frames = estimate_best_b_count(m); if (b_frames < 0) return b_frames; diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 8369254bff..c1013316aa 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -35,6 +35,11 @@ typedef MPVContext MPVEncContext; typedef struct MPVMainEncContext { MPVMainContext common; + + /* temporary frames used by b_frame_strategy == 2 */ + AVFrame *tmp_frames[MAX_B_FRAMES + 2]; + int b_frame_strategy; + int b_sensitivity; } MPVMainEncContext; /* mpegvideo_enc common options */ @@ -115,8 +120,8 @@ FF_MPV_OPT_CMP_FUNC, \ {"intra_penalty", "Penalty for intra blocks in block decision", FF_MPV_OFFSET(intra_penalty), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX/2, FF_MPV_OPT_FLAGS }, \ #define FF_MPV_COMMON_BFRAME_OPTS \ -{"b_strategy", "Strategy to choose between I/P/B-frames", FF_MPV_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS }, \ -{"b_sensitivity", "Adjust sensitivity of b_frame_strategy 1", FF_MPV_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS }, \ +{"b_strategy", "Strategy to choose between I/P/B-frames", FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS }, \ +{"b_sensitivity", "Adjust sensitivity of b_frame_strategy 1", FF_MPV_MAIN_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"brd_scale", "Downscale frames for dynamic B-frame decision", FF_MPV_OFFSET(brd_scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS }, #if FF_API_MPEGVIDEO_OPTS @@ -127,8 +132,8 @@ FF_MPV_OPT_CMP_FUNC, \ #define FF_MPV_DEPRECATED_MATRIX_OPT \ { "force_duplicated_matrix", "Deprecated, does nothing", FF_MPV_OFFSET(dummy), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, #define FF_MPV_DEPRECATED_BFRAME_OPTS \ - { "b_strategy", "Deprecated, does nothing", FF_MPV_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ - { "b_sensitivity", "Deprecated, does nothing", FF_MPV_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, { .i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ + { "b_strategy", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ + { "b_sensitivity", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, { .i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ { "brd_scale", "Deprecated, does nothing", FF_MPV_OFFSET(brd_scale), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, #endif -- 2.32.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".