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 34CDB42301 for ; Fri, 3 Jun 2022 18:45:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A26E068B7FD; Fri, 3 Jun 2022 21:45:27 +0300 (EEST) Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CF8F668B342 for ; Fri, 3 Jun 2022 21:45:21 +0300 (EEST) Received: by mail-qt1-f175.google.com with SMTP id x7so6305001qta.6 for ; Fri, 03 Jun 2022 11:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=AWFyqRyBU41zZtLFmlq93y87+Z6LWuBjYbNeINSff/E=; b=DQl7icaW0IB46d2Wu7fkuQIic7eJlVBSYgeZMaPnesBFLnNmWJgqStnpgM8xU8sWD3 zkot02AAz0G5ykBbWRr0T/eEstS68sDCBU7iMDxZOLpw/mk9ouoUoe/PD57VK4hI0yO6 t6EDjunlr1VtKoOvcR2ddyGA592lMNMRbfXCQ4RsFFSSXVR6fHe4a8/QgOXFeGUp7eKR URfaMiKBWTLQnPqkhmFb9sF6J8Lw8pfgrOfA2fotj4B4JmtVXseAjEnnlTtpvk2P0qOe 2A7k4vj7Y4A9HP6F4edHlTTgpwsvhfsfpuwDVTDhzMoXxr6u3tjVdLTxePt/2hvShq1U uKFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=AWFyqRyBU41zZtLFmlq93y87+Z6LWuBjYbNeINSff/E=; b=m7nQ/kMGpkzHKEqykZLcuMh9RzBIxBDAhUkBT4dg6E+Hgww6PYjJPg6sdMB6qM2PuT PVWa4dCElwGjkxDL0ECHKYmCf1sU6rEZTqScnZRSMELVRlKV+qzrlpIk+NhsywLCuUTl rvfVvnoc+VPCr6saLgcDjWrpIiVudp7TPxN11FAqDfrOLR/6IsCK5Q3OfbnpchZZHYQ/ ZqaQc0uEFrP2cXBUCzktVmmjmXQss0ZyP9+VRGzEqe5zSA5U0ZP9KxZVQbhE0dhhayfr QpvRyJo5n6pSL4F3//Pf5c06lewb5u8/54iuB5vwrpRhsDpdUZ2HTfvEDIovvxli51m9 IKQQ== X-Gm-Message-State: AOAM532W/NwxenODHro/D9nOb7D4JVlh2amrv8VTGa0mYxLA7YzFlc+O 8WnlHObJsJQgAxYQG2iysloAaAgZCgu4ZZctTWO/gpjDfoU= X-Google-Smtp-Source: ABdhPJwqzOAHI4t1M092MZDYwtdNTVH9/5SlLU1pLu+yyjlb0MSDE6oMayLIRFFGX4ithmobwitziH+aubWJ5FLhEvI= X-Received: by 2002:a05:622a:14c:b0:2fc:5024:c8bc with SMTP id v12-20020a05622a014c00b002fc5024c8bcmr8734632qtw.426.1654281920282; Fri, 03 Jun 2022 11:45:20 -0700 (PDT) MIME-Version: 1.0 References: <20220603131156.1772629-1-mvanb1@gmail.com> In-Reply-To: From: =?UTF-8?B?SmFuIEVrc3Ryw7Zt?= Date: Fri, 3 Jun 2022 21:45:08 +0300 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avformat/cafdec: Implement FLAC-in-CAF parsing 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, Jun 3, 2022 at 8:11 PM Andreas Rheinhardt wrote: > > Martijn van Beurden: > > The afconvert utility shipped with MacOS supports muxing of FLAC > > in CAF, see afconvert help output on a recent Mac here: > > https://hydrogenaud.io/index.php?topic=122509.0 A file created > > with afconvert free of copyright (licensed CC0) can be found here: > > http://www.audiograaf.nl/misc_stuff/afconvert-FLAC-in-CAF.caf > > > > This patch implements parsing of such a file > > --- > > libavformat/caf.c | 1 + > > libavformat/cafdec.c | 41 +++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 42 insertions(+) > > > > diff --git a/libavformat/caf.c b/libavformat/caf.c > > index a700e4055b..a61c39fae5 100644 > > --- a/libavformat/caf.c > > +++ b/libavformat/caf.c > > @@ -46,6 +46,7 @@ const AVCodecTag ff_codec_caf_tags[] = { > > { AV_CODEC_ID_GSM, MKTAG('a','g','s','m') }, > > { AV_CODEC_ID_GSM_MS, MKTAG('m','s', 0, '1') }, > > { AV_CODEC_ID_ILBC, MKTAG('i','l','b','c') }, > > + { AV_CODEC_ID_FLAC, MKTAG('f','l','a','c') }, > > { AV_CODEC_ID_MACE3, MKTAG('M','A','C','3') }, > > { AV_CODEC_ID_MACE6, MKTAG('M','A','C','6') }, > > { AV_CODEC_ID_MP1, MKTAG('.','m','p','1') }, > > diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c > > index 168f69f20b..72a74ab297 100644 > > --- a/libavformat/cafdec.c > > +++ b/libavformat/cafdec.c > > @@ -31,6 +31,7 @@ > > #include "demux.h" > > #include "internal.h" > > #include "isom.h" > > +#include "libavcodec/flac.h" > > #include "mov_chan.h" > > #include "libavutil/intreadwrite.h" > > #include "libavutil/intfloat.h" > > @@ -170,6 +171,46 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) > > } > > avio_skip(pb, size - ALAC_NEW_KUKI); > > } > > + } else if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) { > > + int last, type, flac_metadata_size; > > + uint8_t buf[4]; > > + /* The magic cookie format for FLAC consists mostly of an mp4 dfLa atom. */ > > + if (size < (16 + FLAC_STREAMINFO_SIZE)) { > > + av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n"); > > + return AVERROR_INVALIDDATA; > > + } > > + /* Check cookie version. */ > > + if (avio_r8(pb) != 0) { > > + av_log(s, AV_LOG_ERROR, "unknown FLAC magic cookie\n"); > > + return AVERROR_INVALIDDATA; > > + } > > + avio_rb24(pb); /* Flags */ > > + /* read dfLa fourcc */ > > + if (avio_read(pb, buf, 4) != 4) { > > + av_log(s, AV_LOG_ERROR, "failed to read FLAC magic cookie\n"); > > + return AVERROR_INVALIDDATA; > > + } > > + if (memcmp(buf,"dfLa",4)) { > > + av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n"); > > + return AVERROR_INVALIDDATA; > > + } > > + /* Check dfLa version. */ > > + if (avio_r8(pb) != 0) { > > + av_log(s, AV_LOG_ERROR, "unknown dfLa version\n"); > > + return AVERROR_INVALIDDATA; > > + } > > + avio_rb24(pb); /* Flags */ > > + avio_read(pb, buf, sizeof(buf)); > > You are not checking this; this could lead to uninitialized values being > used in flac_parse_block_header() below. > > > + flac_parse_block_header(buf, &last, &type, &flac_metadata_size); > > + if (type != FLAC_METADATA_TYPE_STREAMINFO || flac_metadata_size != FLAC_STREAMINFO_SIZE) { > > + av_log(s, AV_LOG_ERROR, "STREAMINFO must be first FLACMetadataBlock\n"); > > + return AVERROR_INVALIDDATA; > > + } > > + ret = ff_get_extradata(s, st->codecpar, pb, FLAC_STREAMINFO_SIZE); > > + if (ret < 0) > > + return ret; > > + if (!last) > > + av_log(s, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) ignored\n"); > > } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { > > // The data layout for Opus is currently unknown, so we do not export > > // extradata at all. Multichannel streams are not supported. > > Is there an official spec for this? CAF mostly follows ISOBMFF in these things, so https://github.com/xiph/flac/blob/master/doc/isoflac.txt is probably the source of truth for dfLa FLACSpecificBox and such. Base CAF specification is at https://developer.apple.com/library/archive/documentation/MusicAudio/Reference/CAFSpec/CAF_spec/CAF_spec.html , but it stops at AAC, and ignores both Opus and FLAC. Jan _______________________________________________ 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".