From patchwork Tue Apr 6 21:55:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26781 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 662C744AF20 for ; Wed, 7 Apr 2021 00:55:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F51B68A6E7; Wed, 7 Apr 2021 00:55:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068058.outbound.protection.outlook.com [40.92.68.58]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB03A68A5CC for ; Wed, 7 Apr 2021 00:55:46 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dDcDkw8hASV762KMamECrSTdlDJ5WxPKuwGH98XZNh1B3/kOlP18EklDDHOSLB3iTfq5XCNwSuaTKAgCKZX9dU01ZRo4PSUAMnj+kuYm+SqUDuQeh+XhLXs+MKu+n4oxPqap/7ZwKZgpTnwzvZdP3qmFa5GSyTZDVvQmWh5mwrNtAI51ftELsAxqbLzwFoLDOrQ3qN4Cf4DRw9HU8eP/36yhsFaclVfn0nQ6tLpWDQppAPZ7fnli9mbZuYE3AY5X7VtYajx03LJvNDYMgFUrlW3iNT5vkzjN/7CAjQxL+wyB5wr7tHhd2qZB8/78ZzFejrgoDtnpHbv5KgZdE7Fk1g== 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-SenderADCheck; bh=5/7NV3MsnwXQ02LLtb5cXhXFsC4UVA5NFKU8Q3xZRTM=; b=R+lkVbis2xYEnh6nlOxPX7E8/fhSFtwOIgYH56S7gWYyFLlqucY0QSEJfFmV2KJgD7Z4vUzQRXmlOw3JeiuU5+x1rEJcazIxSIhW/CR7YtlMFs/8X2Uv8OlHnWrxGAHEVBMwI2tE7h5l5nZl279yGfmDrrFIKPSNFWb4Z/nTtKVHYUJ3XskwUqEaxPamH9QMbNEzu7hlV4UwH3IX/KovhINP/yzD6IT/ZgfjAQ8jtmHEl5KP60V02XPhBhVFEFtuaVQv+Rrs5f9amhG/iW7pTHjredHJLVUG5fOmR02a3YRAE45pX5iZfgUv9CgvJ7e8hYJKcHMtdOJKJbphuma92g== 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=5/7NV3MsnwXQ02LLtb5cXhXFsC4UVA5NFKU8Q3xZRTM=; b=CCzaWZTZ3SJP7FTT2MGnCZFPvFaqdiK11pMaDSXdHiiYihcOp3P2+F4E7jNtrAQuUrd2ABds9j38HR8XhAmVQCjrfQgLAABe3bsALYn1Tto/qAP0nZgGnjgT+/gLUOi1Jx2gDC4wCxFIn9vv6X+/gyDDxcRzX8UdMCoAMv3qZqD0IA2f3yF6t/zirdFG6+FQfwg6l9yZ3iFSgXq75rlMdHq6yHaYw7YAZ40iVL644YAkE9esCmEnPv/vo3MUX8npjJZDWmqLZMUFoNV2hLDqcbaiv2wjFZbbVmaXMFVSxKiKmbIl5t676KC81ajGygqGz5BnUA1W3zQX6NtQVVtVOQ== Received: from AM5EUR02FT037.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1c::4b) by AM5EUR02HT025.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1c::455) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Tue, 6 Apr 2021 21:55:45 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e1c::46) by AM5EUR02FT037.mail.protection.outlook.com (2a01:111:e400:7e1c::182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Tue, 6 Apr 2021 21:55:45 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:6BFF08467CB5E14DE4EE350EA1F30C487AFAAF64C27133D4AC5065B4C792FF30; UpperCasedChecksum:438AC737458A2809B83D31A6753559661579901EA4A17F714301B31E2F8BB180; SizeAsReceived:7598; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.032; Tue, 6 Apr 2021 21:55:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Apr 2021 23:55:10 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [4OvhhWnGrcHLvHneYYxOoT9v8wVJk26r] X-ClientProxiedBy: ZR0P278CA0046.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::15) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210406215516.832944-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by ZR0P278CA0046.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 21:55:44 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 8b35315c-58f1-47b4-eb68-08d8f946baed X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRct5ooVDkA416xUUNF5iBF4pZ1E7/UJYEW9UuYjm1Qk8wpPkxpldeafhCEoRoDWJBZhM04Trai9M7FfS+KoJ2g81RDZgIobMhCIXWvl40clKBVjWihdWfUefF40SJa8fJC62mf07nb970E+lYkccfl4FBWmz4OZLrI3V/TIgFcTbHg0695xFQkanPQki/WdlPdu91YjBYMmIST7JQQxmNkKQV+646ygEdLmzF2WlYGBUe0G4TRVPIwhWqelAPpifsL8bmq1vi94+51mwbx2jDlEnCH5TSgjPoZiJkfS4HQQeJOCM8tdHIBFf+Na+PZtkxaddYJ1tsrCx+khkXQkAyhr+osAjnhBFp5fegSNWTibs+ybWSdYhQPcLpYVq6J+o6IaA5deOcDALjL+huTOXTEhqu3PUU+MIXeYikL6FbfslaQ5E70g55pURxeZuPassTcfCol4or8qVlEaQKf5Aawulg2wPGno3JoYqQ7zxAq5R7JJ347z2ihWNGu81HYiAC8jm++nC7k498l1M+z/KnaOW0Km+PA6PYvr7OFhuGu0ES2OtrRfr9PdLabJzxJ+J9VdqlSs6z89E4W6fQj6yB4v6HELalFC+ioNKcdKJvpnfGeO0ROatqgTXlnc6OsZwgX67Qd1Fxap2CSONI0qPIutvBKR6D8AWziHj3Ld4yAB1GLNx0eY+L4A7OuQsU0btT+TPbF4NuyD+/AcIMV0X/yxa8gSOUXW5nxFkYQefHqJFTDmCMlUSpAaBUeXxDzbs4= X-MS-TrafficTypeDiagnostic: AM5EUR02HT025: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TDgUQLD5aEB+fSNwTzKwU6kK370teVizxOPgdGvqMY+vZR19Ja/ZMj/M126pqPpO6BVPuVQ++k6JdHQ+YVyL/jKY6QSWNgsAPD84AqQ9CdLQf/JNQqJs96Vd/hN/6NFNyfjVXHbnvbK5f39w8H3BudVhhfmcDFHNgOFDOIk0w2W/zObEGM4Kygx5kJvBKIUIOJIKe9LybJkDI8AbIrhDKc3NDU9rRS2C6QSd/RHW9O2d9cjwPdz2w7T5CcpVlrV9xGTvOtquqy19MNNpN3tAyFT4HErOdO1msKa0z0l3AJjZJdmAkyHSSao2cyM8fHZxYQauOne9B2zAbKAifRARMWf4LHVUTdVYmJI3seIRWxnH4SearTvq9vDxO6sbi5Qa7K4QeByUm+8lp7HlxhIlug== X-MS-Exchange-AntiSpam-MessageData: h00SLl9aUDSgfhjh4XP0N+9oToiMmrzmmM+lVGxJBu/eu0au/OyMiI4Q4IqNqIPQW3oOWM+hC12ThcTIyltdKJ57N+eNpP0naGBPo0GZbYsHZgWuye0nv34RVCm9IF/a46LwcWRi5p4IOm4BTAQPEw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b35315c-58f1-47b4-eb68-08d8f946baed X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 21:55:45.4055 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM5EUR02FT037.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5EUR02HT025 Subject: [FFmpeg-devel] [PATCH 13/19] avcodec/mpeg12enc: Perform size/level/profile checks earlier X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This has the advantage that one does not waste some allocations if one errors out because of these checks. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12enc.c | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index b7d3d1c6b0..8dcc04d341 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -152,19 +152,16 @@ static av_cold int encode_init(AVCodecContext *avctx) max_size, max_size); return AVERROR(EINVAL); } + if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) { + av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); + return AVERROR(EINVAL); + } - if ((ret = ff_mpv_encode_init(avctx)) < 0) - return ret; - - if (find_frame_rate_index(s) < 0) { - if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { - av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n", - avctx->time_base.den, avctx->time_base.num); + if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { + if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { + av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" + "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); return AVERROR(EINVAL); - } else { - av_log(avctx, AV_LOG_INFO, - "MPEG-1/2 does not support %d/%d fps, there may be AV sync issues\n", - avctx->time_base.den, avctx->time_base.num); } } @@ -174,9 +171,9 @@ static av_cold int encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } /* Main or 4:2:2 */ - avctx->profile = s->chroma_format == CHROMA_420 ? FF_PROFILE_MPEG2_MAIN : FF_PROFILE_MPEG2_422; + avctx->profile = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? FF_PROFILE_MPEG2_MAIN + : FF_PROFILE_MPEG2_422; } - if (avctx->level == FF_LEVEL_UNKNOWN) { if (avctx->profile == FF_PROFILE_MPEG2_422) { /* 4:2:2 */ if (avctx->width <= 720 && avctx->height <= 608) @@ -184,7 +181,8 @@ static av_cold int encode_init(AVCodecContext *avctx) else avctx->level = 2; /* High */ } else { - if (avctx->profile != FF_PROFILE_MPEG2_HIGH && s->chroma_format != CHROMA_420) { + if (avctx->profile != FF_PROFILE_MPEG2_HIGH && + avctx->pix_fmt != AV_PIX_FMT_YUV420P) { av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); return AVERROR(EINVAL); @@ -198,16 +196,18 @@ static av_cold int encode_init(AVCodecContext *avctx) } } - if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) { - av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); - return AVERROR(EINVAL); - } + if ((ret = ff_mpv_encode_init(avctx)) < 0) + return ret; - if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { - if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { - av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" - "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); + if (find_frame_rate_index(s) < 0) { + if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { + av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n", + avctx->time_base.den, avctx->time_base.num); return AVERROR(EINVAL); + } else { + av_log(avctx, AV_LOG_INFO, + "MPEG-1/2 does not support %d/%d fps, there may be AV sync issues\n", + avctx->time_base.den, avctx->time_base.num); } }