From patchwork Mon Dec 20 18:27:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32767 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4638303iog; Mon, 20 Dec 2021 10:27:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6nTeQRluMQM4VH/QTcx3zoylbiGP/53R71MwIE8nSe5komMXVJCV3F9r11ysLDffO1dXt X-Received: by 2002:a50:d492:: with SMTP id s18mr16880590edi.145.1640024870765; Mon, 20 Dec 2021 10:27:50 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id js5si12598494ejc.656.2021.12.20.10.27.50; Mon, 20 Dec 2021 10:27:50 -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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Qho20Nv8; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5EA4168AFC0; Mon, 20 Dec 2021 20:27:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075062.outbound.protection.outlook.com [40.92.75.62]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 114BE68AB2E for ; Mon, 20 Dec 2021 20:27:41 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bIFlFThYiufPic1HKJhU2ZdNHGfQiJPaOGNI2ZRTKBIfCuTyYJ1Ni8AGu0tsr4rFxubnxFHtXCH9AnavD3nGhtFkDLguf+c599t3ndeCF2FnQ8t8EcA/z1sMnuYS1c4o1Qm4OTicwenncM3/qUmGcCLE9/mlUC/XgWuiWk+IZE0cQIK5lSD+5kxi9XxB8iB40vt1l/CgwAJ92gOb321c5B1OlUBjt3ADWwJU0eYU2PeMDIQJeP+G25WH8u9bZBkPxaMAlGlsIesTZfyjdysxK7RQujI5jBTn3Gxia6WdeRmJ9FZveF88J2zcGRLt0XDIG7NChwqPMozbUIYj0bP0Ag== 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=BYTWe5opYDlksQIovCVvdglT7S95XJie0BbZimu5mno=; b=lpFfrRKMDl9mGCD+WWo2v3OeVZ/K4x3csn+Lj3A7jZaA12xRC6o5eHrlERG0Pv98QLdBzde2NDvC/ACtUpz87Do1yfbf9ZcLhDqx2+8D/ChW4fB2H9GYCyN2k6CeNthjE6ptK0QdO1H/J4EoyyCNl5CqA+sCbLb9eJROQXmo85nNLInGzisqsu3ZiBWB4VtuLBYsq/svEkSJ296M5uRdbxOJRj6KeqtJQ7UmBlI9eqF3yVuOpNO8YQnnTGIfqRBKsq8ArvnFpBsOtHqjdTIt6Q4AxQdge5EKNrBKnd/J7Ev6de9VKO5NQjcaPxnyHSoA8MkhbgVZ2Y9TbQE5QjnfcQ== 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=BYTWe5opYDlksQIovCVvdglT7S95XJie0BbZimu5mno=; b=Qho20Nv8icV6ZWTmPyFsbfr6j/PcO7+jIw/zRx6o3WK1IIryxaJZdet2eXUvCgt+efcpqLmlxRwuqwKH5ERL9EaObEJYI5pHyQJf9C9i8561dr2y3/KixNV99EkZEE/VGxIlZd7dVtOfEY1UgU1JA62mjoZ127WlF4jVmbu0hvTqXmYKg5W6cRXvqxp2SJz83udT5OzhhO27tbLXW4yQoKGRCv7JiDP0laoeXgxhaA/eoeyb0qvmKzJ9vYB+O9iFqtyfYAvCfYXe2xXTZYdwgN6ByyYJxdXj4ofGAVr85PjfTkNZ0mtAJhaKd5rkpp+XrLTDPZq7fx9gozA8OxgrAA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB5298.eurprd03.prod.outlook.com (2603:10a6:20b:d1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.14; Mon, 20 Dec 2021 18:27:37 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%6]) with mapi id 15.20.4801.020; Mon, 20 Dec 2021 18:27:37 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 20 Dec 2021 19:27:30 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [tHaooJUbvdWo5QujJfF+IMeskXhjdvGX] X-ClientProxiedBy: AS8PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:20b:127::28) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211220182730.194200-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 958239e2-a740-4dd1-d68e-08d9c3e66647 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiR3EehW4kxQzdNcP2D/mG1JktJ3tURytVOVXc9lij6ViTTAtLAYT393Ro6j6ooZxwYZ0GjK9f8uM0YA22YEVPCb17BL7evVIfOEBsvcAnZF83alhUQ6jLKAP0juNQ0JNhjz0nqtHX4Ov5TNR7x3hlNFGmK9nLQB0noOyru2bvwABzKmcAQKESGh+chvJqOfWpD6vRSX3biinJh7Ae0jV4VqMySeX81/d+3nZH08CpLvRHa7A4zO0/+g4unWHryKylB6hc2/kegFHHFtmea1uqNHooyR7EwNAVCv9Ke4Mn7j0s/ghz9/CtXKKwQp9pH5cdJ+IYi8pJYBk9wSOh/L0Vgql3m1hH/ych2bB9D8ZANlB0d+yaCP4xGPTlpJM5Wxw8j8GDUXEtbHM4cKH/mAwIKvNbbdpnNhZW4Mifxi5FUE18TftOGqJ9gwZdgSUfj2bqgxau08+KX29elztQr0ZvCvqVUDDSWxkCO9kuWNkz1v2IekXhl9f74oXxm8+OsRRsUIIfNbbYB13YQzIucKBWDAlGLI90ikeRFcCF66KMnmFA42SJCDNY1w5m4dHycWxfOqykQVNSd1jC63mQvIv/XrShqNbLqWf/Pz22yZ7whDC5kMF1IrOkhR19zYWCjVy+O3kXOgB2C/qexPjf4XYqbxm+/6L9/7PUt/0g55Qk9E9QqabLonllPYvt2fo0YbgGSN6bznvmAuU7JqRtGztiy7tDzBQ88POKI5ilAqNg6xUmyHEM9fZSSdCdcPIv/bVD0= X-MS-TrafficTypeDiagnostic: AM6PR03MB5298:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X3hyPeE/dPR3oGKSuPbbcWCLwglgoPYV0AwKKkgTrnxzYoQ+CxpC4WNe/QfIfRECSfH+qFp53f2ZssKxyA3RHAHKQFzcf48tDFr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FM/T3W4IuaVO4wFJ1Hq20cJJzFEJ/SIyLk8FVrZtKTWkbpP3akL+f/KtN3rB9jz2ZEsfZ8ES4uCSFNkoahUxAL9Lk/dHCmxC8IN8Hkg1rIrycb7De7AV7/GEjz5vrsjuouRIvQfAFW3OpTg2eO/9EALBNS6vCpnXefGkhz/6+4Z6VeovRKkfx377mcK0745QjVc3QGuRnd3Fo6YunEeXZC9TltJyc0NeV0WxdNw8x08tYuhOVcyyjjLU0M9smR50rKxGDsahZye5fizplFPFXUlVouTZL7WM6xfYjGQbhkEebZhHS+XEWSe4VIvHWtpI+M11n8ESdKjC1CIlHqBTHQ3safnMKtofIKRDN6JYOoU5ICFFRxG5pNo6cqces7V5zI4zvnlSmgBGBmT09kJalzPn18OL9wQpaIQn04pPINTN2pxypARowutoHITVj6MepOWTYdRNac6dcM+UB6Yw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 958239e2-a740-4dd1-d68e-08d9c3e66647 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2021 18:27:37.7387 (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: AM6PR03MB5298 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/libx26[45]: Don't forward old x26[45] SEI's 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QpI+m2TsdxXd Currently, user data unregistered SEIs found in input are forwarded as side-data to encoders; for the libx26[45] encoders these are included in the reencoded output (even including x264 SEIs in H.265 and vice versa). This makes tools like mediainfo display the wrong (old) encoding parameters and basically makes these SEI messages useless. This commit therefore filters the SEI messages by some known, recognized encoders away. This fixes tickets #9500 and #9557. Signed-off-by: Andreas Rheinhardt --- 1. Obviously, having to maintain a list of recognized encoders and their uuids is horrible; but I didn't see another way. 2. nvenc is probably also affected by this; but I couldn't test it anyway, so someone else will have to fix it. 3. How could it happen that no one noticed this issue when the SEI patches were applied? libavcodec/Makefile | 6 +++--- libavcodec/libx264.c | 3 ++- libavcodec/libx265.c | 3 ++- libavcodec/sei.c | 38 ++++++++++++++++++++++++++++++++++++++ libavcodec/sei.h | 9 +++++++++ 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 libavcodec/sei.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index fb90ecea84..969311947f 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1066,9 +1066,9 @@ OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o OBJS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.o libwebpenc.o OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER) += libwebpenc_common.o libwebpenc_animencoder.o -OBJS-$(CONFIG_LIBX262_ENCODER) += libx264.o -OBJS-$(CONFIG_LIBX264_ENCODER) += libx264.o -OBJS-$(CONFIG_LIBX265_ENCODER) += libx265.o +OBJS-$(CONFIG_LIBX262_ENCODER) += libx264.o sei.o +OBJS-$(CONFIG_LIBX264_ENCODER) += libx264.o sei.o +OBJS-$(CONFIG_LIBX265_ENCODER) += libx265.o sei.o OBJS-$(CONFIG_LIBXAVS_ENCODER) += libxavs.o OBJS-$(CONFIG_LIBXAVS2_ENCODER) += libxavs2.o OBJS-$(CONFIG_LIBXVID_ENCODER) += libxvid.o diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 2b680abf21..27920ba295 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -468,7 +468,8 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, AVFrameSideData *side_data = frame->side_data[j]; void *tmp; x264_sei_payload_t *sei_payload; - if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED) + if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED || + side_data->size < 16 || ff_sei_is_encoder_uuid(side_data->data)) continue; tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload)); if (!tmp) { diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 7dd70a3450..bb2133f4a4 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -548,7 +548,8 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, void *tmp; x265_sei_payload *sei_payload; - if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED) + if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED || + side_data->size < 16 || ff_sei_is_encoder_uuid(side_data->data)) continue; tmp = av_fast_realloc(ctx->sei_data, diff --git a/libavcodec/sei.c b/libavcodec/sei.c new file mode 100644 index 0000000000..8678704e6f --- /dev/null +++ b/libavcodec/sei.c @@ -0,0 +1,38 @@ +/* + * Filtering of H.26[45] encoder user data unregistered SEI messages + * Copyright (C) 2021 Andreas Rheinhardt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include "sei.h" + +int ff_sei_is_encoder_uuid(const uint8_t uuid[16]) +{ + static const uint8_t x264_uuid[] = { + 0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7, + 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef + }; + static const uint8_t x265_uuid[] = { + 0x2c, 0xa2, 0xde, 0x09, 0xb5, 0x17, 0x47, 0xdb, + 0xbb, 0x55, 0xa4, 0xfe, 0x7f, 0xc2, 0xfc, 0x4e + }; + return !memcmp(uuid, x264_uuid, sizeof(x264_uuid)) || + !memcmp(uuid, x265_uuid, sizeof(x265_uuid)); +} diff --git a/libavcodec/sei.h b/libavcodec/sei.h index 5513590b51..e143e0f045 100644 --- a/libavcodec/sei.h +++ b/libavcodec/sei.h @@ -19,6 +19,8 @@ #ifndef AVCODEC_SEI_H #define AVCODEC_SEI_H +#include + // SEI payload types form a common namespace between the H.264, H.265 // and H.266 standards. A given payload type always has the same // meaning, but some names have different payload types in different @@ -137,4 +139,11 @@ enum { SEI_TYPE_SAMPLE_ASPECT_RATIO_INFO = 204, }; +/** + * Returns 0 iff the uuid does not match the uuid of + * a user_data_unregistered SEI message emitted by + * a recognized encoder. + */ +int ff_sei_is_encoder_uuid(const uint8_t uuid[16]); + #endif /* AVCODEC_SEI_H */