From patchwork Wed Aug 3 13:58:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37119 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp460096pzb; Wed, 3 Aug 2022 07:02:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR720YJA2h3T9P3m/Q7LyXGaTvIFvhx2k74oKdd1t6216Z9hFbN7WS5p7QL0TkNVZw45No72 X-Received: by 2002:a05:6402:43c5:b0:43d:f9ca:4061 with SMTP id p5-20020a05640243c500b0043df9ca4061mr7976702edc.352.1659535374786; Wed, 03 Aug 2022 07:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535374; cv=none; d=google.com; s=arc-20160816; b=fIOCSvcAXeWyod1FjmdTQwWRsb+Ww4jqMLkwMVOJ5qLFhggz6jc3KQuWhW2OL1mlqZ 6cfZ2MkrdttCNgcM/BL0ZB0oFWnd0KZrtD6zMxPwp7ihtaKnY7Aal4MAg9FS8gNjueSA PRkeDynD0LSsrAxohdf8fHAmvK8lKt9BoH2yduOAeFmKKvjw8asUWoULsXaTaYx6kDtV tR0yqe1D5JcUmGkn3emYcEz7aLfYTXEEUAaokRZmItBxVeoiRabD1scPEzcop0DbNDKG 6sFv7cmw9xCqlQUuARuymhFMvAwIR3FZL5Vq/YDFWacVOZoFYSewu5J5N/dh7qNSJ49h MZTg== 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=t2wXVx4m7KWHXurvmKVIdJkZgFymaBbfi0vpj8bptVU=; b=GgMydkPko6XtE4dKn5yiwim0hdpQ5691kkMYVSBbqE8xCnDFhnAIVBnQzqT4CEG6Fz 7OgW4grZkvWV1J8FGt02alMP5Y0T0hRlM8dwh9rkCTFUCkPWaK/DReARdt3T08DPQ7Ey otA4S0H8NSosfnxS8njqTwA4y4QOQEutaPd6z4GtKiliIhg8cha/R14/y8mBdtVqhSFx iJQ72XfSlQOUDW234ziy4bKeElo+2xUfbVWb64erYRBNG5I1A+9SRyHjW/Uo+ig3ReUT fvkXFYT1rExNuPKtG2arCskzlum1/CDaR9AaGNu2NvXAUbxYCffM6Os+Uh7SMLTxCecj 67lw== 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 nd12-20020a170907628c00b0073066a8f85esi10457205ejc.686.2022.08.03.07.02.49; Wed, 03 Aug 2022 07:02:54 -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 668A968B9D7; Wed, 3 Aug 2022 16:59:24 +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 A179A68B8F7 for ; Wed, 3 Aug 2022 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1A237240179 for ; Wed, 3 Aug 2022 15:59:03 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id aFW-VUp1OU-t for ; Wed, 3 Aug 2022 15:59:00 +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 00CF824056A for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 038A23A0451; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:26 +0200 Message-Id: <20220803135844.16662-7-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy 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: dAIihIC1Ejx0 There are currently three possible modes for an output stream: 1) The stream is produced by encoding output from some filtergraph. This is true when ost->enc_ctx != NULL, or equivalently when ost->encoding_needed != 0. 2) The stream is produced by copying some input stream's packets. This is true when ost->enc_ctx == NULL && ost->source_index >= 0. 3) The stream is produced by attaching some file directly. This is true when ost->enc_ctx == NULL && ost->source_index < 0. OutputStream.stream_copy is currently used to identify case 2), and sometimes to confusingly (or even incorrectly) identify case 1). Remove it, replacing its usage with checking enc_ctx/source_index values. --- fftools/ffmpeg.c | 23 +++++++++-------------- fftools/ffmpeg.h | 1 - fftools/ffmpeg_opt.c | 33 ++++++++++++--------------------- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 62ff1a98df..0a1dc5bb3b 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1566,9 +1566,7 @@ static void print_final_stats(int64_t total_size) static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time) { AVBPrint buf, buf_script; - OutputStream *ost; int64_t total_size = of_filesize(output_files[0]); - AVCodecContext *enc; int vid, i; double bitrate; double speed; @@ -1600,11 +1598,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); for (i = 0; i < nb_output_streams; i++) { - float q = -1; - ost = output_streams[i]; - enc = ost->enc_ctx; - if (!ost->stream_copy) - q = ost->quality / (float) FF_QP2LAMBDA; + const OutputStream * const ost = output_streams[i]; + const AVCodecContext * const enc = ost->enc_ctx; + const float q = enc ? ost->quality / (float) FF_QP2LAMBDA : -1; if (vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); @@ -3258,7 +3254,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, // copy estimated duration as a hint to the muxer if (ost->st->duration <= 0 && ist && ist->st->duration > 0) ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - } else if (ost->stream_copy) { + } else if (ost->source_index >= 0) { ret = init_output_stream_streamcopy(ost); if (ret < 0) return ret; @@ -3343,7 +3339,7 @@ static int transcode_init(void) * known after the encoder is initialized. */ for (i = 0; i < nb_output_streams; i++) { - if (!output_streams[i]->stream_copy && + if (output_streams[i]->enc_ctx && (output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) continue; @@ -3417,9 +3413,7 @@ static int transcode_init(void) av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); - if (ost->stream_copy) - av_log(NULL, AV_LOG_INFO, " (copy)"); - else { + if (ost->enc_ctx) { const AVCodec *in_codec = input_streams[ost->source_index]->dec; const AVCodec *out_codec = ost->enc; const char *decoder_name = "?"; @@ -3449,7 +3443,8 @@ static int transcode_init(void) av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))", in_codec_name, decoder_name, out_codec_name, encoder_name); - } + } else + av_log(NULL, AV_LOG_INFO, " (copy)"); av_log(NULL, AV_LOG_INFO, "\n"); } @@ -3959,7 +3954,7 @@ static int process_input(int file_index) OutputStream *ost = output_streams[j]; if (ost->source_index == ifile->ist_index + i && - (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) { + (!ost->enc_ctx || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) { OutputFile *of = output_files[ost->file_index]; output_packet(of, ost->pkt, ost, 1); } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6417db03bd..713de42e2b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -540,7 +540,6 @@ typedef struct OutputStream { char *apad; OSTFinished finished; /* no more packets should be written for this stream */ int unavailable; /* true if the steram is unavailable (possibly temporarily) */ - int stream_copy; // init_output_stream() has been called for this stream // The encoder and the bitstream filters have been initialized and the stream diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 12cde4b617..784209e770 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1555,16 +1555,13 @@ static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *o avcodec_get_name(ost->st->codecpar->codec_id)); return AVERROR_ENCODER_NOT_FOUND; } - } else if (!strcmp(codec_name, "copy")) - ost->stream_copy = 1; - else { + } else if (strcmp(codec_name, "copy")) { ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1); ost->st->codecpar->codec_id = ost->enc->id; } - ost->encoding_needed = !ost->stream_copy; + ost->encoding_needed = !!ost->enc; } else { /* no encoding supported for other media types */ - ost->stream_copy = 1; ost->encoding_needed = 0; } @@ -1898,7 +1895,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); - if (!ost->stream_copy) { + if (ost->enc_ctx) { AVCodecContext *video_enc = ost->enc_ctx; const char *p = NULL; char *frame_size = NULL; @@ -2087,9 +2084,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->last_frame = av_frame_alloc(); if (!ost->last_frame) exit_program(1); - } - - if (ost->stream_copy) + } else check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO); return ost; @@ -2107,7 +2102,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); - if (!ost->stream_copy) { + if (ost->enc_ctx) { AVCodecContext *audio_enc = ost->enc_ctx; int channels = 0; char *layout = NULL; @@ -2186,9 +2181,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in } } #endif - } - - if (ost->stream_copy) + } else check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO); return ost; @@ -2199,7 +2192,7 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int OutputStream *ost; ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index); - if (!ost->stream_copy) { + if (ost->enc_ctx) { av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n"); exit_program(1); } @@ -2212,7 +2205,7 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, OutputStream *ost; ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index); - if (!ost->stream_copy) { + if (ost->enc_ctx) { av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n"); exit_program(1); } @@ -2223,7 +2216,6 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index) { OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index); - ost->stream_copy = 1; ost->finished = 1; return ost; } @@ -2236,7 +2228,7 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index); st = ost->st; - if (!ost->stream_copy) { + if (ost->enc_ctx) { AVCodecContext *subtitle_enc = ost->enc_ctx; char *frame_size = NULL; @@ -2401,7 +2393,7 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, ofilter->ost = ost; ofilter->format = -1; - if (ost->stream_copy) { + if (!ost->enc_ctx) { av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, " "which is fed from a complex filtergraph. Filtering and streamcopy " "cannot be used together.\n", ost->file_index, ost->index); @@ -2768,7 +2760,6 @@ static void of_add_attachments(AVFormatContext *oc, OptionsContext *o) memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); ost = new_attachment_stream(o, oc, -1); - ost->stream_copy = 0; ost->attachment_filename = o->attachments[i]; ost->st->codecpar->extradata = attachment; ost->st->codecpar->extradata_size = len; @@ -3068,7 +3059,7 @@ static int open_output_file(OptionsContext *o, const char *filename) exit_program(1); } } - } else if (ost->stream_copy && ost->source_index >= 0) { + } else if (ost->source_index >= 0) { InputStream *ist = input_streams[ost->source_index]; ist->processing_needed = 1; } @@ -3193,7 +3184,7 @@ static int open_output_file(OptionsContext *o, const char *filename) continue; ist = input_streams[output_streams[i]->source_index]; av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); - if (!output_streams[i]->stream_copy) { + if (output_streams[i]->enc_ctx) { av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0); } }