From patchwork Thu Aug 15 05:43:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Ionascu X-Patchwork-Id: 14521 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D2C314441CD for ; Thu, 15 Aug 2019 08:50:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A5127689A43; Thu, 15 Aug 2019 08:50:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 913BA689A00 for ; Thu, 15 Aug 2019 08:50:02 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id 10so320624wmp.3 for ; Wed, 14 Aug 2019 22:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tT0R8tu31LZhlxRFkllxj3jZWYYgqNqIOj/fnapbBQY=; b=W063YzZkg3/jqOJI5x3hpxJWc6mRSHKtENMj2xpgUkaAKe3GcX5YRWENNUa9r9Z6ea mdA9W79WG6jWF2yhhPnjq4/iR7sHXhiWI6Gdv2oClldeUfkVc2AUdIFgelvFf2XKIBtg 7gN5M55bMTTZHigqKjvxTD4Tz4qfLTxfSqZAN224ZfhRGgepOc3Gp1IKIMNFVx0Axi54 gk43bnOGZOlj4w6PT0rfZkbqgB9Xn2rz/lIjVirMFeP2eQuiN9QTR0z7r9QiMP5a6M71 YFgQPBTS8yHtJobFkDQd9P4MxtreRwUIZjbAGK2b3wLeepHGxCngJxnmWGtiQGWc87C4 usxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tT0R8tu31LZhlxRFkllxj3jZWYYgqNqIOj/fnapbBQY=; b=KlIsoS8/1ca7vUle3VSzkTqH87VJktnjNGLgeFO7GutgItg25OSOpRv6WoLq7YbD8G HzlCPENsISBIUCoTXs/t9bTfA2w8TmSJDgsXOtYv/WfEU/DNXhDS5KauhMf1mhzHnIRm VNbFY6yz69roaJ7dj376rYXXs8JhVPZfl9U/z4dyM7GFJPHrTwFvp5SW8Q6U1Q5vw88b v+qfbIj95E2uXulZQEBQuBiZbEZRklRJtluBzn0WXX79HlJs09c8L93ZK2sQbj6GcBSi qyig1haTV1KbflPoLUYDfKJlQOyU3INaRok5nrcakc+RD2ItwqZo9m1Kim92YPbbcp6G 0Xjg== X-Gm-Message-State: APjAAAXCJt6kGYmcAIO2eQYnvi/4oiBR/muc28+8NJQFbdAg/ldfbZX0 U8bP/JssFZNp9wlLYc5jN24QDL+D X-Google-Smtp-Source: APXvYqxcrd8IpXyvz7C1ly4iKTljGJwYPi3Jzc23Q/q7KTkBsWuJvxUHVUuqVfH9TtdJ4ayDKT/S0Q== X-Received: by 2002:a1c:9e4b:: with SMTP id h72mr821197wme.99.1565847890504; Wed, 14 Aug 2019 22:44:50 -0700 (PDT) Received: from LAPTOP.fritz.box (2a0a-a544-f227-0-3114-9dc1-c006-e6bb.ipv6dyn.netcologne.de. [2a0a:a544:f227:0:3114:9dc1:c006:e6bb]) by smtp.gmail.com with ESMTPSA id 6sm451848wmf.23.2019.08.14.22.44.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 22:44:49 -0700 (PDT) From: Stanislav Ionascu To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Aug 2019 07:43:33 +0200 Message-Id: <20190815054333.541-1-stanislav.ionascu@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190814215044.GO3219@michaelspb> References: <20190814215044.GO3219@michaelspb> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avformat/matroskadec: properly parse stsd in v_quicktime 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: Stanislav Ionascu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Per matroska spec, v_quicktime contains the complete stsd atom, after the mandatory size + fourcc. By properly parsing the hvcc sub-atoms of the track, it becomes possible to demux/decode mp4/mov tracks stored as is in matroska containers. Also dvh1 in stsd in matroska is more likely hevc codec than dv. QuickTime palette parsing is reused from the stsd parser results. Signed-off-by: Stanislav Ionascu --- libavformat/matroskadec.c | 62 +++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 4e20f15792..9ca9efe6b1 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2473,25 +2473,51 @@ static int matroska_parse_tracks(AVFormatContext *s) } else if (!strcmp(track->codec_id, "V_QUICKTIME") && (track->codec_priv.size >= 21) && (track->codec_priv.data)) { - int ret = get_qt_codec(track, &fourcc, &codec_id); - if (ret < 0) - return ret; - if (codec_id == AV_CODEC_ID_NONE && AV_RL32(track->codec_priv.data+4) == AV_RL32("SMI ")) { - fourcc = MKTAG('S','V','Q','3'); - codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc); + MOVStreamContext *msc; + MOVContext *mc = NULL; + void *priv_data; + int nb_streams; + priv_data = st->priv_data; + nb_streams = s->nb_streams; + mc = av_mallocz(sizeof(*mc)); + if (!mc) + return AVERROR(ENOMEM); + mc->fc = s; + st->priv_data = msc = av_mallocz(sizeof(MOVStreamContext)); + if (!msc) { + av_free(mc); + st->priv_data = priv_data; + return AVERROR(ENOMEM); } - if (codec_id == AV_CODEC_ID_NONE) - av_log(matroska->ctx, AV_LOG_ERROR, - "mov FourCC not found %s.\n", av_fourcc2str(fourcc)); - if (track->codec_priv.size >= 86) { - bit_depth = AV_RB16(track->codec_priv.data + 82); - ffio_init_context(&b, track->codec_priv.data, - track->codec_priv.size, - 0, NULL, NULL, NULL, NULL); - if (ff_get_qtpalette(codec_id, &b, track->palette)) { - bit_depth &= 0x1F; - track->has_palette = 1; - } + ffio_init_context(&b, track->codec_priv.data, + track->codec_priv.size, + 0, NULL, NULL, NULL, NULL); + + /* ff_mov_read_stsd_entries updates stream s->nb_streams-1, + * so set it temporarily to indicate which stream to update. */ + s->nb_streams = st->index + 1; + ff_mov_read_stsd_entries(mc, &b, 1); + + /* copy palette from MOVStreamContext */ + track->has_palette = msc->has_palette; + if (track->has_palette) { + /* leave bit_depth = -1, to reuse bits_per_coded_sample */ + memcpy(track->palette, msc->palette, AVPALETTE_COUNT); + } + + av_free(msc); + av_free(mc); + st->priv_data = priv_data; + s->nb_streams = nb_streams; + fourcc = st->codecpar->codec_tag; + codec_id = st->codecpar->codec_id; + + av_log(matroska->ctx, AV_LOG_TRACE, + "mov FourCC found %s.\n", av_fourcc2str(fourcc)); + + // dvh1 in mkv is likely HEVC + if (st->codecpar->codec_tag == MKTAG('d','v','h','1')) { + codec_id = AV_CODEC_ID_HEVC; } } else if (codec_id == AV_CODEC_ID_PCM_S16BE) { switch (track->audio.bitdepth) {