From patchwork Sat Dec 18 23:07:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32718 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2958833iog; Sat, 18 Dec 2021 15:08:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5axspq2O5eoVcJ3sTTSo0175SQ6Jg6q6uYUeMdRvh5LmwJjZ8oKnaa6wVVCO2/iKbsm/1 X-Received: by 2002:aa7:d64e:: with SMTP id v14mr9195699edr.194.1639868921772; Sat, 18 Dec 2021 15:08:41 -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 nc39si4982979ejc.119.2021.12.18.15.08.41; Sat, 18 Dec 2021 15:08:41 -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=s06VtFlR; 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 25FA168AF8B; Sun, 19 Dec 2021 01:08:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2010.outbound.protection.outlook.com [40.92.89.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C5E3F68A588 for ; Sun, 19 Dec 2021 01:08:12 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AfKotmjO7ndk7qcx2Oc1JgR4Czb7xnv5jOmuzV1wYI7GEo6t/JTHce5MuRZGJ1vv3Fp/mh+6gxVxyKcbn5dlOB3tg1PwNsBLyZEeSqiFt0ftF+P39dRutPMXJWMt1W3gAsmV8B9RYf9yrz02UDICndWTRlz6XITObk0dQ6kDFtZYzJ90a7W77U3Epeit0w7eRnUnlZjKxoz2pgD1CnfudrU4xxbsl3NemgR3Cnt/yAHpmeer3wpx4VldYbzTrcynVcn6syu5Vf8QpU9ibyhpCRJKJZecuTse4IcxwVZTIAR2NFl/4iwRwJ1bOm4n7DZ+XYxKhDyke5Ms71PcB+cyZA== 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=xaa89tJ/iI38a3pZdaessgW5++Hj1+hCMDX1egysPrA=; b=cMtohV0/WwnDtJQGik9oPqjLvJ7+eSr1nrkR0u/IVuuifhPuxEf1HG/5S8RQGGpsDyPF/nAbK1v+tSl/KtJTy7dLo1SFolxnbH11YrgbBqquHzpSWf3wusfXVExs3ULlUvVn3shqL9j0BBgypiT2eilIuM/7DAUNqH8klhbDeMkNjgax+TEELFWUDtasBsStjxQNdGEv2CfeSlZR3WsyxW8S8thdgVzHA5wQz6qs9uLCGqbxoZ1uqdvk21zwoXxEbVYjFaIv3KnVkKtIdn8c2PsgS/VjCMRLat119HRE1pNbBNhh2gkDzhHEatUW3Zfx5io5sMe0daVIoUet9zTsrw== 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=xaa89tJ/iI38a3pZdaessgW5++Hj1+hCMDX1egysPrA=; b=s06VtFlRl/x/9/d2NSPjkUEAHEkH0GvD0CucHOfOK4cSOZKm2MjeSIiCCPR0l4jCOMZSjs+WCnFwpuPoNTT1CIQPL774OwMACscZFt0SyqiicPpeqqM7ybMbyrhvjWspTMS3u2fb1FDeNNtqKUomdfvLgU/rDr9fFgo+BYOubOTE1IN3ZsUlzuISHpDhzR/XUeka6qXeDL0XYrE07doyMgDaSDnZyVphZ2rrct5RY7l03IaHFE3MphfgA1sQPFIUstZIr6qD+natHgKA63/ad65O1LDR+ZFGyDPjAZ74+KdrDckXYBJqmyxA2BTxNvyBl/ODLjZbc+fXAnpUXEm5Og== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3862.eurprd03.prod.outlook.com (2603:10a6:20b:17::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.19; Sat, 18 Dec 2021 23:08:01 +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; Sat, 18 Dec 2021 23:08:01 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 00:07:45 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [WnkGDNmqlcDQTwT803sU3halMyWqTUuI] X-ClientProxiedBy: AM0PR03CA0076.eurprd03.prod.outlook.com (2603:10a6:208:69::17) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211218230745.1227624-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c7dde0bd-4569-490c-0793-08d9c27b3cbc X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiR3EehW4kxQzdNcP2D/mG1JfHfJXIedYdZAqjnhifPwQxeDvABg1zAiEpxg0LzonpkzJh2TpoH0m4RWWDZXHxsQEzMjf6QL/W6IcHw3xNA4uPlcdRZW87h49soI1FJkiyldJSnKO6aa7XusqoV7N6gY9y+U+H7tdWv3KUyReqo43Gli6kyIDK9bSv9+COM47Zw0HBdEM3Ep9DRZsLQHQ7dMkF3DYHT1JPvvd6Jx+5YHAu9ktkMt4Lc3QsHOG3Y6On63U9fwKmwOPzvhAAA3tE48S7KFXGB9Umt+jL3qNE/b7VBWC3XzP0skjZbNqqUrXBMdiLaiY06vz8AGZZC7POXQMETbAh81tgmwX8SoBWWsdxHobOOChyAlPQnhdCLP7R0K2HUpuGM9orAfba5v4cNL7FmzDsP1YLZi6eJTroL4lqQxd8w/XpZUBK39QZqVrqY/8+t5VNocnqUmRlWeuyxrcvUUsDso3sr1ZGRWnOjDiSnA1iag8Lj1Gm/9XgDVCFqhAPzT/Uuhlo8wKsrUVwkMWxndgE2MNAAmrVcH+lJxm3+CPO51QEAI27ru6gJN5M1Y7LhUMf3Poy7eMwYdTHJWAZFsoR4XexZG2y/2iEsDbvgYHr6PGA60NRKHPfijlnt6C8NwS5qcK9ewvWjMH408qU+BqGbbv7OZy/6aU2dvdOdSTYevkmbNklpuKdvHBuJsRsLbKyHMtK7JpuhjhnzB2ewH86kVz9/A+m4xJ/8QrrliRYT0BR5oSSFPPi0ghlY= X-MS-TrafficTypeDiagnostic: AM6PR03MB3862:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I+uG8i6jlRFGPWb3/m6I1pXjwY9EUZf8zbpuH4aySG0ZFx/hV/s6X0tNVEkaDT3qz75rLBD4zLP+UJDFLQhmNVKEm47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rzYDi6/YiFa8uO1gd7rznfzoqqQlJ3/JMJ5bttZCER8Hnm/FAOGXrG/CgxVH6DphaNBTHHLWc4+4kV8FXiK6KrcOVj4tXmxTWPwrS6Lishiovnvo2Dr3o2MtRWuM7SwsWPu3yFJxzQWgPlKZJNmjGRacf8Bt3h5G7GZ3VZwxiR3aHm1vLVsfAd6FmVBMu2B2nQuTQvcto+VuUKq7ZhW1c+nNZwdV+4cadvwQGtnECa9PZcMH7wLoLY4t65xs+GWSwca6Y+gQIPx2RnvxZpr2dG3ol7s2QjeHcoFxkdVS5bb3O82epXXrcF0MR03vmtjwsRixdK3mlYv6n7SIDu8yET3G6uk3WxJot/wVqnjw65xE0MdX3hWAZfAoYlkwFwU/tTNglR2/GUiS6fFBojyFs9BzpqwMv8/vlMRle8K6QNhwOlCMF3DuFSAHRXaIGjo/+/liBw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7dde0bd-4569-490c-0793-08d9c27b3cbc X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2021 23:08:01.0513 (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: AM6PR03MB3862 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/h2645: Fix SEI->display matrix transformation 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: xZdRTZJhGJ3m The earlier code did not account for the fact that av_display_rotation_set() wants the angle in the anticlockwise direction (despite what its documentation stated for a long time); furthermore, the H.2645 spec wants the flips applied first, whereas our code did it the other way around. This can be fixed by negating the angle once for every flip. Signed-off-by: Andreas Rheinhardt --- Maybe the common H.264 and H.265 code could be shared one day? libavcodec/h264_metadata_bsf.c | 15 ++++++++++++--- libavcodec/h264_slice.c | 9 +++++++++ libavcodec/hevcdec.c | 10 ++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index 452a8ec5dc..8c5d19c5a8 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -341,15 +341,24 @@ static int h264_metadata_handle_display_orientation(AVBSFContext *bsf, SEI_TYPE_DISPLAY_ORIENTATION, &message) == 0) { H264RawSEIDisplayOrientation *disp = message->payload; + double angle = disp->anticlockwise_rotation * 180.0 / 65536.0; int32_t *matrix; matrix = av_malloc(9 * sizeof(int32_t)); if (!matrix) return AVERROR(ENOMEM); - av_display_rotation_set(matrix, - disp->anticlockwise_rotation * - 180.0 / 65536.0); + /* av_display_rotation_set() expects the angle in the clockwise + * direction, hence the first minus. + * The below code applies the flips after the rotation, yet + * the H.2645 specs require flipping to be applied first. + * Because of R O(phi) = O(-phi) R (where R is flipping around + * an arbitatry axis and O(phi) is the proper rotation by phi) + * we can create display matrices as desired by negating + * the degree once for every flip applied. */ + angle = -angle * (1 - 2 * !!disp->hor_flip) * (1 - 2 * !!disp->ver_flip); + + av_display_rotation_set(matrix, angle); av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip); // If there are multiple display orientation messages in an diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 4467882775..c21004df97 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1305,6 +1305,15 @@ static int h264_export_frame_props(H264Context *h) AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9); if (rotation) { + /* av_display_rotation_set() expects the angle in the clockwise + * direction, hence the first minus. + * The below code applies the flips after the rotation, yet + * the H.2645 specs require flipping to be applied first. + * Because of R O(phi) = O(-phi) R (where R is flipping around + * an arbitatry axis and O(phi) is the proper rotation by phi) + * we can create display matrices as desired by negating + * the degree once for every flip applied. */ + angle = -angle * (1 - 2 * !!o->hflip) * (1 - 2 * !!o->vflip); av_display_rotation_set((int32_t *)rotation->data, angle); av_display_matrix_flip((int32_t *)rotation->data, o->hflip, o->vflip); diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 46d9edf8eb..3aa70e2245 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2769,6 +2769,16 @@ static int set_side_data(HEVCContext *s) if (!rotation) return AVERROR(ENOMEM); + /* av_display_rotation_set() expects the angle in the clockwise + * direction, hence the first minus. + * The below code applies the flips after the rotation, yet + * the H.2645 specs require flipping to be applied first. + * Because of R O(phi) = O(-phi) R (where R is flipping around + * an arbitatry axis and O(phi) is the proper rotation by phi) + * we can create display matrices as desired by negating + * the degree once for every flip applied. */ + angle = -angle * (1 - 2 * !!s->sei.display_orientation.hflip) + * (1 - 2 * !!s->sei.display_orientation.vflip); av_display_rotation_set((int32_t *)rotation->data, angle); av_display_matrix_flip((int32_t *)rotation->data, s->sei.display_orientation.hflip,