From patchwork Thu May 31 23:24:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Timo_Ter=C3=A4s?= X-Patchwork-Id: 9217 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp205726jad; Thu, 31 May 2018 16:25:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKzDGaEcsOl52UDofLZ5HQIWw1pJQmsrZ2ZCsbhf2aqP4wXxFfqEhGnD+Sx4vajB+uQdjDQ X-Received: by 2002:a1c:9991:: with SMTP id b139-v6mr1162384wme.160.1527809120718; Thu, 31 May 2018 16:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527809120; cv=none; d=google.com; s=arc-20160816; b=vFsQVFHAfejQeAJ2GrDBC0c88FB45E3VByBLkM9ow0YMH82+t02tKEKnMhXjkMy1c/ TLICLSrDYsypoT3c8ZydTRnn9OtCARcI5GlCUzkrJD3u1uSEbP7YGxh3jqBoAOaWjOob rGkFLHyMhR4/2XS7AdbA9NYzN7yUPoQ6O/p+Px/BrbluhyCynZjpXxxNetqgMGvQdXkM exjLAQe+ujnQtrkmoldDj/6+vr/jUJWFMfwT48ixG9ywgKpoY35F/grdepB7okIncALr KedtbpIxHf5DMUX816fKLRn7Rh6RNL1qsD7oaWOgLKAyYkZlRq8xRHAqP0hZf5aAJdUo 9xrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to:arc-authentication-results; bh=6gRHNOu34xO402eeBOvvqhYc/ATYjFiOivQCH2CD+0c=; b=e94UtN4yB1zi69MGzM6rS7aBF061xW4lhrU7TtQdHEYxquyYQkDuduHrMc8aGZ77rZ G6x8r097NLMJfvfhkuZxl391X68vG77RSGi0sen9t1elB9LNjuLcSbUnSAlsClzHf3+t wDA5jn+RNR+ZEjLHfZQMzBj8VYf4F4KD1ysXa7zK0rhKB0VYIMzbI5uhuCzbyLwNhEIE HOeazrVVAsr8b5Ak486kRUdO7nySYHx4wrUub5ss/xtGN+zclu3PZJXWvuwmv/iiBDGh gW6JqH3yIVoVvvYQ99UHzAiOeXUJ6TydamOF1jn4ZIUzGmvXsOvHI53DzWLxjFW76YCO 5LaA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 66-v6si401036wmd.35.2018.05.31.16.25.20; Thu, 31 May 2018 16:25:20 -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; 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 DD8E168A4AA; Fri, 1 Jun 2018 02:24:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 736DC68A3D3 for ; Fri, 1 Jun 2018 02:24:27 +0300 (EEST) Received: by mail-qt0-f194.google.com with SMTP id s9-v6so483535qtg.2 for ; Thu, 31 May 2018 16:25:12 -0700 (PDT) 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=C2Yu7iZxNrVUJE7iPbbUDXuC8d/ei0EiP1F0XrOCkDA=; b=rX75nolBlx1TM4Snh0j2ie7i4O0N7VCWZ1YjBNgFiZXeQ+hCzURvP8IJZn/C9YWjYl tqlo56O+woUqrwzJu08jBJzUTU65sFGP0Ka72LErm5nm+Jgw27Vax1yZzI2A7lwbrqQF tdbfbKY24eVmJZNgRA5XAgfBzIvkKzGLuR29EyNqhmpERMgyoKCv94OWYUBPpOk6o0ba bPlDpP9mNpGXLo+uMm5aKHMq6PYjA9Htfazfnzt3dLe6VsYM+qv/Xav2jGSNqCUTq/1z QEW0EwmfHOSVnFz6CXBfKu2CbpGm6AWnIZzGLSjOgTGv+RVzimTxK3blJ4d1nZzl5k+K nWJg== X-Gm-Message-State: APt69E3oCoaVRjNkEEzRnGFPGUDgLYYZAIttfMGP1vfgvcrk2Xh/Iv/w /Il8jTrrPNmb7ttPZ4Zvoww+Csnq X-Received: by 2002:a0c:ad44:: with SMTP id v4-v6mr2979458qvc.120.1527809111618; Thu, 31 May 2018 16:25:11 -0700 (PDT) Received: from localhost.localdomain ([208.74.140.117]) by smtp.gmail.com with ESMTPSA id m6-v6sm3957336qkm.12.2018.05.31.16.25.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 16:25:11 -0700 (PDT) From: =?UTF-8?q?Timo=20Ter=C3=A4s?= To: FFmpeg development discussions and patches , Rostislav Pehlivanov Date: Fri, 1 Jun 2018 02:24:39 +0300 Message-Id: <20180531232439.10858-1-timo.teras@iki.fi> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531225847.10479-1-timo.teras@iki.fi> References: <20180531225847.10479-1-timo.teras@iki.fi> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avformat/movenc: properly handle cover image codecs 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: =?UTF-8?q?Timo=20Ter=C3=A4s?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Find codec tag for attached images using appropriate list of supported image formats. This fixes writing the cover image to m4v/m4a and other container formats that do not allow these codecs as a track. Signed-off-by: Timo Teräs --- This replaces the previous patch: PATCH] [RFC] avformat/movenc: support covert images for ipod muxer It appears that query_codec() is used only to figure out which stream to select as the default copy stream. Fixing it properly for movenc attached pictures is difficult, as the stream disposition would need to be passed through the call stack. Additionally, it would make sense to rewrite the selection logic open_output_file() to not use APIC special tag and be based on the input/output dispositions. So this just adds proper handling of the codecs in mov_init() phase which fixes most of the usability issues. Please backport to 4.0 stable branch too. Changes in v2: - map the codec to the actual covr image tag value and use that when writing the cover image instead of doing a new switch over the codec libavformat/movenc.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 7e616e866f..4ba90135df 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1557,10 +1557,20 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) return tag; } +static const AVCodecTag codec_cover_image_tags[] = { + { AV_CODEC_ID_MJPEG, 0xD }, + { AV_CODEC_ID_PNG, 0xE }, + { AV_CODEC_ID_BMP, 0x1B }, + { AV_CODEC_ID_NONE, 0 }, +}; + static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag; + if (track->st->disposition & AV_DISPOSITION_ATTACHED_PIC) + return ff_codec_get_tag(codec_cover_image_tags, track->par->codec_id); + if (track->mode == MODE_MP4 || track->mode == MODE_PSP) tag = track->par->codec_tag; else if (track->mode == MODE_ISM) @@ -3429,7 +3439,7 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s) { MOVMuxContext *mov = s->priv_data; int64_t pos = 0; - int i, type; + int i; for (i = 0; i < s->nb_streams; i++) { MOVTrack *trk = &mov->tracks[i]; @@ -3439,22 +3449,6 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s) trk->cover_image.size <= 0) continue; - switch (st->codecpar->codec_id) { - case AV_CODEC_ID_MJPEG: - type = 0xD; - break; - case AV_CODEC_ID_PNG: - type = 0xE; - break; - case AV_CODEC_ID_BMP: - type = 0x1B; - break; - default: - av_log(s, AV_LOG_ERROR, "unsupported codec_id (0x%x) for cover", - st->codecpar->codec_id); - continue; - } - if (!pos) { pos = avio_tell(pb); avio_wb32(pb, 0); @@ -3462,7 +3456,7 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s) } avio_wb32(pb, 16 + trk->cover_image.size); ffio_wfourcc(pb, "data"); - avio_wb32(pb, type); + avio_wb32(pb, trk->tag); avio_wb32(pb , 0); avio_write(pb, trk->cover_image.data, trk->cover_image.size); }