From patchwork Sat Jul 23 14:09:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36906 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1046940pzb; Sat, 23 Jul 2022 07:11:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7wPt6/f2pXa7rmSlpuKWmV5IGZJf0kiHeed5EhjOXUh3wzYdL1IxpJ+fHTCH+lyf1JlIV X-Received: by 2002:a17:907:a0c7:b0:72f:b205:112 with SMTP id hw7-20020a170907a0c700b0072fb2050112mr3559108ejc.559.1658585487367; Sat, 23 Jul 2022 07:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658585487; cv=none; d=google.com; s=arc-20160816; b=u8+JkrBmhfB70yTLJrPwsbnK2JHGS7PThEaJ80TUMkPf7r2gPpzHoLTQJfq3jmUqRf 87OGmKAVvMUjo8ERcMREVgewhs9XAS4n8UBumtp+Ef3eCzYJbGcMkUQB9OksdbolYnGU l5rmeIBj4+g/3fPn8uUYcK3IbAkBD4uBI1kJxEfVpd5xDxm8mSjO4BJ5ckPpvPHMHHsK M2eXD2qV9uT7sjxoZ5C9fe/0n5MT4r0KvbLZSbJcJY3wkHlY7lrOiM9aAqUCPMrlDE6p crTYn4xOjXvunPIn4/g0CcGun+VB4S4BDHNnCUOYItm8UzIvR0ix84CmlxFon0tq6qTG 48tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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; bh=+wkBUizy7P+aDaKf8c4j9Av7mpHt5jIHZTiCh+QDh+Y=; b=wii5oUGHVv4KjQgFyHHIPxOGfsOuEFw3n+bTcArT3Nclei2muiyNiReoxy/9zsOgRR ncOP2IX09GeMHLPlM2nOWGDJTK/Q9jXMss3TBiMM2MGIi9tC4BF+kxSoLm29b4FZfoO5 K5tjh7mOoasYIQ9NZyxyw36IVuaAB3Q/LqNMQk/ZsAHMTt9AGb+39hilN9Llmuc2Yrhm xrkxEQQhD0l1umWBoCJcyriKgKTEssw9CkQcTIWBlIFaArKa4BDiah1Akm+zR1bGE3t3 xpDFJCw83R3HmXhqmXk6LrJkKl7qp569LCZq0nEL5WM7trxUK/X0uOO+J1TrEa/RuBQV J5sQ== 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 b11-20020a0564021f0b00b0043bca6b19e3si5990952edb.609.2022.07.23.07.11.26; Sat, 23 Jul 2022 07:11:27 -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 DD77A68B74E; Sat, 23 Jul 2022 17:10:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D23DA68B7B5 for ; Sat, 23 Jul 2022 17:10:27 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EF82E24056A for ; Sat, 23 Jul 2022 16:10:24 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id n5yplG66vKoV for ; Sat, 23 Jul 2022 16:10:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id A3C93240590 for ; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id B27D43A03EF; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Jul 2022 16:09:47 +0200 Message-Id: <20220723140952.31814-22-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220723140952.31814-1-anton@khirnov.net> References: <20220723140952.31814-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/27] fftools/ffmpeg_opt: factor auto-mapping subtitles out of open_output_file() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: aChot7EqYbH9 --- fftools/ffmpeg_opt.c | 70 ++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 174b1dd0eb..da74b0265a 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2580,6 +2580,42 @@ static void map_auto_audio(OutputFile *of, AVFormatContext *oc, new_audio_stream(o, oc, idx); } +static void map_auto_subtitle(OutputFile *of, AVFormatContext *oc, + OptionsContext *o) +{ + char *subtitle_codec_name = NULL; + /* subtitles: pick first */ + MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s"); + if ((avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) { + for (int i = 0; i < nb_input_streams; i++) + if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + AVCodecDescriptor const *input_descriptor = + avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id); + AVCodecDescriptor const *output_descriptor = NULL; + AVCodec const *output_codec = + avcodec_find_encoder(oc->oformat->subtitle_codec); + int input_props = 0, output_props = 0; + if (input_streams[i]->user_set_discard == AVDISCARD_ALL) + continue; + if (output_codec) + output_descriptor = avcodec_descriptor_get(output_codec->id); + if (input_descriptor) + input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); + if (output_descriptor) + output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); + if (subtitle_codec_name || + input_props & output_props || + // Map dvb teletext which has neither property to any output subtitle encoder + input_descriptor && output_descriptor && + (!input_descriptor->props || + !output_descriptor->props)) { + new_subtitle_stream(o, oc, i); + break; + } + } + } +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -2656,44 +2692,14 @@ static int open_output_file(OptionsContext *o, const char *filename) } if (!o->nb_stream_maps) { - char *subtitle_codec_name = NULL; /* pick the "best" stream of each type */ if (!o->video_disable) map_auto_video(of, oc, o); if (!o->audio_disable) map_auto_audio(of, oc, o); + if (!o->subtitle_disable) + map_auto_subtitle(of, oc, o); - - /* subtitles: pick first */ - MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s"); - if (!o->subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) { - for (i = 0; i < nb_input_streams; i++) - if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { - AVCodecDescriptor const *input_descriptor = - avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id); - AVCodecDescriptor const *output_descriptor = NULL; - AVCodec const *output_codec = - avcodec_find_encoder(oc->oformat->subtitle_codec); - int input_props = 0, output_props = 0; - if (input_streams[i]->user_set_discard == AVDISCARD_ALL) - continue; - if (output_codec) - output_descriptor = avcodec_descriptor_get(output_codec->id); - if (input_descriptor) - input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); - if (output_descriptor) - output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); - if (subtitle_codec_name || - input_props & output_props || - // Map dvb teletext which has neither property to any output subtitle encoder - input_descriptor && output_descriptor && - (!input_descriptor->props || - !output_descriptor->props)) { - new_subtitle_stream(o, oc, i); - break; - } - } - } /* Data only if codec id match */ if (!o->data_disable ) { enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_DATA);