From patchwork Thu Sep 1 21:23:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37604 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp545336pzh; Thu, 1 Sep 2022 14:24:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR5WmllXayAhPkEn6wcz4gzg76Fozsq5DGYuUo6dUVL92q2Q7A69Z9BAxyEEq1Sw8XnjFrwR X-Received: by 2002:a05:6402:1e8d:b0:441:58db:b6a2 with SMTP id f13-20020a0564021e8d00b0044158dbb6a2mr29711289edf.277.1662067483537; Thu, 01 Sep 2022 14:24:43 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o21-20020a170906975500b0073d6e0416f9si288857ejy.671.2022.09.01.14.24.43; Thu, 01 Sep 2022 14:24:43 -0700 (PDT) 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=BqmM59so; 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 8DF1268B9DC; Fri, 2 Sep 2022 00:24:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2098.outbound.protection.outlook.com [40.92.89.98]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3D00A68B83C for ; Fri, 2 Sep 2022 00:24:28 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HGQudbIwgnevxBLwiQVUhNL3Yx20HVPdAOG+LiNwcuhzTEnHs2DE7HNJahZEabTLKjtBvIEPqjufHaP677Y0TPZ2wKXdVtUr1fvLXrWADmhsNcWZe1kTBhwUgUZMoEdPHh5bVgNMYbzI+hkPiYmDyxxhCp2r2g6IdADtsZpGk+JaSMswhuu3/yjMePqLvwkvdNwrXGsqn26ukRkjfvlbhI/Wxu3x4wCtovnSZIqUqTNDi9AScWU/i4EbexdGnJWiWzcxAojH0Gbj8IsawmqlCnomyr9nw+9cSqxo39RECVC6dPQhzBf+GFhfqJp9GnmVRGM7BzE5rMu4h05kXwiz3w== 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=WU0lgdWozunmDHwV9uQd5xu9EfBemSB4FIC0HPKKNgY=; b=CrkTZvpxhiZWvG+Pgg2nUCXm28QF0zcVMxabpDVjWFRqk90Fp89LLNh7ocUFjjckDqGLziuZ3Zld2/ChnR9p0SRhYteuYlCRyyUmQNbFn1OmJa5RSdFVxJVl4jrd8RiGltYZG5gUCaU1DyGuPCXlwLGB7Bwrgh54vLBIP91IkRdpmL8oK5W/2cZ2PSxxKQa7pVRT1ouNQW4IrM64tJ9Fl7vIZZ5jebUP+E1SHerOJQMWcNlKTMMQSLBWdhAiTMUi48z8GMXaj5brzuCC8S3ceO78ER8Xl++MjPoBlnM2376pau5LS9Ak8mx/ux0l8HhET5f7Jv2C/lbdOlDIeFSFXw== 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=WU0lgdWozunmDHwV9uQd5xu9EfBemSB4FIC0HPKKNgY=; b=BqmM59soOLiZqUiMlvtqcfm94su578GVbEtODU/jnQBMfsDzQd3agRVhmigjKDJd+Iy7CS7vWuwlPVfyO/zb4aZPNkeg2pwTDnZGv8wF8r3iLXfuclRae59b0IMnRPDJFqaTxd8aYYav9XOy0pnqbrNYfatUYNDiAL9ijyc2+YNfTXU59G7wiqzHdDkL5TdlyJXMRFuU77WXYiccoPLATYYjqZN7+sHb/WcAulN6OhIaMQUNrLPtsK4u3flWWGy9CA7W7VVDrBe1CqMegvxllxuBo6eWPXS6BL6PyZr/Yls7PONjunjjo82S8GQTbl+y2PZcdqPiIXmRBAiP9JQ5GQ== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PAXP250MB0424.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:287::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.12; Thu, 1 Sep 2022 21:24:23 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::90cc:8832:55f1:c7d6]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::90cc:8832:55f1:c7d6%7]) with mapi id 15.20.5588.010; Thu, 1 Sep 2022 21:24:23 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Sep 2022 23:23:59 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [PXHJ687aUCivrgFoNoiUaSoXnl6nYKpE] X-ClientProxiedBy: ZR0P278CA0185.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:44::18) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220901212403.2622789-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd315191-5a47-4d51-938e-08da8c605721 X-MS-Exchange-SLBlob-MailProps: ZILSnhm0P3nBJnOPH7CaP06/PjPoSCFAf0glQwCTtofE5CDU0+fNaScj5p5aA9cB/gw007cIqNOnDdCs+AFoO7bD8BYhsASoAmIUu3kQkjA+KlXoqGHqBBuGZQKx04MOohcAt6p01+zplrXi+ZmEfelKFRlMxO2Sw6ZTH0lqx98RfLS7SUQ777zN8tRbar4qE3VHdRPNlcXmvOFJ0O4DFL4FRnE4h6xMf4mvxRR3kWZtpZ4X17NSrZZen/Ee2KlNfvDE7fQRj+P/Iuhov2vadoVnxSCcdD6PYWlnlHquhGDcpk231p1J6fvXhPKff65MBeQBpsTsQkbfn+yZdWGw7/dRDH6XdTnMcGVpfUgSgosX2Xr92fOTyH8ovxutalyltKPGyTqs1biyVIUaahbniGebehjHzMRMG79p+Sx0gVv4KQY2ktfmm3JaZW13yA4fD4HnRtcfrPqxWLkwd55sZfbI4dpBlT7CplvAUPPycSF1aTRmM/GGdHPWMYUjOt7KmpnH8jHkj+WZLsYhVttbzqWyLxKg/dv10qi5ZF92ypGk07lNZTPcX+7skX5VjLAA42vtbztCMvnn9ZTNOcPhGsq4XDMjgJazB3a5++/X4M8Dj1iE0zcFuLUzpNAgX+N2MLcNngVfEW53b3FoC9nlh0HFEKZ7tCRnTziFAXLkmPLB95wed8WwFv8bLrjqB/QIoF32uf70iXzSgUVIDiXfzRXXG8YFuNhUGddpO2/dq4xg/fKCYXGK3Nfq3e8itdfOcZNuaVrvCl4ccmkW/RBGnt0Rb2w72Joj X-MS-TrafficTypeDiagnostic: PAXP250MB0424:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-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ccbjjlMvymtH8Qin/61OVDuiDNC07sik9o1aFz4dopoC9UvpM9mzEz06mhvfIXbMqqccUMPWEMqqMtlLPuqCH76a4Z2AR4cZVCojT2RLML9M/7FL35dshoYgffxC9YuZuLN7s8f3fw5f2V4LJk/ajGJNnVve/EZUSJhDnFVFAChMJLIpC9UG6DjK0Bb2lR1tpom+9ulFe0MCCY9N2v1GAy2jF+qMJIlfkP1fMtCjmnX4wwi7wGatCUWpeTSu3XLnzmU20MNSpq7QhA2ItExA0UH5d+OEWbILfIU5Wl62k/nZcRRt7ujl1iFfNkH5xC++ilHy1EWJg6s4JOft+koCWbqxcKM21y2ELgNKhZCaBKIm0D2TRIjDPzzhrWyYFsQYrTVcNUzejJP4hBW+1+XQkYirOi09VBn129RdSvU+AGqX+qdfiezf2wp9ELYhr3OPz0gbAfxsk9aGYwi7zQLBx0kFo3lRtclWqGIe7VAu477qLdFd856uJ8s8e0/ItKGAKNLqFGXwbs5a3Rb7NI9Y9DUB88mKEqQTydbBp4iYbF6fmC/DWdlEkN/POuMB/7gYrBKwTCesrzK/k7/GY8AOMtzfpQgjJOMtFpdlMgAqV/tJMoi9USeohroFONf4EptGsazOfvGF1FByhC7XcXazzp3ntXSRv0O2BqRXHwqaIhlMyODBtQfO3APBRXxHS5XxfNDyPSwZhShsCTyFxMhJ6VVZf4lHeYewfUpqJ5rV36mKuZXRVwGDbz18wnmMti0LmvLOkGGOQ8dYw9FMKAkfw1g2PR2MB8/KBFnBLEEchQRTP3Gv3nnEc0vRh9Uh1FjgnMZxxkkbUQxlXICdrU0dE+NGRsqt/BJvYxRgf1g56YVMegwtq9JEknGp/AU6XlSUXoopHVET9lPeDf59B0pKX/ZxrG49fw5/WA/7+udOJuBgMImtIB2J2O0tu1m2nUh5b+mj1Y= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd315191-5a47-4d51-938e-08da8c605721 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2022 21:24:23.4944 (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: PAXP250MB0424 Subject: [FFmpeg-devel] [PATCH 4/8] avformat/matroskaenc: Don't override samplerate for CodecDelay 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: XJZb+tc65VEI Opus can be decoded to multiple samplerates (namely 48kHz, 24KHz, 16Khz, 12 KHz and 8Khz); libopus as well as our encoder wrapper support these sample rates. The OpusHead contains a field for this original samplerate. Yet the pre-skip (and the granule-position in the Ogg-Opus mapping in general) are always in the 48KHz clock, irrespective of the original sample rate. Before commit c3c22bee6362737cf290929b7f31df9fb88da983, our libopus encoder was buggy: It did not account for the fact that the pre-skip field is always according to a 48kHz clock and wrote a too small value in case one uses the encoder with a sample rate other than 48kHz; this discrepancy between CodecDelay and OpusHead led to Firefox rejecting such streams. In order to account for that, said commit made the muxer always use 48kHz instead of the actual sample rate to convert the initial_padding (in samples in the stream's sample rate) to ns. This meant that both fields are now off by the same factor, so Firefox was happy. Then commit f4bdeddc3cab807e43e0450744dfe9a45661e1d7 fixed the issue in libopusenc; so the OpusHead is correct, but the CodecDelay is still off*. This commit fixes this by effectively reverting c3c22bee6362737cf290929b7f31df9fb88da983. *: Firefox seems to no longer abort when CodecDelay and OpusHead are off. Signed-off-by: Andreas Rheinhardt --- Non-48kHz Opus is also weird in the demuxer: avformat_find_stream_info() sets the samplerate to 48kHz. Therefore 49b0246635 calculated initial_padding based upon 48kHz for Opus, regardless of the actual sample rate indicated in the TrackEntry. This is wrong if avformat_find_stream_info() is not used. I think a better (but still hacky) solution would be to just report the sample rate as 48kHz for Opus regardless of what the header says. (Trying to pass initial padding through the decoder is problematic: The corresponding field of AVCodecContext is unused for decoding, instead there is a delay field which is always set by libavcodec whose semantics are unclear (there are two inconsistent definitions: "Number of frames delay in addition to what a standard decoder as specified in the spec would produce." and "the number of samples the decoder needs to output before the decoder's output is valid". The Opus decoders and parser are the only components that set delay at all (based upon OpusHead). When converting AVCodecParameters->AVCodecContext, initial_padding is mapped to both delay and initial_padding; in the other direction, initial_padding is taken from initial_padding (which is encoder-only). If one wants to pass this value through the decoder, then the best way to do so is probably to use initial_padding for decoding, too, and let the user set it and let lavc update it if the decoder encounters information about this in the bitstream/extradata. This includes that lavc updates initial_padding if it changes the sample rate (as it does for Opus). This would also fix delay (the second definition would be deprecated).) libavformat/matroskaenc.c | 2 +- libavformat/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index de6c993e6a..c525edb39f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1830,7 +1830,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, case AVMEDIA_TYPE_AUDIO: if (par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) { int64_t codecdelay = av_rescale_q(par->initial_padding, - (AVRational){ 1, 48000 }, + (AVRational){ 1, par->sample_rate }, (AVRational){ 1, 1000000000 }); if (codecdelay < 0) { av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n"); diff --git a/libavformat/version.h b/libavformat/version.h index 7b414039ad..a54ffd6c0e 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" #define LIBAVFORMAT_VERSION_MINOR 30 -#define LIBAVFORMAT_VERSION_MICRO 100 +#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \