From patchwork Thu Apr 16 02:18:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18989 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 D59D944A541 for ; Thu, 16 Apr 2020 05:18:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A980A68B7BA; Thu, 16 Apr 2020 05:18:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E341F68B74A for ; Thu, 16 Apr 2020 05:18:14 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id y24so3103225wma.4 for ; Wed, 15 Apr 2020 19:18:14 -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:mime-version :content-transfer-encoding; bh=gpRRptHyaXo+53vx0G8m6Dyelox1nC9CkbC0lCqTAAo=; b=l3mk1EPFa083TPoBVmUbwkpWdlJpJImE8NU0kp6siQylpiU5SV2HQOBqda9KzgOGSc AoRz9Zzag/lyTGaaxMreznGUhW01Cgy0vegxxVpY+B4CezaVAxMiNrrpWOii9ZzTkz07 qBzwgJdf7pHFEnVQFHvDBakpbR/6KgePtxbRwPxfo5PLaGxKkbdhAFYb+wdkMXSnP0T9 mcJaNHCNIcSUsAdeOcogVS9yYQHxcRk5SuOe5/13x6BX4GGwWgslpnUoaDrHSy3vhenf 0ajrxNBzdGY+06pfy6t0F36v5sryB73Cdv2gu2u7rJqhGcUZLoOYpNuIAqllBNkq29Fc oEcQ== 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:mime-version :content-transfer-encoding; bh=gpRRptHyaXo+53vx0G8m6Dyelox1nC9CkbC0lCqTAAo=; b=DBm7CicP5DrjgiuQZRACWAHDTGu71KnTRhhRjLnF0VYJ8GijwsY0cMV/Z+/fUNbH7s 6EcD4dydudmMmXJuOXJUsiwBriitDqtKschQe3qITbqnOWbmNaAlw63z9u5S69lcVqIt LQVvjuLXynceBeZ/G3Ywq2BeJLJV44Wsp2Nc3L43/6hM8tRI5Jibs/jVm80fnl9O63Gv 5t8st/GNsDvwVRZmNpdricc8HXuMtiSke2aD8FzApD3QVxVW07ABK57h9pGj6xhBFK4o Jr/c59QrX4teleJqRUJPw/PFoxRC/q56S+9PPMLvuefKRgtsAJiu6ZnzZElBozyeL+i0 62qA== X-Gm-Message-State: AGi0PubhBXOrNnLGeeX9H/5U6CpGvpNPtpURqWDatX/A7k6BEmSokbE2 bh+PX8yEM4B8qsyAs7+S1Ie22H0b X-Google-Smtp-Source: APiQypKYckluG2CcsP7hL6eX3bCk7zz5EoYqtqgPcP+L4dOlbfUqJ/RQ5fwjr9aG0IaW5FtnKQmWzg== X-Received: by 2002:a1c:4085:: with SMTP id n127mr2356550wma.163.1587003493460; Wed, 15 Apr 2020 19:18:13 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v1sm21217455wrv.19.2020.04.15.19.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 19:18:12 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Apr 2020 04:18:03 +0200 Message-Id: <20200416021804.17900-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/matroskaenc: Improve mimetype search 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Use the mime_types of the corresponding AVCodecDescriptor instead of tables specific to Matroska. The former are generally more encompassing: They contain every item of the current lists except "text/plain" for AV_CODEC_ID_TEXT and "binary" for AV_CODEC_ID_BIN_DATA. The former has been preserved by special-casing it while the latter is a hack added in c9212abf so that the demuxer (which uses the same tables) sets the appropriate CodecID for broken files ("binary" is not a correct mime type at all); using it for the muxer was a mistake. The correct mime type for AV_CODEC_ID_BIN_DATA is "application/octet-stream" and this is what one gets from the AVCodecDescriptor. Signed-off-by: Andreas Rheinhardt --- I also have a patch like this for the Matroska demuxer; it would make the mime_tables in matroska.c completely superfluous. But there are two things that need to be fixed before this can happen: 1. The Matroska muxer must be able to write video streams with attached pic disposition as attachment. (This is currently broken and if more attachments will be exported as attached picture video streams (as will happen because the AVCodecDescriptor list contains entries (e.g. WebP) that the current list does not contain), then more simple Matroska->Matroska remuxing scenarios will be affected by this.) 2. The Matroska demuxer does not set the dimensions of attached pictures (because they are not available at the container level). So if no decoder is available, these values will never be set. But init_muxer() in mux.c checks for valid dimensions (unless the format is of AVFMT_NODIMENSIONS type which Matroska is not (strangely not even the null or the hash muxers have this set)) and this breaks e.g. remuxing Matroska->Matroska. Given that e.g. the flac muxer needs the dimensions for attached pictures, one cannot simply omit the check for attached picture streams. The only solution I can think of is adding another flag which says that the format does not need dimensions for attached pictures. Of course, 1. needs to be fixed before the proposed solution for 2. makes any sense (at least for Matroska, I don't know if there are other formats that are affected by this). libavformat/matroskaenc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index d3256d8f5d..e1ddf366d4 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1667,17 +1667,11 @@ static int mkv_write_attachments(AVFormatContext *s) if (t = av_dict_get(st->metadata, "mimetype", NULL, 0)) mimetype = t->value; else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) { - int i; - for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_mime_tags[i].id == st->codecpar->codec_id) { - mimetype = ff_mkv_mime_tags[i].str; - break; - } - for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_image_mime_tags[i].id == st->codecpar->codec_id) { - mimetype = ff_mkv_image_mime_tags[i].str; - break; - } + const AVCodecDescriptor *desc = avcodec_descriptor_get(st->codecpar->codec_id); + if (desc && desc->mime_types) { + mimetype = desc->mime_types[0]; + } else if (st->codecpar->codec_id = AV_CODEC_ID_TEXT) + mimetype = "text/plain"; } if (!mimetype) { av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and " From patchwork Thu Apr 16 02:18:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18990 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 F410B44A0D1 for ; Thu, 16 Apr 2020 05:18:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D5F5768BB3D; Thu, 16 Apr 2020 05:18:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76D1068BB2E for ; Thu, 16 Apr 2020 05:18:28 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id u13so3030117wrp.3 for ; Wed, 15 Apr 2020 19:18:28 -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=ZPuSgCqtS5uc1NST+kvAmy6YrGOygJImi6VuE3ntkgE=; b=RFFNvqs0ZNQv0CEbqDppP8rOq5Haqg8I0lLPCz1uBEh70nUJUCirYHHZDcbyB/kaTk 0ajFavb4q7r7FzQ9JBDq4dy7stS0zthZ3jP3IaVvd4zvlF5NUOhwc4MOBI9awCQOm8rU Xkg0TlRCVK2IfdVG/1SNuHdKZyat3oytYyBYgNks9BOxEUnrYadt3jvGTfTXtKcuIR5w SdI6UL0o7hiXWJetE11mU0PCQX0l/XVVSHngoTbPunRYVTtfpw/JccX5fh0/b6688waN 39BZv43mKM2ZfCGcjj7qwEN/5dsWTbdStarIO60ulMxSDfqzzwgEA0FkQ6gEllVY/lDh gBlw== 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=ZPuSgCqtS5uc1NST+kvAmy6YrGOygJImi6VuE3ntkgE=; b=sr8YwcDmtJNbezr8B0XoISVYuIzKp4f1YjpME5yIXCmTmlcQtt8ObD+mmu3lta+lAI GuxyykLfkCekIV5M48D4STip4qBSKsdc6Nc5c+eXYFLfUq0X5Nn1Qa944OTOGGFoM4jL OxxYgOcl0LJNrbQMy3yLWjd4tzrRKRsKmBeq+/xI83Q5rMye590k+2q7w+KLq2WdTDum V3ssO5+frKVjTerzvvuOTwIPPmGLdVBumHMq8ZQIb4zXvNy/MMWAtoCMXsbTrET00dzF zQxIWiEioK3TnWrN+z+GDzohDJStE8pIrnXQ9uSRErZZueed82N3mVq/lVr/+fjfjR7G q2Rg== X-Gm-Message-State: AGi0PubmOrIoRMxq/r5bu/mK+zIf3AtX66mn+avDrdWqFwUTY9fKqTx+ 5MYAogkyFghgLLsCHY0+Tt/CWlU+ X-Google-Smtp-Source: APiQypLy/jjZs7y05oqL2A6y31fiYjA6AehQzhSbh4NSVuecPgl4JkT6UkdvHP4nqa78B8b5ELGtGw== X-Received: by 2002:a5d:574b:: with SMTP id q11mr22216441wrw.324.1587003507504; Wed, 15 Apr 2020 19:18:27 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v1sm21217455wrv.19.2020.04.15.19.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 19:18:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Apr 2020 04:18:04 +0200 Message-Id: <20200416021804.17900-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200416021804.17900-1-andreas.rheinhardt@gmail.com> References: <20200416021804.17900-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/matroska: Move mime_tag lists to matroskadec 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" They are not used any more by the muxer. Signed-off-by: Andreas Rheinhardt --- libavformat/matroska.c | 19 ------------------- libavformat/matroska.h | 2 -- libavformat/matroskadec.c | 35 +++++++++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/libavformat/matroska.c b/libavformat/matroska.c index 4d18d147fc..7c56aba403 100644 --- a/libavformat/matroska.c +++ b/libavformat/matroska.c @@ -119,25 +119,6 @@ const CodecTags ff_webm_codec_tags[] = { {"" , AV_CODEC_ID_NONE} }; -const CodecMime ff_mkv_image_mime_tags[] = { - {"image/gif" , AV_CODEC_ID_GIF}, - {"image/jpeg" , AV_CODEC_ID_MJPEG}, - {"image/png" , AV_CODEC_ID_PNG}, - {"image/tiff" , AV_CODEC_ID_TIFF}, - - {"" , AV_CODEC_ID_NONE} -}; - -const CodecMime ff_mkv_mime_tags[] = { - {"text/plain" , AV_CODEC_ID_TEXT}, - {"application/x-truetype-font", AV_CODEC_ID_TTF}, - {"application/x-font" , AV_CODEC_ID_TTF}, - {"application/vnd.ms-opentype", AV_CODEC_ID_OTF}, - {"binary" , AV_CODEC_ID_BIN_DATA}, - - {"" , AV_CODEC_ID_NONE} -}; - const AVMetadataConv ff_mkv_metadata_conv[] = { { "LEAD_PERFORMER", "performer" }, { "PART_NUMBER" , "track" }, diff --git a/libavformat/matroska.h b/libavformat/matroska.h index e177cd027f..6f198f06e6 100644 --- a/libavformat/matroska.h +++ b/libavformat/matroska.h @@ -362,8 +362,6 @@ typedef struct CodecTags{ extern const CodecTags ff_mkv_codec_tags[]; extern const CodecTags ff_webm_codec_tags[]; -extern const CodecMime ff_mkv_mime_tags[]; -extern const CodecMime ff_mkv_image_mime_tags[]; extern const AVMetadataConv ff_mkv_metadata_conv[]; extern const char * const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREOMODE_TYPE_NB]; extern const char * const ff_matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT]; diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index c699ce66b8..ff6c6c0c9e 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -747,6 +747,25 @@ static EbmlSyntax matroska_cluster_enter[] = { }; #undef CHILD_OF +static const CodecMime mkv_image_mime_tags[] = { + {"image/gif" , AV_CODEC_ID_GIF}, + {"image/jpeg" , AV_CODEC_ID_MJPEG}, + {"image/png" , AV_CODEC_ID_PNG}, + {"image/tiff" , AV_CODEC_ID_TIFF}, + + {"" , AV_CODEC_ID_NONE} +}; + +static const CodecMime mkv_mime_tags[] = { + {"text/plain" , AV_CODEC_ID_TEXT}, + {"application/x-truetype-font", AV_CODEC_ID_TTF}, + {"application/x-font" , AV_CODEC_ID_TTF}, + {"application/vnd.ms-opentype", AV_CODEC_ID_OTF}, + {"binary" , AV_CODEC_ID_BIN_DATA}, + + {"" , AV_CODEC_ID_NONE} +}; + static const char *const matroska_doctypes[] = { "matroska", "webm" }; static int matroska_read_close(AVFormatContext *s); @@ -2882,10 +2901,10 @@ static int matroska_read_header(AVFormatContext *s) av_dict_set(&st->metadata, "mimetype", attachments[j].mime, 0); st->codecpar->codec_id = AV_CODEC_ID_NONE; - for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { - if (!strncmp(ff_mkv_image_mime_tags[i].str, attachments[j].mime, - strlen(ff_mkv_image_mime_tags[i].str))) { - st->codecpar->codec_id = ff_mkv_image_mime_tags[i].id; + for (i = 0; mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { + if (!strncmp(mkv_image_mime_tags[i].str, attachments[j].mime, + strlen(mkv_image_mime_tags[i].str))) { + st->codecpar->codec_id = mkv_image_mime_tags[i].id; break; } } @@ -2913,10 +2932,10 @@ static int matroska_read_header(AVFormatContext *s) memcpy(st->codecpar->extradata, attachments[j].bin.data, attachments[j].bin.size); - for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { - if (!strncmp(ff_mkv_mime_tags[i].str, attachments[j].mime, - strlen(ff_mkv_mime_tags[i].str))) { - st->codecpar->codec_id = ff_mkv_mime_tags[i].id; + for (i = 0; mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { + if (!strncmp(mkv_mime_tags[i].str, attachments[j].mime, + strlen(mkv_mime_tags[i].str))) { + st->codecpar->codec_id = mkv_mime_tags[i].id; break; } }