From patchwork Tue May 23 13:58:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41799 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600690pzb; Tue, 23 May 2023 07:00:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Td3S6AppHE9gKZ0fFIVoUekfEnq8pcC6DfGN8nQb9MDQhrZZl2UYRhH0e4xtAFSdGapCi X-Received: by 2002:a50:ed8d:0:b0:510:55a3:97ad with SMTP id h13-20020a50ed8d000000b0051055a397admr11200122edr.0.1684850406500; Tue, 23 May 2023 07:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850406; cv=none; d=google.com; s=arc-20160816; b=cXu8yeIz2/12sN1tq0hAcHmP3IAZ0ryi4CyyqF9i8IOCILCKwwBmDm+YscPQmtzI3I grnZs/tsNRwJO7w5ZAtN0X4aJgfEhWezap2uazRreR90/AS6Cqk8C21gLfMNuxL9wZf/ SYi8QvopPI6uVnfH1UGd+dfevLBaB5K7o4Vn+dWt47Ez5GmXfnOyP+R4csDCibPbJ4hm tafAc3Btt5zhLbdh0fRaIBceGZ7mZjLdzttL3U2OqawznFYAFdL/Jl0u5tIE6NLLH9cv 9VF3yrWDyNEQd7sR6mnjXek2sbOysAI/n1KRnVn8sLhAtMzlIM7CFgFtzBHTOuQdVjJY hDZQ== 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=+e6H0XDh3QBcTTVpZUPJJfCgnY+4/SJ7oh3TM9OyaBw=; b=W1uZffW6KzC0eW+NIElqIUBhrBncfbQYo55MqoMSJsymMT2j9cd2uofAwEFEdL1z/n 8TktyVY3v0QKN5fa9D8EZljt0Y5KUwIYna9lQJuofT2aKP13q+FknGjORCKXYPaxd20/ AC3IirPqEz3M0FSBsMNyO8fQLJ8jw0jEB/oS/PuLpZ6SNCjate7WuFPCx9NIqNCBLmqk IKwun8NLiWIniAi/ueaAEJ6qjj40DoXle1K2gl+jXmWn1WK6VTorb8drCeGW1pfAzAov aJSFozsaif0q8VJ9rRWDEsdVktoPMtz3L1RMXkrYGGz2P7uHniLBv1VMQgaL9dFc6FKO jGfA== 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 n22-20020a056402515600b0050bca43049fsi500883edd.350.2023.05.23.07.00.05; Tue, 23 May 2023 07:00:06 -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 7D4EF68C140; Tue, 23 May 2023 16:59:09 +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 B791568C104 for ; Tue, 23 May 2023 16:59:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CD25F2404F8 for ; Tue, 23 May 2023 15:58:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vfy7ZjblJYxg for ; Tue, 23 May 2023 15:58:50 +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 780D3240591 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 448E73A11DB for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:31 +0200 Message-Id: <20230523135842.20388-4-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/15] fftools/ffmpeg: fail earlier on text/bitmap subtitles mismatch 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: GRBi4uBMAjBc Checking whether the user requested an unsupported conversion between text and bitmap subtitles can be done immediately when creating the output stream. --- fftools/ffmpeg_enc.c | 18 ------------------ fftools/ffmpeg_mux_init.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 59e9466420..f023657a07 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -345,24 +345,6 @@ int enc_open(OutputStream *ost, AVFrame *frame) dec_ctx->subtitle_header_size); enc_ctx->subtitle_header_size = dec_ctx->subtitle_header_size; } - if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE && - enc_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { - int input_props = 0, output_props = 0; - AVCodecDescriptor const *input_descriptor = - avcodec_descriptor_get(ist->dec->id); - AVCodecDescriptor const *output_descriptor = - avcodec_descriptor_get(enc_ctx->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 (input_props && output_props && input_props != output_props) { - av_log(ost, AV_LOG_ERROR, - "Subtitle encoding currently only possible from text to text " - "or bitmap to bitmap"); - return AVERROR_INVALIDDATA; - } - } break; default: diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b73791acee..56f9d1215c 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -822,6 +822,13 @@ static void new_stream_subtitle(Muxer *mux, const OptionsContext *o, if (ost->enc_ctx) { AVCodecContext *subtitle_enc = ost->enc_ctx; + + AVCodecDescriptor const *input_descriptor = + avcodec_descriptor_get(ost->ist->par->codec_id); + AVCodecDescriptor const *output_descriptor = + avcodec_descriptor_get(subtitle_enc->codec_id); + int input_props = 0, output_props = 0; + char *frame_size = NULL; MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, mux->fc, st); @@ -829,6 +836,16 @@ static void new_stream_subtitle(Muxer *mux, const OptionsContext *o, av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size); exit_program(1); } + 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 (input_props && output_props && input_props != output_props) { + av_log(ost, AV_LOG_ERROR, + "Subtitle encoding currently only possible from text to text " + "or bitmap to bitmap\n"); + exit_program(1); + } } }