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 8C8C0447A9 for ; Fri, 23 Sep 2022 21:20:15 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9313F68BC54; Sat, 24 Sep 2022 00:20:14 +0300 (EEST) Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 11A0268BC08 for ; Sat, 24 Sep 2022 00:20:08 +0300 (EEST) Received: by mail-oi1-f181.google.com with SMTP id m130so1341561oif.6 for ; Fri, 23 Sep 2022 14:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=JsYNsqkzpQWuVHf4ZMY67qFCEbmMGgtg1y1Ti/AY8yg=; b=LjBMZaoNElcjO7Jx4JAxmYhxIoOESGPTJQEwIYBFqExWVn+IU7Cw8l+ViYb2OzhhYg WV2v95insh7SEzPyIxxcq1svIiGyEpeLSA+8H6osxz3mktOndGabfT3hLc3V+O/8ljmp kjaUd5SWsK48X/ln5yKrph74xWxXh8eAnUWuW9jFkPVZrWHPFBxlVGlPrQHaHlfWp+ZC TRQn26LfP42UhJ7IQkFXpwFO8sLnkBtA7xubudzlybxjMEZRGkySpbjCTlnDs3lZC4Lj +Ytu8fKvO8OmHv+bxuQ/qSusF9Q4cXOofLhxd6A0Al3jg6iijesSXiFLC2cUOD3ga6vr YxOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=JsYNsqkzpQWuVHf4ZMY67qFCEbmMGgtg1y1Ti/AY8yg=; b=ygF8bX3swQjXgDMys3CIPO30+QCpwZvSOPKi1rCd+MNneXXvdzAuubAc5iw+MnEd+b 0N8r8zNxHxt/dDmZpt8scJ4GXU1Y2azGnBIA4tCOnGlz9X6Grt29SGbuRGXuFuDLa2Mq 1NtsTQavmErmfyWGXvaTRdA+gtfnoB3JUkLl+2B6D3CWpEY/jzIxR9NJyDfwf8tsvRQ4 TXzaigkVONYF9f3aOGcFlPaAu6qSopk1fCvAEu8ECP+yaHD8EPyJN2DRcK7BOtmQsE1a R6n+/NwfdCy0Yx60vyRuxXTrZEaTkAnkgUVvD49TP+CAqyIu7m+aLlGjqK/w+StUmDQ5 B2vQ== X-Gm-Message-State: ACrzQf2ALfOUilus1SAbZJyc+y3z4vYsxkdnedFUh2+QLAP1+7nIiYeE f5B9hZ+3mh9ffffwlcVkx7Op3UjcZR4= X-Google-Smtp-Source: AMsMyM59Yyiad3ahg9A5vzZuCqPRHCvIDrHJG+qu58gQg2DyjK46Ce9B9qyWpSzOOu25z83UfcWqrA== X-Received: by 2002:a05:6808:e8e:b0:34d:7829:135 with SMTP id k14-20020a0568080e8e00b0034d78290135mr5166069oil.252.1663968005815; Fri, 23 Sep 2022 14:20:05 -0700 (PDT) Received: from [192.168.0.13] ([191.97.187.183]) by smtp.gmail.com with ESMTPSA id m5-20020a056870888500b00127d2005ea1sm5355524oam.18.2022.09.23.14.20.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Sep 2022 14:20:05 -0700 (PDT) Message-ID: <2e395cf4-b4fa-b7a5-0673-71bf2838d9d9@gmail.com> Date: Fri, 23 Sep 2022 18:20:04 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Content-Language: en-US From: James Almer To: ffmpeg-devel@ffmpeg.org References: <20220921122159.1238-1-jamrial@gmail.com> <20220922231445.6525-1-jamrial@gmail.com> In-Reply-To: <20220922231445.6525-1-jamrial@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH v2] avformat/cafenc: derive Opus frame size from the relevant stream parameters 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 9/22/2022 8:14 PM, James Almer wrote: > Use the stream duration as last resort, as an off-by-one result of the > "st->duration / (caf->packets - 1)" calculation can break playback on some > devices. > Also, don't write the sample_rate value propagated by encoders like libopus. > The sample rate of the audio fed to it is irrelevant for the container after > being encoded. > > Fixes ticket #9930. > > Signed-off-by: James Almer > --- > libavformat/cafenc.c | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c > index fedb430b17..b90811d46f 100644 > --- a/libavformat/cafenc.c > +++ b/libavformat/cafenc.c > @@ -53,7 +53,11 @@ static uint32_t codec_flags(enum AVCodecID codec_id) { > } > } > > -static uint32_t samples_per_packet(enum AVCodecID codec_id, int channels, int block_align) { > +static uint32_t samples_per_packet(const AVCodecParameters *par) { > + enum AVCodecID codec_id = par->codec_id; > + int channels = par->ch_layout.nb_channels, block_align = par->block_align; > + int frame_size = par->frame_size, sample_rate = par->sample_rate; > + > switch (codec_id) { > case AV_CODEC_ID_PCM_S8: > case AV_CODEC_ID_PCM_S16LE: > @@ -83,6 +87,8 @@ static uint32_t samples_per_packet(enum AVCodecID codec_id, int channels, int bl > return 320; > case AV_CODEC_ID_MP1: > return 384; > + case AV_CODEC_ID_OPUS: > + return frame_size * 48000 / sample_rate; > case AV_CODEC_ID_MP2: > case AV_CODEC_ID_MP3: > return 1152; > @@ -110,7 +116,7 @@ static int caf_write_header(AVFormatContext *s) > AVDictionaryEntry *t = NULL; > unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, par->codec_id); > int64_t chunk_size = 0; > - int frame_size = par->frame_size; > + int frame_size = par->frame_size, sample_rate = par->sample_rate; > > if (s->nb_streams != 1) { > av_log(s, AV_LOG_ERROR, "CAF files have exactly one stream\n"); > @@ -139,7 +145,10 @@ static int caf_write_header(AVFormatContext *s) > } > > if (par->codec_id != AV_CODEC_ID_MP3 || frame_size != 576) > - frame_size = samples_per_packet(par->codec_id, par->ch_layout.nb_channels, par->block_align); > + frame_size = samples_per_packet(par); > + > + if (par->codec_id == AV_CODEC_ID_OPUS) > + sample_rate = 48000; > > ffio_wfourcc(pb, "caff"); //< mFileType > avio_wb16(pb, 1); //< mFileVersion > @@ -147,7 +156,7 @@ static int caf_write_header(AVFormatContext *s) > > ffio_wfourcc(pb, "desc"); //< Audio Description chunk > avio_wb64(pb, 32); //< mChunkSize > - avio_wb64(pb, av_double2int(par->sample_rate)); //< mSampleRate > + avio_wb64(pb, av_double2int(sample_rate)); //< mSampleRate > avio_wl32(pb, codec_tag); //< mFormatID > avio_wb32(pb, codec_flags(par->codec_id)); //< mFormatFlags > avio_wb32(pb, par->block_align); //< mBytesPerPacket > @@ -248,7 +257,7 @@ static int caf_write_trailer(AVFormatContext *s) > avio_seek(pb, caf->data, SEEK_SET); > avio_wb64(pb, file_size - caf->data - 8); > if (!par->block_align) { > - int packet_size = samples_per_packet(par->codec_id, par->ch_layout.nb_channels, par->block_align); > + int packet_size = samples_per_packet(par); > if (!packet_size) { > packet_size = st->duration / (caf->packets - 1); > avio_seek(pb, FRAME_SIZE_OFFSET, SEEK_SET); Will apply. _______________________________________________ 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".