From patchwork Fri Nov 18 03:25:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Gregan X-Patchwork-Id: 1469 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp1143112vsb; Thu, 17 Nov 2016 19:25:24 -0800 (PST) X-Received: by 10.28.180.214 with SMTP id d205mr20584572wmf.131.1479439524491; Thu, 17 Nov 2016 19:25:24 -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 18si788187wmq.97.2016.11.17.19.25.24; Thu, 17 Nov 2016 19:25:24 -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=@flim.org; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DACC0689E04; Fri, 18 Nov 2016 05:25:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from flim.org (flim.org [65.99.223.158]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C976689890 for ; Fri, 18 Nov 2016 05:25:13 +0200 (EET) Received: from localhost (unknown [121.98.51.0]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by flim.org (Postfix) with ESMTPSA id D181614190 for ; Fri, 18 Nov 2016 03:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=flim.org; s=default; t=1479439512; bh=s1smam0eI89ebY+n/u2GBS84li7sbrnHP3bt99vecjA=; h=Date:From:To:Subject:References:In-Reply-To:From; b=lYjTbAB4IilChnU0LGUEMOIrKJvgHKLVE2FAirVhlEPbR/05OWhgTqbiSeni2jXOx EKaop7Z+3Cje2PgagRTK4n/dxWed5HxcWbuZ4Zpn+FSgMv9jinUSW9NPEBLgk3H8Pu HL4WSzHnUgk2P+R4izfghEDpeeeIXWfm6S3OysAE= Date: Fri, 18 Nov 2016 16:25:09 +1300 From: Matthew Gregan To: FFmpeg development discussions and patches Message-ID: <20161118032423.GH8366@brak.lan> Mail-Followup-To: FFmpeg development discussions and patches References: <82396c770b2569fa6b0398e311a58e5c6fa39fa3.1477894999.git.kinetik@flim.org> <26d88c9d-a385-f246-2f2a-6900ab7e0a89@gmail.com> <20161101011100.GA8366@brak.lan> <733a3021-6f78-2427-1ff7-8d78fd9abedf@gmail.com> <20161101232152.GD8366@brak.lan> <877d0678-0dbb-97c3-311a-3f24b32c2e79@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <877d0678-0dbb-97c3-311a-3f24b32c2e79@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [FFmpeg-devel] [PATCH 1/2] Add experimental muxing support for FLAC in ISO BMFF (MP4). X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" At 2016-11-17T22:57:49-0300, James Almer wrote: > > @@ -345,6 +346,7 @@ const AVCodecTag ff_codec_movaudio_tags[] = { > > + { AV_CODEC_ID_FLAC, MKTAG('f', 'L', 'a', 'C') }, /* nonstandard */ > > This is enables muxing into mov, which bypasses the experimental check below > since mov isn't MODE_MP4. Thanks. Updated the check to reject non-MP4 as invalid before checking the experimental flag. I based the original check on the VP9/MP4 muxing, which has the same bug, should I send a patch to restrict that to MP4 too? Updated patch attached. From 6309c0c60835a843a846915c7534a61786291ad3 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Thu, 20 Oct 2016 17:28:11 +1300 Subject: Add experimental muxing support for FLAC in ISO BMFF (MP4). Based on the draft spec at https://git.xiph.org/?p=flac.git;a=blob;f=doc/isoflac.txt '-strict -2' is required to create files in this format. diff --git a/libavformat/isom.c b/libavformat/isom.c index 1fa46bd..cd0b0b7 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -60,6 +60,7 @@ const AVCodecTag ff_mp4_obj_type[] = { { AV_CODEC_ID_EAC3 , 0xA6 }, { AV_CODEC_ID_DTS , 0xA9 }, /* mp4ra.org */ { AV_CODEC_ID_VP9 , 0xC0 }, /* nonstandard, update when there is a standard value */ + { AV_CODEC_ID_FLAC , 0xC1 }, /* nonstandard, update when there is a standard value */ { AV_CODEC_ID_TSCC2 , 0xD0 }, /* nonstandard, camtasia uses it */ { AV_CODEC_ID_VORBIS , 0xDD }, /* nonstandard, gpac uses it */ { AV_CODEC_ID_DVD_SUBTITLE, 0xE0 }, /* nonstandard, see unsupported-embedded-subs-2.mp4 */ @@ -345,6 +346,7 @@ const AVCodecTag ff_codec_movaudio_tags[] = { { AV_CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') }, { AV_CODEC_ID_EVRC, MKTAG('s', 'e', 'v', 'c') }, /* 3GPP2 */ { AV_CODEC_ID_SMV, MKTAG('s', 's', 'm', 'v') }, /* 3GPP2 */ + { AV_CODEC_ID_FLAC, MKTAG('f', 'L', 'a', 'C') }, /* nonstandard */ { AV_CODEC_ID_NONE, 0 }, }; diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 5452ff7..21b0050 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -33,6 +33,7 @@ #include "avc.h" #include "libavcodec/ac3_parser.h" #include "libavcodec/dnxhddata.h" +#include "libavcodec/flac.h" #include "libavcodec/get_bits.h" #include "libavcodec/put_bits.h" #include "libavcodec/vc1_common.h" @@ -655,6 +656,26 @@ static int mov_write_wfex_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra return update_size(pb, pos); } +static int mov_write_dfla_tag(AVIOContext *pb, MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + avio_wb32(pb, 0); + ffio_wfourcc(pb, "dfLa"); + avio_w8(pb, 0); /* version */ + avio_wb24(pb, 0); /* flags */ + + /* Expect the encoder to pass a METADATA_BLOCK_TYPE_STREAMINFO. */ + if (track->par->extradata_size != FLAC_STREAMINFO_SIZE) + return AVERROR_INVALIDDATA; + + /* TODO: Write other METADATA_BLOCK_TYPEs if the encoder makes them available. */ + avio_w8(pb, 1 << 7 | FLAC_METADATA_TYPE_STREAMINFO); /* LastMetadataBlockFlag << 7 | BlockType */ + avio_wb24(pb, track->par->extradata_size); /* Length */ + avio_write(pb, track->par->extradata, track->par->extradata_size); /* BlockData[Length] */ + + return update_size(pb, pos); +} + static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { uint32_t layout_tag, bitmap; @@ -964,8 +985,13 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex avio_wb16(pb, 16); avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ } else { /* reserved for mp4/3gp */ - avio_wb16(pb, 2); - avio_wb16(pb, 16); + if (track->par->codec_id == AV_CODEC_ID_FLAC) { + avio_wb16(pb, track->par->channels); + avio_wb16(pb, track->par->bits_per_raw_sample); + } else { + avio_wb16(pb, 2); + avio_wb16(pb, 16); + } avio_wb16(pb, 0); } @@ -1010,6 +1036,8 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex mov_write_extradata_tag(pb, track); else if (track->par->codec_id == AV_CODEC_ID_WMAPRO) mov_write_wfex_tag(s, pb, track); + else if (track->par->codec_id == AV_CODEC_ID_FLAC) + mov_write_dfla_tag(pb, track); else if (track->vos_len > 0) mov_write_glbl_tag(pb, track); @@ -1178,6 +1206,7 @@ static int mp4_get_codec_tag(AVFormatContext *s, MOVTrack *track) else if (track->par->codec_id == AV_CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c'); else if (track->par->codec_id == AV_CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g'); else if (track->par->codec_id == AV_CODEC_ID_VC1) tag = MKTAG('v','c','-','1'); + else if (track->par->codec_id == AV_CODEC_ID_FLAC) tag = MKTAG('f','L','a','C'); else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); else if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE) tag = MKTAG('m','p','4','s'); @@ -5043,7 +5072,8 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt) trk->start_cts = 0; } - if (trk->par->codec_id == AV_CODEC_ID_MP4ALS) { + if (trk->par->codec_id == AV_CODEC_ID_MP4ALS || + trk->par->codec_id == AV_CODEC_ID_FLAC) { int side_size = 0; uint8_t *side = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size); if (side && side_size > 0 && (side_size != par->extradata_size || memcmp(side, par->extradata, side_size))) { @@ -5757,6 +5787,19 @@ static int mov_init(AVFormatContext *s) i, track->par->sample_rate); } } + if (track->par->codec_id == AV_CODEC_ID_FLAC) { + if (track->mode != MODE_MP4) { + av_log(s, AV_LOG_ERROR, "FLAC only supported in MP4.\n"); + return AVERROR(EINVAL); + } + if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { + av_log(s, AV_LOG_ERROR, + "FLAC in MP4 support is experimental, add " + "'-strict %d' if you want to use it.\n", + FF_COMPLIANCE_EXPERIMENTAL); + return AVERROR_EXPERIMENTAL; + } + } } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { track->timescale = st->time_base.den; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { -- 2.10.1