From patchwork Fri Apr 7 04:29:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Gregan X-Patchwork-Id: 3327 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp116565vss; Thu, 6 Apr 2017 21:29:52 -0700 (PDT) X-Received: by 10.28.0.78 with SMTP id 75mr25658949wma.138.1491539392797; Thu, 06 Apr 2017 21:29:52 -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 l45si5744782wrc.236.2017.04.06.21.29.52; Thu, 06 Apr 2017 21:29:52 -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=@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 7A34C688361; Fri, 7 Apr 2017 07:29:45 +0300 (EEST) 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 5F2B168092E for ; Fri, 7 Apr 2017 07:29:38 +0300 (EEST) Received: from localhost (unknown [121.98.48.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by flim.org (Postfix) with ESMTPSA id B06FC140F4; Fri, 7 Apr 2017 04:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=flim.org; s=default; t=1491539416; bh=/hB5baEt32qDrPYWS0L4wpI9BQWVIIv5NEdorAp6na0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=34AKQaAUxnKrb2k8ogQft5lEKWMnBinhpJNeD93DOvxOzeGNJ1seT9KBdEXwrCX+V I1jVcXrLFs0ehGefhrOQHVb0w/A+980vbjPnXBBQeFcF5bDTCCO1nQ6AEaxI+R9+qJ v4E08+29D3LrucRqdLpW2FD3kSvtMI7uIH2BAa/8= Date: Fri, 7 Apr 2017 16:29:36 +1200 From: Matthew Gregan To: James Almer Message-ID: <20170407042936.GB21136@brak.lan> Mail-Followup-To: James Almer , FFmpeg development discussions and patches References: <20170316011949.GA30563@brak.lan> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [FFmpeg-devel] [PATCH 2/2] Add experimental support for Opus 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 Cc: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" At 2017-04-05T20:43:21-0300, James Almer wrote: > > + /* OpusSpecificBox size plus magic for Ogg OpusHead header. */ > > + size = atom.size + 16; > > This should be 8. "OpusHead" is not 16 bytes. > > > + avio_read(pb, st->codecpar->extradata + 9, size - 17); > > Same, this should be size - 9. Oops, silly mistake there. Thanks for the feedback! Updated patch attached. From 9ff591b9ae6a50ea3326e7374f800f7dd12eeef2 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Thu, 16 Mar 2017 14:17:21 +1300 Subject: Re: [PATCH 2/2] Add experimental demuxing support for Opus in ISO BMFF (MP4). Based on the draft spec at http://vfrmaniac.fushizen.eu/contents/opus_in_isobmff.html Signed-off-by: Matthew Gregan --- libavformat/mov.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index f2296f8917..2995a009a8 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -5264,6 +5264,54 @@ static int cenc_filter(MOVContext *c, MOVStreamContext *sc, int64_t index, uint8 return 0; } +static int mov_read_dops(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + const int OPUS_SEEK_PREROLL_MS = 80; + AVStream *st; + size_t size; + int16_t pre_skip; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + if ((uint64_t)atom.size > (1<<30) || atom.size < 11) + return AVERROR_INVALIDDATA; + + /* Check OpusSpecificBox version. */ + if (avio_r8(pb) != 0) { + av_log(c->fc, AV_LOG_ERROR, "unsupported OpusSpecificBox version\n"); + return AVERROR_INVALIDDATA; + } + + /* OpusSpecificBox size plus magic for Ogg OpusHead header. */ + size = atom.size + 8; + + if (ff_alloc_extradata(st->codecpar, size)) + return AVERROR(ENOMEM); + + AV_WL32(st->codecpar->extradata, MKTAG('O','p','u','s')); + AV_WL32(st->codecpar->extradata + 4, MKTAG('H','e','a','d')); + AV_WB8(st->codecpar->extradata + 8, 1); /* OpusHead version */ + avio_read(pb, st->codecpar->extradata + 9, size - 9); + + /* OpusSpecificBox is stored in big-endian, but OpusHead is + little-endian; aside from the preceeding magic and version they're + otherwise currently identical. Data after output gain at offset 16 + doesn't need to be bytewapped. */ + pre_skip = AV_RB16(st->codecpar->extradata + 10); + AV_WL16(st->codecpar->extradata + 10, pre_skip); + AV_WL32(st->codecpar->extradata + 12, AV_RB32(st->codecpar->extradata + 12)); + AV_WL16(st->codecpar->extradata + 16, AV_RB16(st->codecpar->extradata + 16)); + + st->codecpar->initial_padding = pre_skip; + st->codecpar->seek_preroll = av_rescale_q(OPUS_SEEK_PREROLL_MS, + (AVRational){1, 1000}, + (AVRational){1, 48000}); + + return 0; +} + static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('A','C','L','R'), mov_read_aclr }, { MKTAG('A','P','R','G'), mov_read_avid }, @@ -5345,6 +5393,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('d','f','L','a'), mov_read_dfla }, { MKTAG('s','t','3','d'), mov_read_st3d }, /* stereoscopic 3D video box */ { MKTAG('s','v','3','d'), mov_read_sv3d }, /* spherical video box */ +{ MKTAG('d','O','p','s'), mov_read_dops }, { 0, NULL } }; -- 2.12.2