From patchwork Wed Sep 28 09:55:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38422 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp94072pzh; Wed, 28 Sep 2022 02:59:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7fJQUkiI7qPXDiO4NVhlRZS1NH8NseyUx2jhR6tGHOmZzyb7B8MPDBoDl3GCrNdq6DxOZz X-Received: by 2002:a17:907:2c74:b0:77d:5a0e:bb8f with SMTP id ib20-20020a1709072c7400b0077d5a0ebb8fmr25769603ejc.579.1664359164489; Wed, 28 Sep 2022 02:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664359164; cv=none; d=google.com; s=arc-20160816; b=zms3klk6yZaNo5AKXqJRPv5SDn4EHpGnntqbRXXpqJVpYB+HGbtWh4a5I7oQNXMLDa dtfszDqfNW21MaYoPPRbGcgMJQwLHKty1iTjKpSl1RJCChrdI6RlLpNiNxUhZsGRU0vr pbIVWtkM5vdrirvQSc+Vfa8QMPQdm7nksxq2WZ0TJH9YgsiUuVHQyDAEHGY34yh2QpRW oC5u/JnIUUl14M7UQNHuM8Ji7fWMo8S6oCqkziCvJBZOGdBTOacUdiZyoVnJzbzc0Mi/ bqWKtHvyYKBUs2Nn2iMibcR9UvvFuhVUAcPLl06nJ1ookz04adlUh3LI70v/EltcnGkv ntYQ== 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=oC/G6vAsqoSOTIelD7hncCyCfbzDOuPSsw4VmQcgjQA=; b=bgCrLhzbd2zpf5fublgKIYjGTmYVUDIFi/FCD7PkdlDj7NzIvd4J6Io1dAWonJQkxj RW0u5RCxV+ZLo/ct/6lke4MmFOYSvpAnafLP7Cf11k+Rmymd0Nn0/6t9zhVM+/Kzlz5o /Jp0ApJ5GLvQ5w3ObM4Rif9DbqyCLdKmi2oFixHgXE4vrH9p6dT8rr91OO+uv8xVtalc v+jan0sKgTxfzwA/luWid+gCUpMohJ8DJN7+kpkO8YV0P6UbZ8AyjcWMf+Sb59MsR4pN lo84e09+UhDCzF+PDsCBVfDMt/r6slaVzo7SpULApl/IdCN2neVt+3jSpT042whtDXPZ d1tg== 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 nc19-20020a1709071c1300b0078276be53d5si4678613ejc.0.2022.09.28.02.59.24; Wed, 28 Sep 2022 02:59:24 -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 49AB568BC10; Wed, 28 Sep 2022 12:58:18 +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 A120268BBDD for ; Wed, 28 Sep 2022 12:58:07 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3F1A12405EC for ; Wed, 28 Sep 2022 11:58:04 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id nYmx-0f_i6NG for ; Wed, 28 Sep 2022 11:58:03 +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 36F632405F9 for ; Wed, 28 Sep 2022 11:58:01 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 48D433A1767 for ; Wed, 28 Sep 2022 11:58:01 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 11:55:56 +0200 Message-Id: <20220928095556.28209-9-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220928095556.28209-1-anton@khirnov.net> References: <20220928095556.28209-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: move some code from init_output_stream() to init_output_stream_encode() 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: 8Xjxm4j1gn2Z The code is subtitle-encoding-specific, so this is a more appropriate place for it. --- fftools/ffmpeg.c | 58 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 6deca8bfbf..754172e568 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3129,6 +3129,34 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) enc_ctx->width = input_streams[ost->source_index]->par->width; enc_ctx->height = input_streams[ost->source_index]->par->height; } + if (dec_ctx && dec_ctx->subtitle_header) { + /* ASS code assumes this buffer is null terminated so add extra byte. */ + ost->enc_ctx->subtitle_header = av_mallocz(dec_ctx->subtitle_header_size + 1); + if (!ost->enc_ctx->subtitle_header) + return AVERROR(ENOMEM); + memcpy(ost->enc_ctx->subtitle_header, dec_ctx->subtitle_header, + dec_ctx->subtitle_header_size); + ost->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(ost->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(NULL, AV_LOG_ERROR, + "Subtitle encoding currently only possible from text to text " + "or bitmap to bitmap"); + return AVERROR_INVALIDDATA; + } + } + break; case AVMEDIA_TYPE_DATA: break; @@ -3156,23 +3184,13 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, if (ost->enc_ctx) { const AVCodec *codec = ost->enc_ctx->codec; - AVCodecContext *dec = NULL; InputStream *ist; ret = init_output_stream_encode(ost, frame); if (ret < 0) return ret; - if ((ist = get_input_stream(ost))) - dec = ist->dec_ctx; - if (dec && dec->subtitle_header) { - /* ASS code assumes this buffer is null terminated so add extra byte. */ - ost->enc_ctx->subtitle_header = av_mallocz(dec->subtitle_header_size + 1); - if (!ost->enc_ctx->subtitle_header) - return AVERROR(ENOMEM); - memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); - ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size; - } + ist = get_input_stream(ost); if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0)) av_dict_set(&ost->encoder_opts, "threads", "auto", 0); @@ -3184,24 +3202,6 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, return ret; } - if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE && codec->type == AVMEDIA_TYPE_SUBTITLE) { - int input_props = 0, output_props = 0; - AVCodecDescriptor const *input_descriptor = - avcodec_descriptor_get(dec->codec_id); - AVCodecDescriptor const *output_descriptor = - avcodec_descriptor_get(ost->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) { - snprintf(error, error_len, - "Subtitle encoding currently only possible from text to text " - "or bitmap to bitmap"); - return AVERROR_INVALIDDATA; - } - } - if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) { if (ret == AVERROR_EXPERIMENTAL) abort_codec_experimental(codec, 1);