From patchwork Thu Apr 13 14:11:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41147 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1286742pzb; Thu, 13 Apr 2023 07:16:18 -0700 (PDT) X-Google-Smtp-Source: AKy350YgbftyyeRHVRaVvrMJ+nHcsh1zg5jIgoY5zHWby0aT7OMzQTt9bL0fRbS43qvLYa6oIYsV X-Received: by 2002:a17:907:7892:b0:933:4c24:101b with SMTP id ku18-20020a170907789200b009334c24101bmr6280105ejc.7.1681395377932; Thu, 13 Apr 2023 07:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395377; cv=none; d=google.com; s=arc-20160816; b=oMWy/FWYbFb98ZLoFHxTvM1G5FTZIBm+m1cc5OHkvkHUnuaBDjGCbvH+iNBK3zuZdF jTEReH6upCkM4bySU+aUGHK+vvk1MW4Es9dKFndeR4lXzjlP/i1UkDzYHWT5EdmWjEgK p/872NgMNc/OLDZjApUN4PFdU1fKP88TR4BSAuZO/OVT3lDj4ZVOQgxTN/3G7bj9CO5Z fRSB1KzXqx3fySEA6dqzWTbggCfTrGNv9mxwQIB6XnfHJ/ctCr0yM+iMSWGoKLWmZz4P Exq6p84wzLP8I/UnaTbUBuimpGqsOd2Nr8qUQxDLHe504JDt6xyJjVYabGlELCHSrxK0 AMLQ== 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:message-id:date:to:from :delivered-to; bh=grwWd6N7Oc3CdKjPbfqNSx8KesSGf7MZhlPGmeRzziI=; b=iHI+zbIBvolOLwRrskO1vhoO/qf0Moipi2Cb/qiBeaFaAuvM6kbqpSQVRtMpMA1Hi6 H4P9OT9sI7E34eVu+0OYDR648gVUopWnfNqaDK8SUUWq5LrcZzTpvsoQn2H/RAwFOm1y 6rfssYnmAjoZNwCEjt7PfU7hytUJTobxFP+hsaa3XP7kuu4tgaxRHimcbHFQLGI+C9Nt OqUxLfQ07kMg/aRbItXKlhV5Q/e+RoeccGfQZcjSmtB940WhgBG0nM79WTi5bll8xP6I qSHSDxZgaPzbIhZECOPy62JbiUhh6atTeWeVBfJwN6edZl1hXR0sEDUQVyxxIFL7gzWZ UNAg== 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 kb17-20020a170907925100b0094a671c2297si1899688ejb.296.2023.04.13.07.16.17; Thu, 13 Apr 2023 07:16:17 -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 86DD468BE03; Thu, 13 Apr 2023 17:16:02 +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 73F6C680A2D for ; Thu, 13 Apr 2023 17:15:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3F6C2240D20 for ; Thu, 13 Apr 2023 16:15:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id aOML-fuiGW5C for ; Thu, 13 Apr 2023 16:15:53 +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 117272404EC for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C5D263A038E for ; Thu, 13 Apr 2023 16:15:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:11:59 +0200 Message-Id: <20230413141223.17245-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_mux_init: move new_output_stream() lower in the 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: BgyAII3DqBzq Reduces the diff in the following commit. Temporarily add a forward declaration for new_output_stream(), it will be removed in the next commit. --- fftools/ffmpeg_mux_init.c | 481 +++++++++++++++++++------------------- 1 file changed, 242 insertions(+), 239 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 62e5643a04..69c1532b9e 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -419,245 +419,7 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) } static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, - enum AVMediaType type, InputStream *ist) -{ - AVFormatContext *oc = mux->fc; - MuxStream *ms; - OutputStream *ost; - const AVCodec *enc; - AVStream *st = avformat_new_stream(oc, NULL); - int ret = 0; - const char *bsfs = NULL, *time_base = NULL; - char *next, *codec_tag = NULL; - double qscale = -1; - int i; - - if (!st) - report_and_exit(AVERROR(ENOMEM)); - - if (oc->nb_streams - 1 < o->nb_streamid_map) - st->id = o->streamid_map[oc->nb_streams - 1]; - - ms = mux_stream_alloc(mux, type); - ost = &ms->ost; - - ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0); - if (!ms->muxing_queue) - report_and_exit(AVERROR(ENOMEM)); - ms->last_mux_dts = AV_NOPTS_VALUE; - - ost->st = st; - ost->ist = ist; - ost->kf.ref_pts = AV_NOPTS_VALUE; - st->codecpar->codec_type = type; - - ret = choose_encoder(o, oc, ost, &enc); - if (ret < 0) { - av_log(ost, AV_LOG_FATAL, "Error selecting an encoder\n"); - exit_program(1); - } - - if (enc) { - ost->enc_ctx = avcodec_alloc_context3(enc); - if (!ost->enc_ctx) - report_and_exit(AVERROR(ENOMEM)); - - ret = enc_alloc(&ost->enc, enc); - if (ret < 0) - report_and_exit(ret); - - av_strlcat(ms->log_name, "/", sizeof(ms->log_name)); - av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name)); - } else { - av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name)); - } - - ost->filtered_frame = av_frame_alloc(); - if (!ost->filtered_frame) - report_and_exit(AVERROR(ENOMEM)); - - ost->pkt = av_packet_alloc(); - if (!ost->pkt) - report_and_exit(AVERROR(ENOMEM)); - - if (ost->enc_ctx) { - AVCodecContext *enc = ost->enc_ctx; - AVIOContext *s = NULL; - char *buf = NULL, *arg = NULL, *preset = NULL; - const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL; - - ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id, - oc, st, enc->codec); - - MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); - ost->autoscale = 1; - MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st); - if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) { - AVBPrint bprint; - av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); - do { - av_bprint_clear(&bprint); - buf = get_line(s, &bprint); - if (!buf[0] || buf[0] == '#') - continue; - if (!(arg = strchr(buf, '='))) { - av_log(ost, AV_LOG_FATAL, "Invalid line found in the preset file.\n"); - exit_program(1); - } - *arg++ = 0; - av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE); - } while (!s->eof_reached); - av_bprint_finalize(&bprint, NULL); - avio_closep(&s); - } - if (ret) { - av_log(ost, AV_LOG_FATAL, - "Preset %s specified, but could not be opened.\n", preset); - exit_program(1); - } - - MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st); - if (enc_stats_pre && - (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { - const char *format = "{fidx} {sidx} {n} {t}"; - - MATCH_PER_STREAM_OPT(enc_stats_pre_fmt, str, format, oc, st); - - ret = enc_stats_init(ost, &ost->enc_stats_pre, 1, enc_stats_pre, format); - if (ret < 0) - exit_program(1); - } - - MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st); - if (enc_stats_post && - (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { - const char *format = "{fidx} {sidx} {n} {t}"; - - MATCH_PER_STREAM_OPT(enc_stats_post_fmt, str, format, oc, st); - - ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format); - if (ret < 0) - exit_program(1); - } - - MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st); - if (mux_stats && - (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { - const char *format = "{fidx} {sidx} {n} {t}"; - - MATCH_PER_STREAM_OPT(mux_stats_fmt, str, format, oc, st); - - ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format); - if (ret < 0) - exit_program(1); - } - } else { - ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL); - } - - - if (o->bitexact) { - ost->bitexact = 1; - } else if (ost->enc_ctx) { - ost->bitexact = check_opt_bitexact(ost->enc_ctx, ost->encoder_opts, "flags", - AV_CODEC_FLAG_BITEXACT); - } - - MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st); - if (time_base) { - AVRational q; - if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 || - q.num <= 0 || q.den <= 0) { - av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base); - exit_program(1); - } - st->time_base = q; - } - - MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st); - if (time_base) { - AVRational q; - if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 || - q.den <= 0) { - av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base); - exit_program(1); - } - ost->enc_timebase = q; - } - - ms->max_frames = INT64_MAX; - MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st); - for (i = 0; inb_max_frames; i++) { - char *p = o->max_frames[i].specifier; - if (!*p && type != AVMEDIA_TYPE_VIDEO) { - av_log(ost, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n"); - break; - } - } - - ost->copy_prior_start = -1; - MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st); - - MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st); - if (bsfs && *bsfs) { - ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx); - if (ret < 0) { - av_log(ost, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret)); - exit_program(1); - } - } - - MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st); - if (codec_tag) { - uint32_t tag = strtol(codec_tag, &next, 0); - if (*next) - tag = AV_RL32(codec_tag); - ost->st->codecpar->codec_tag = tag; - if (ost->enc_ctx) - ost->enc_ctx->codec_tag = tag; - } - - MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st); - if (ost->enc_ctx && qscale >= 0) { - ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE; - ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; - } - - ms->max_muxing_queue_size = 128; - MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ms->max_muxing_queue_size, oc, st); - - ms->muxing_queue_data_threshold = 50*1024*1024; - MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ms->muxing_queue_data_threshold, oc, st); - - MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample, - oc, st); - - MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat, - oc, st); - - if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx) - ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - - av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0); - - av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0); - if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24) - av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); - - if (ost->ist) { - ost->ist->discard = 0; - ost->ist->st->discard = ost->ist->user_set_discard; - - if (!(ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))) - ist_output_add(ost->ist, ost); - } - ost->last_mux_dts = AV_NOPTS_VALUE; - - MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, - ost->copy_initial_nonkeyframes, oc, st); - - return ost; -} + enum AVMediaType type, InputStream *ist); static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost) @@ -1098,6 +860,247 @@ static OutputStream *new_subtitle_stream(Muxer *mux, const OptionsContext *o, In return ost; } +static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, + enum AVMediaType type, InputStream *ist) +{ + AVFormatContext *oc = mux->fc; + MuxStream *ms; + OutputStream *ost; + const AVCodec *enc; + AVStream *st = avformat_new_stream(oc, NULL); + int ret = 0; + const char *bsfs = NULL, *time_base = NULL; + char *next, *codec_tag = NULL; + double qscale = -1; + int i; + + if (!st) + report_and_exit(AVERROR(ENOMEM)); + + if (oc->nb_streams - 1 < o->nb_streamid_map) + st->id = o->streamid_map[oc->nb_streams - 1]; + + ms = mux_stream_alloc(mux, type); + ost = &ms->ost; + + ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0); + if (!ms->muxing_queue) + report_and_exit(AVERROR(ENOMEM)); + ms->last_mux_dts = AV_NOPTS_VALUE; + + ost->st = st; + ost->ist = ist; + ost->kf.ref_pts = AV_NOPTS_VALUE; + st->codecpar->codec_type = type; + + ret = choose_encoder(o, oc, ost, &enc); + if (ret < 0) { + av_log(ost, AV_LOG_FATAL, "Error selecting an encoder\n"); + exit_program(1); + } + + if (enc) { + ost->enc_ctx = avcodec_alloc_context3(enc); + if (!ost->enc_ctx) + report_and_exit(AVERROR(ENOMEM)); + + ret = enc_alloc(&ost->enc, enc); + if (ret < 0) + report_and_exit(ret); + + av_strlcat(ms->log_name, "/", sizeof(ms->log_name)); + av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name)); + } else { + av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name)); + } + + ost->filtered_frame = av_frame_alloc(); + if (!ost->filtered_frame) + report_and_exit(AVERROR(ENOMEM)); + + ost->pkt = av_packet_alloc(); + if (!ost->pkt) + report_and_exit(AVERROR(ENOMEM)); + + if (ost->enc_ctx) { + AVCodecContext *enc = ost->enc_ctx; + AVIOContext *s = NULL; + char *buf = NULL, *arg = NULL, *preset = NULL; + const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL; + + ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id, + oc, st, enc->codec); + + MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); + ost->autoscale = 1; + MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st); + if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) { + AVBPrint bprint; + av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); + do { + av_bprint_clear(&bprint); + buf = get_line(s, &bprint); + if (!buf[0] || buf[0] == '#') + continue; + if (!(arg = strchr(buf, '='))) { + av_log(ost, AV_LOG_FATAL, "Invalid line found in the preset file.\n"); + exit_program(1); + } + *arg++ = 0; + av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE); + } while (!s->eof_reached); + av_bprint_finalize(&bprint, NULL); + avio_closep(&s); + } + if (ret) { + av_log(ost, AV_LOG_FATAL, + "Preset %s specified, but could not be opened.\n", preset); + exit_program(1); + } + + MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st); + if (enc_stats_pre && + (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + const char *format = "{fidx} {sidx} {n} {t}"; + + MATCH_PER_STREAM_OPT(enc_stats_pre_fmt, str, format, oc, st); + + ret = enc_stats_init(ost, &ost->enc_stats_pre, 1, enc_stats_pre, format); + if (ret < 0) + exit_program(1); + } + + MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st); + if (enc_stats_post && + (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + const char *format = "{fidx} {sidx} {n} {t}"; + + MATCH_PER_STREAM_OPT(enc_stats_post_fmt, str, format, oc, st); + + ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format); + if (ret < 0) + exit_program(1); + } + + MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st); + if (mux_stats && + (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + const char *format = "{fidx} {sidx} {n} {t}"; + + MATCH_PER_STREAM_OPT(mux_stats_fmt, str, format, oc, st); + + ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format); + if (ret < 0) + exit_program(1); + } + } else { + ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL); + } + + + if (o->bitexact) { + ost->bitexact = 1; + } else if (ost->enc_ctx) { + ost->bitexact = check_opt_bitexact(ost->enc_ctx, ost->encoder_opts, "flags", + AV_CODEC_FLAG_BITEXACT); + } + + MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st); + if (time_base) { + AVRational q; + if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 || + q.num <= 0 || q.den <= 0) { + av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base); + exit_program(1); + } + st->time_base = q; + } + + MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st); + if (time_base) { + AVRational q; + if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 || + q.den <= 0) { + av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base); + exit_program(1); + } + ost->enc_timebase = q; + } + + ms->max_frames = INT64_MAX; + MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st); + for (i = 0; inb_max_frames; i++) { + char *p = o->max_frames[i].specifier; + if (!*p && type != AVMEDIA_TYPE_VIDEO) { + av_log(ost, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n"); + break; + } + } + + ost->copy_prior_start = -1; + MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st); + + MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st); + if (bsfs && *bsfs) { + ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx); + if (ret < 0) { + av_log(ost, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret)); + exit_program(1); + } + } + + MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st); + if (codec_tag) { + uint32_t tag = strtol(codec_tag, &next, 0); + if (*next) + tag = AV_RL32(codec_tag); + ost->st->codecpar->codec_tag = tag; + if (ost->enc_ctx) + ost->enc_ctx->codec_tag = tag; + } + + MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st); + if (ost->enc_ctx && qscale >= 0) { + ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE; + ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; + } + + ms->max_muxing_queue_size = 128; + MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ms->max_muxing_queue_size, oc, st); + + ms->muxing_queue_data_threshold = 50*1024*1024; + MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ms->muxing_queue_data_threshold, oc, st); + + MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample, + oc, st); + + MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat, + oc, st); + + if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx) + ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + + av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0); + + av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0); + if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24) + av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); + + if (ost->ist) { + ost->ist->discard = 0; + ost->ist->st->discard = ost->ist->user_set_discard; + + if (!(ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))) + ist_output_add(ost->ist, ost); + } + ost->last_mux_dts = AV_NOPTS_VALUE; + + MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, + ost->copy_initial_nonkeyframes, oc, st); + + return ost; +} + static void init_output_filter(OutputFilter *ofilter, const OptionsContext *o, Muxer *mux) { From patchwork Thu Apr 13 14:12:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41146 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1286542pzb; Thu, 13 Apr 2023 07:16:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YIcb/+6WSwfu4/pvUdIMp1+BQhDpfEg4EOTqq2ktLH5PLTmausG1g322ZogMIR6eG39PhJ X-Received: by 2002:a50:ee0f:0:b0:506:7c83:87e7 with SMTP id g15-20020a50ee0f000000b005067c8387e7mr198368eds.41.1681395365069; Thu, 13 Apr 2023 07:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395365; cv=none; d=google.com; s=arc-20160816; b=ln+5uxlp6eYdCz5hUU2fokzneLEoY57TTNPyvdlGdPWBy9Ncgj986lAv271ei6WS9N ZoDq0wEJEGyNwc76/iQ5UgMMyT91erR/ER1mmcM+b5StUjOp+TlaCCTfIiXRU4TXXMC8 WxNs0vOkFKGJvKrIYoVZifLzBKL49XW8S5zYlN0eMk8sytFIl7cS2E8EyDBe0L93W7wK Td/SyhwdmDxjR6fH+n3FMx/Dmub9wZxb+kgOAaU9DamxlU+z+CBLR6l/Tbixbxe0Ve9Q d16e/bPvX/zLv0uVq45P/eLfDdP2PeZjS+fhJhs8khf6vl10U+7GQ3s1uVAKtN8k0qGX g1+A== 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=svECdxk71BsiCUPn/LJxxn+9a3Wkg9A2T7XCtpNIn+M=; b=emWzErPghbGA3jetWEKLcwpUDomIcOewXAbePHdVRhyv02SiAY3XfdxioJWaiVqiWV fh9SsvToR7tcZ09YUoZI0j9jIZbdBenal1b8yGfBkWKo+tnttb0BIV61ju01n/2y82x3 s0eC+hzciqj6uONfZ/hnC70a9c7BduefZqF4zrF9TwBA2QL62+goJpCEZv0zk0xVaTK8 /qU9VrbB297Oo/o9qOxrURsV5Vhws3LRZeM7z1jY5h925YeeVM8ABoxMP2cZuxSlmqyo I1XJ+KrYBIMyDiRmCf1XwxEr1XO0l40Ak5yq5NW1JA5uOyrGIfLFUcAdp1JYBUBuhUBP xy0A== 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 gj32-20020a170907742000b0092bb8b36552si1901436ejc.615.2023.04.13.07.16.04; Thu, 13 Apr 2023 07:16:05 -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 7B8F868B9FC; Thu, 13 Apr 2023 17:16:01 +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 1C68068B6D3 for ; Thu, 13 Apr 2023 17:15:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DC668240D1D for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id YrclR2TFbb7C for ; Thu, 13 Apr 2023 16:15:53 +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 21A6C2404EE for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D35E53A039B for ; Thu, 13 Apr 2023 16:15:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:00 +0200 Message-Id: <20230413141223.17245-2-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_mux_init: restructure output stream creation 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: UWC+pwj+6gST Creating a new output stream of a given type is currently done by calling new__stream(), which all start by calling new_output_stream() to allocate the stream and do common init, followed by type-specific init. Reverse this structure - the caller now calls the common function ost_add() with the type as a parameter, which then calls the type-specific function internally. This will allow adding common code that runs after type-specific code in future commits. --- fftools/ffmpeg_mux_init.c | 89 +++++++++++++++------------------------ 1 file changed, 35 insertions(+), 54 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 69c1532b9e..714315cfd0 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -418,9 +418,6 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) return ms; } -static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, - enum AVMediaType type, InputStream *ist); - static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost) { @@ -471,14 +468,13 @@ static void parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str) } } -static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) +static void new_stream_video(Muxer *mux, const OptionsContext *o, + OutputStream *ost) { AVFormatContext *oc = mux->fc; AVStream *st; - OutputStream *ost; char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_VIDEO, ist); st = ost->st; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); @@ -703,17 +699,14 @@ static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, Input exit_program(1); } else check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO); - - return ost; } -static OutputStream *new_audio_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) +static void new_stream_audio(Muxer *mux, const OptionsContext *o, + OutputStream *ost) { AVFormatContext *oc = mux->fc; AVStream *st; - OutputStream *ost; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_AUDIO, ist); st = ost->st; @@ -801,49 +794,37 @@ static OutputStream *new_audio_stream(Muxer *mux, const OptionsContext *o, Input #endif } else check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO); - - return ost; } -static OutputStream *new_data_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) +static void new_stream_data(Muxer *mux, const OptionsContext *o, + OutputStream *ost) { - OutputStream *ost; - - ost = new_output_stream(mux, o, AVMEDIA_TYPE_DATA, ist); if (ost->enc_ctx) { av_log(ost, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n"); exit_program(1); } - - return ost; } -static OutputStream *new_unknown_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) +static void new_stream_unknown(Muxer *mux, const OptionsContext *o, + OutputStream *ost) { - OutputStream *ost; - - ost = new_output_stream(mux, o, AVMEDIA_TYPE_UNKNOWN, ist); if (ost->enc_ctx) { av_log(ost, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n"); exit_program(1); } - - return ost; } -static OutputStream *new_attachment_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) +static void new_stream_attachment(Muxer *mux, const OptionsContext *o, + OutputStream *ost) { - OutputStream *ost = new_output_stream(mux, o, AVMEDIA_TYPE_ATTACHMENT, ist); ost->finished = 1; - return ost; } -static OutputStream *new_subtitle_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) +static void new_stream_subtitle(Muxer *mux, const OptionsContext *o, + OutputStream *ost) { AVStream *st; - OutputStream *ost; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_SUBTITLE, ist); st = ost->st; if (ost->enc_ctx) { @@ -856,12 +837,10 @@ static OutputStream *new_subtitle_stream(Muxer *mux, const OptionsContext *o, In exit_program(1); } } - - return ost; } -static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, - enum AVMediaType type, InputStream *ist) +static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, + enum AVMediaType type, InputStream *ist) { AVFormatContext *oc = mux->fc; MuxStream *ms; @@ -1098,6 +1077,15 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st); + switch (type) { + case AVMEDIA_TYPE_VIDEO: new_stream_video (mux, o, ost); break; + case AVMEDIA_TYPE_AUDIO: new_stream_audio (mux, o, ost); break; + case AVMEDIA_TYPE_SUBTITLE: new_stream_subtitle (mux, o, ost); break; + case AVMEDIA_TYPE_DATA: new_stream_data (mux, o, ost); break; + case AVMEDIA_TYPE_ATTACHMENT: new_stream_attachment(mux, o, ost); break; + default: new_stream_unknown (mux, o, ost); break; + } + return ost; } @@ -1107,8 +1095,8 @@ static void init_output_filter(OutputFilter *ofilter, const OptionsContext *o, OutputStream *ost; switch (ofilter->type) { - case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(mux, o, NULL); break; - case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(mux, o, NULL); break; + case AVMEDIA_TYPE_VIDEO: ost = ost_add(mux, o, AVMEDIA_TYPE_VIDEO, NULL); break; + case AVMEDIA_TYPE_AUDIO: ost = ost_add(mux, o, AVMEDIA_TYPE_AUDIO, NULL); break; default: av_log(mux, AV_LOG_FATAL, "Only video and audio filters are supported " "currently.\n"); @@ -1190,7 +1178,7 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o) } } if (best_ist) - new_video_stream(mux, o, best_ist); + ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist); } static void map_auto_audio(Muxer *mux, const OptionsContext *o) @@ -1232,7 +1220,7 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o) } } if (best_ist) - new_audio_stream(mux, o, best_ist); + ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist); } static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) @@ -1267,7 +1255,7 @@ static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) input_descriptor && output_descriptor && (!input_descriptor->props || !output_descriptor->props)) { - new_subtitle_stream(mux, o, ist); + ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist); break; } } @@ -1287,7 +1275,7 @@ static void map_auto_data(Muxer *mux, const OptionsContext *o) continue; if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA && ist->st->codecpar->codec_id == codec_id ) - new_data_stream(mux, o, ist); + ost_add(mux, o, AVMEDIA_TYPE_DATA, ist); } } @@ -1336,18 +1324,8 @@ loop_end: if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA) return; - switch (ist->st->codecpar->codec_type) { - case AVMEDIA_TYPE_VIDEO: new_video_stream (mux, o, ist); break; - case AVMEDIA_TYPE_AUDIO: new_audio_stream (mux, o, ist); break; - case AVMEDIA_TYPE_SUBTITLE: new_subtitle_stream (mux, o, ist); break; - case AVMEDIA_TYPE_DATA: new_data_stream (mux, o, ist); break; - case AVMEDIA_TYPE_ATTACHMENT: new_attachment_stream(mux, o, ist); break; - case AVMEDIA_TYPE_UNKNOWN: - if (copy_unknown_streams) { - new_unknown_stream (mux, o, ist); - break; - } - default: + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN && + !copy_unknown_streams) { av_log(mux, ignore_unknown_streams ? AV_LOG_WARNING : AV_LOG_FATAL, "Cannot map stream #%d:%d - unsupported type.\n", map->file_index, map->stream_index); @@ -1358,7 +1336,10 @@ loop_end: "If you want them copied, please use -copy_unknown\n"); exit_program(1); } + return; } + + ost_add(mux, o, ist->st->codecpar->codec_type, ist); } } @@ -1392,7 +1373,7 @@ static void of_add_attachments(Muxer *mux, const OptionsContext *o) avio_read(pb, attachment, len); memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); - ost = new_attachment_stream(mux, o, NULL); + ost = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL); ost->attachment_filename = o->attachments[i]; ost->st->codecpar->extradata = attachment; ost->st->codecpar->extradata_size = len; From patchwork Thu Apr 13 14:12:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41156 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1288633pzb; Thu, 13 Apr 2023 07:18:19 -0700 (PDT) X-Google-Smtp-Source: AKy350b55DrIlKSZyko76Kzi+6sDNixe7CrmfG+rK+g2FIY0sCiq9HvuDKVo/Az/KToZCvBK1Jix X-Received: by 2002:a17:906:e25a:b0:94a:96c4:2361 with SMTP id gq26-20020a170906e25a00b0094a96c42361mr2700777ejb.73.1681395498723; Thu, 13 Apr 2023 07:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395498; cv=none; d=google.com; s=arc-20160816; b=EARYsusRfBdHzQrQxww/n7knKigoirEazOWLF6WKGOAoe02z8Erwof6AZYyMUNllP9 Ys93dCouFrlhsVIliNJRMSxBwLHLc9vZO1Abv88HB1gTgB+mBMOK1dOxGv3MkBWYvmw6 HpbOBmq+v4uj7/LfxZOiIZ8aJ662/qPaEm5fMrxCpEmhNhcXp1W8UF1bK6qpSETyWKI8 ZqXu9E5m3oSRkKWPBPbMkIZ7KqfgdDW5HUibH0PPz0ZPWT6kXM+KInb7otVodtzBthXq dBqWqjLf7WRfs3WfV4wYkh9g80ZJtvFu1Sh9pCZqOnj97hsVAd2vwf7ueAKf0uRfokp2 BKyA== 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=qlv4DLwGVrdV0+cGy1BQYQJFfEs7ubu1XLgTQ2YkNWk=; b=drQnS+CXoV9K0oZBSPw1zsqjlw62qGOnzczbSuWWRCh7BKqLM4WJOMJ9ulurtqKmA8 ENCTGfgiNNtT7i4QcWak9RL8RopTD/u/hIQKYpq+Ma8Vahl+aSjd9ZsV6hIqyh7rEBup rtQ/5dHq5RC9mIfGV6hknVIOVMFB8Yq45FDMmcEqT5M6FdIBKWx3KHHxPEMOv6RJE6hj kJFCIQtbEIqnCsOm4ZGnzWKoYgYbp3FJqOuD4K5fPzp7+d01wgGx4rsRK+pky7OxwOBJ kZxUFmYEYWXYv4ucqvkKJLkU7HFJQtBxVJmipSkzpBZCJE8esq72vDLtQikCrrCxAt/q t0sw== 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 fu37-20020a170907b02500b0094c67d4acdcsi1839773ejc.372.2023.04.13.07.18.18; Thu, 13 Apr 2023 07:18:18 -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 D9E0468BE48; Thu, 13 Apr 2023 17:16:10 +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 5DDAA68BE3D for ; Thu, 13 Apr 2023 17:15:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 03D7F2405EC for ; Thu, 13 Apr 2023 16:15:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id i0XmGzMya9VH for ; Thu, 13 Apr 2023 16:15:53 +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 229A52404F5 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DECB53A03E5 for ; Thu, 13 Apr 2023 16:15:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:01 +0200 Message-Id: <20230413141223.17245-3-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/25] fftools/ffmpeg: move init_output_stream_streamcopy() to ffmpeg_mux_init 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: wrv/7kNOUTm0 Everything in it can be done immediately when creating the output stream, there is no reason to postpone it. --- fftools/ffmpeg.c | 136 ------------------------------------ fftools/ffmpeg_mux_init.c | 143 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 136 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 6e44542776..c1070485be 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1985,136 +1985,6 @@ static int init_input_stream(InputStream *ist, char *error, int error_len) return 0; } -static int init_output_stream_streamcopy(OutputStream *ost) -{ - OutputFile *of = output_files[ost->file_index]; - InputStream *ist = ost->ist; - InputFile *ifile = input_files[ist->file_index]; - AVCodecParameters *par = ost->st->codecpar; - AVCodecContext *codec_ctx; - AVRational sar; - int i, ret; - uint32_t codec_tag = par->codec_tag; - - av_assert0(ist && !ost->filter); - - codec_ctx = avcodec_alloc_context3(NULL); - if (!codec_ctx) - return AVERROR(ENOMEM); - - ret = avcodec_parameters_to_context(codec_ctx, ist->par); - if (ret >= 0) - ret = av_opt_set_dict(codec_ctx, &ost->encoder_opts); - if (ret < 0) { - av_log(ost, AV_LOG_FATAL, - "Error setting up codec context options.\n"); - avcodec_free_context(&codec_ctx); - return ret; - } - - ret = avcodec_parameters_from_context(par, codec_ctx); - avcodec_free_context(&codec_ctx); - if (ret < 0) { - av_log(ost, AV_LOG_FATAL, - "Error getting reference codec parameters.\n"); - return ret; - } - - if (!codec_tag) { - unsigned int codec_tag_tmp; - if (!of->format->codec_tag || - av_codec_get_id (of->format->codec_tag, par->codec_tag) == par->codec_id || - !av_codec_get_tag2(of->format->codec_tag, par->codec_id, &codec_tag_tmp)) - codec_tag = par->codec_tag; - } - - par->codec_tag = codec_tag; - - if (!ost->frame_rate.num) - ost->frame_rate = ist->framerate; - - if (ost->frame_rate.num) - ost->st->avg_frame_rate = ost->frame_rate; - else - ost->st->avg_frame_rate = ist->st->avg_frame_rate; - - ret = avformat_transfer_internal_stream_timing_info(of->format, ost->st, ist->st, copy_tb); - if (ret < 0) - return ret; - - // copy timebase while removing common factors - if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) { - if (ost->frame_rate.num) - ost->st->time_base = av_inv_q(ost->frame_rate); - else - ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); - } - - // copy estimated duration as a hint to the muxer - if (ost->st->duration <= 0 && ist->st->duration > 0) - ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - - if (!ost->copy_prior_start) { - ost->ts_copy_start = (of->start_time == AV_NOPTS_VALUE) ? - 0 : of->start_time; - if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) { - ost->ts_copy_start = FFMAX(ost->ts_copy_start, - ifile->start_time + ifile->ts_offset); - } - } - - if (ist->st->nb_side_data) { - for (i = 0; i < ist->st->nb_side_data; i++) { - const AVPacketSideData *sd_src = &ist->st->side_data[i]; - uint8_t *dst_data; - - dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size); - if (!dst_data) - return AVERROR(ENOMEM); - memcpy(dst_data, sd_src->data, sd_src->size); - } - } - -#if FFMPEG_ROTATION_METADATA - if (ost->rotate_overridden) { - uint8_t *sd = av_stream_new_side_data(ost->st, AV_PKT_DATA_DISPLAYMATRIX, - sizeof(int32_t) * 9); - if (sd) - av_display_rotation_set((int32_t *)sd, -ost->rotate_override_value); - } -#endif - - switch (par->codec_type) { - case AVMEDIA_TYPE_AUDIO: - if ((par->block_align == 1 || par->block_align == 1152 || par->block_align == 576) && - par->codec_id == AV_CODEC_ID_MP3) - par->block_align = 0; - if (par->codec_id == AV_CODEC_ID_AC3) - par->block_align = 0; - break; - case AVMEDIA_TYPE_VIDEO: - if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option - sar = - av_mul_q(ost->frame_aspect_ratio, - (AVRational){ par->height, par->width }); - av_log(ost, AV_LOG_WARNING, "Overriding aspect ratio " - "with stream copy may produce invalid files\n"); - } - else if (ist->st->sample_aspect_ratio.num) - sar = ist->st->sample_aspect_ratio; - else - sar = par->sample_aspect_ratio; - ost->st->sample_aspect_ratio = par->sample_aspect_ratio = sar; - ost->st->avg_frame_rate = ist->st->avg_frame_rate; - ost->st->r_frame_rate = ist->st->r_frame_rate; - break; - } - - ost->mux_timebase = ist->st->time_base; - - return 0; -} - static int init_output_stream_nofilter(OutputStream *ost) { int ret = 0; @@ -2124,12 +1994,6 @@ static int init_output_stream_nofilter(OutputStream *ost) if (ret < 0) return ret; } else { - if (ost->ist) { - ret = init_output_stream_streamcopy(ost); - if (ret < 0) - return ret; - } - ret = of_stream_init(output_files[ost->file_index], ost); if (ret < 0) return ret; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 714315cfd0..06a6b3fd2d 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -37,6 +37,7 @@ #include "libavutil/avutil.h" #include "libavutil/bprint.h" #include "libavutil/dict.h" +#include "libavutil/display.h" #include "libavutil/getenv_utf8.h" #include "libavutil/intreadwrite.h" #include "libavutil/log.h" @@ -839,6 +840,142 @@ static void new_stream_subtitle(Muxer *mux, const OptionsContext *o, } } +static int streamcopy_init(const Muxer *mux, const OptionsContext *o, + OutputStream *ost) +{ + const InputStream *ist = ost->ist; + const InputFile *ifile = input_files[ist->file_index]; + + AVCodecParameters *par = ost->st->codecpar; + uint32_t codec_tag = par->codec_tag; + + AVCodecContext *codec_ctx = NULL; + AVDictionary *codec_opts = NULL; + int ret = 0; + + codec_ctx = avcodec_alloc_context3(NULL); + if (!codec_ctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(codec_ctx, ist->par); + if (ret >= 0) + ret = av_opt_set_dict(codec_ctx, &ost->encoder_opts); + if (ret < 0) { + av_log(ost, AV_LOG_FATAL, + "Error setting up codec context options.\n"); + goto fail; + } + + ret = avcodec_parameters_from_context(par, codec_ctx); + if (ret < 0) { + av_log(ost, AV_LOG_FATAL, + "Error getting reference codec parameters.\n"); + goto fail; + } + + if (!codec_tag) { + const struct AVCodecTag * const *ct = mux->fc->oformat->codec_tag; + unsigned int codec_tag_tmp; + if (!ct || av_codec_get_id (ct, par->codec_tag) == par->codec_id || + !av_codec_get_tag2(ct, par->codec_id, &codec_tag_tmp)) + codec_tag = par->codec_tag; + } + + par->codec_tag = codec_tag; + + if (!ost->frame_rate.num) + ost->frame_rate = ist->framerate; + + if (ost->frame_rate.num) + ost->st->avg_frame_rate = ost->frame_rate; + else + ost->st->avg_frame_rate = ist->st->avg_frame_rate; + + ret = avformat_transfer_internal_stream_timing_info(mux->fc->oformat, + ost->st, ist->st, copy_tb); + if (ret < 0) + goto fail; + + // copy timebase while removing common factors + if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) { + if (ost->frame_rate.num) + ost->st->time_base = av_inv_q(ost->frame_rate); + else + ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); + } + + // copy estimated duration as a hint to the muxer + if (ost->st->duration <= 0 && ist->st->duration > 0) + ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); + + if (!ost->copy_prior_start) { + ost->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ? + 0 : mux->of.start_time; + if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) { + ost->ts_copy_start = FFMAX(ost->ts_copy_start, + ifile->start_time + ifile->ts_offset); + } + } + + if (ist->st->nb_side_data) { + for (int i = 0; i < ist->st->nb_side_data; i++) { + const AVPacketSideData *sd_src = &ist->st->side_data[i]; + uint8_t *dst_data; + + dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size); + if (!dst_data) { + ret = AVERROR(ENOMEM); + goto fail; + } + memcpy(dst_data, sd_src->data, sd_src->size); + } + } + +#if FFMPEG_ROTATION_METADATA + if (ost->rotate_overridden) { + uint8_t *sd = av_stream_new_side_data(ost->st, AV_PKT_DATA_DISPLAYMATRIX, + sizeof(int32_t) * 9); + if (sd) + av_display_rotation_set((int32_t *)sd, -ost->rotate_override_value); + } +#endif + + switch (par->codec_type) { + case AVMEDIA_TYPE_AUDIO: + if ((par->block_align == 1 || par->block_align == 1152 || par->block_align == 576) && + par->codec_id == AV_CODEC_ID_MP3) + par->block_align = 0; + if (par->codec_id == AV_CODEC_ID_AC3) + par->block_align = 0; + break; + case AVMEDIA_TYPE_VIDEO: { + AVRational sar; + if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option + sar = + av_mul_q(ost->frame_aspect_ratio, + (AVRational){ par->height, par->width }); + av_log(ost, AV_LOG_WARNING, "Overriding aspect ratio " + "with stream copy may produce invalid files\n"); + } + else if (ist->st->sample_aspect_ratio.num) + sar = ist->st->sample_aspect_ratio; + else + sar = par->sample_aspect_ratio; + ost->st->sample_aspect_ratio = par->sample_aspect_ratio = sar; + ost->st->avg_frame_rate = ist->st->avg_frame_rate; + ost->st->r_frame_rate = ist->st->r_frame_rate; + break; + } + } + + ost->mux_timebase = ist->st->time_base; + +fail: + avcodec_free_context(&codec_ctx); + av_dict_free(&codec_opts); + return ret; +} + static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, InputStream *ist) { @@ -1086,6 +1223,12 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, default: new_stream_unknown (mux, o, ost); break; } + if (ost->ist && !ost->enc) { + ret = streamcopy_init(mux, o, ost); + if (ret < 0) + exit_program(1); + } + return ost; } From patchwork Thu Apr 13 14:12:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41150 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1287485pzb; Thu, 13 Apr 2023 07:16:59 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/ZADG5CpAr9u7s8OQeQdymCaL6mC+hFBcZr01mOxexDBW5oxrWD4gSXwKD4SEb3562wZQ X-Received: by 2002:a17:906:1857:b0:94a:4e86:31bc with SMTP id w23-20020a170906185700b0094a4e8631bcmr6743620eje.13.1681395419575; Thu, 13 Apr 2023 07:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395419; cv=none; d=google.com; s=arc-20160816; b=tZYNblO5fES+4hhSv1avALJ6gOkZqrLVXN+N7pL+YhJ3+0DEWXyDbGNayY95+d5M2B ZjH01xB16neSNhaparVJYx74mKHQXxLVMDicw5XnWNjxi30/rg+nTAAI+papGA+bNS5u pxD8ntEr2GkfuuyhdcomqVS9heNTfmIf0RciOEmP026cmW4UDJuV18M1JsBiOTnifQ4r yqDijDpX6fzxrFyTVTZf55NASQf/hYkj02wUS2GwCya7Grce3gskadSaFEJ7PWvo4AiI 1ZFty9xh+10/6+VK9YdqJKKtOUo9EgO5XB9oRKiPxJYWh0428t9FrOFqdPgqMWeybarV 04Qw== 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=bLFpyrzbNZncJwkty04IFUNvagFTsjApH5ElwZHy5iE=; b=ZCoUh5jifZ/EljmcJ1gcIJOO5wQa2Yg+cJLIi38GiOMZmLW5hzhhGMKkNU3Zi4nude eX1JQ0g5czAYo8Xu46MXgJ5cB2I/xTo51eut6LisxlLySgLQ249d2AQz0DbuvwdrKK1t +EOQPlYqElEgQi5g1gPeVr5cXMj2bXNMicLozf2e0AfjkGloaGPN66HTK3SFsBBAlhJa 5RPPche5FXBX0L8DZZe3nax66RlRPp0qF8XlYRjsDMtFybIwDO1wVhxDg+XRlc80pNTh r4l7WJgUquQaJOtsz3Gn9GyOXAzF67qZCufvQDO0eW2fNI9ciSVupF6bUgF3X/BBqfz3 rpAw== 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 ff18-20020a1709069c1200b009492273178esi1790293ejc.220.2023.04.13.07.16.59; Thu, 13 Apr 2023 07:16:59 -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 67CE068BE68; Thu, 13 Apr 2023 17:16:05 +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 33D8B68BDA5 for ; Thu, 13 Apr 2023 17:15:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E4FDB240591 for ; Thu, 13 Apr 2023 16:15:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 7VIPpzlljQmA for ; Thu, 13 Apr 2023 16:15:55 +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 3BD1D2405B5 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id EAAB93A0404 for ; Thu, 13 Apr 2023 16:15:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:02 +0200 Message-Id: <20230413141223.17245-4-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/25] fftools/ffmpeg_mux_init: remove a redundant check 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: agxi3crDOa7W --- fftools/ffmpeg_mux_init.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 06a6b3fd2d..e3d66b9897 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -917,18 +917,16 @@ static int streamcopy_init(const Muxer *mux, const OptionsContext *o, } } - if (ist->st->nb_side_data) { - for (int i = 0; i < ist->st->nb_side_data; i++) { - const AVPacketSideData *sd_src = &ist->st->side_data[i]; - uint8_t *dst_data; - - dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size); - if (!dst_data) { - ret = AVERROR(ENOMEM); - goto fail; - } - memcpy(dst_data, sd_src->data, sd_src->size); + for (int i = 0; i < ist->st->nb_side_data; i++) { + const AVPacketSideData *sd_src = &ist->st->side_data[i]; + uint8_t *dst_data; + + dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size); + if (!dst_data) { + ret = AVERROR(ENOMEM); + goto fail; } + memcpy(dst_data, sd_src->data, sd_src->size); } #if FFMPEG_ROTATION_METADATA From patchwork Thu Apr 13 14:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41162 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1289252pzb; Thu, 13 Apr 2023 07:19:01 -0700 (PDT) X-Google-Smtp-Source: AKy350bl/BaXF8KHvbZA3LOX6NA1HuBmsu02Fpv98gzM/YjMif7dN+oSqnbT1lZpsTeENsZkkPj9 X-Received: by 2002:a17:906:a3c2:b0:94a:8f3a:1a65 with SMTP id ca2-20020a170906a3c200b0094a8f3a1a65mr2752464ejb.5.1681395541188; Thu, 13 Apr 2023 07:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395541; cv=none; d=google.com; s=arc-20160816; b=nCdLhceqdZBB0ZLZitpmeZk03ddVik0esBlQtNbT2wMaaNXSj6MDeounIq8kVMHahg 9m4gCa5WLRC8L9ZqqdqagaJmx6jWctZIQuN2jnw4zlprhkwDhZzZVuvNWy++jGv9bJLS Qc3L/aEHnndAP40DYJpc+dc275uCcE1VGVzQ4UKEiQ+jguzqpwqthmKJ6a1KKS0+BBrO OPsgjRvoQUgTLG+RwSDsqdhnH+0AWEhyQ2BgizgNDD7Vlnf0rx3+kJA5n2DaFFoYSQ9K SAiiGJvoAphCLnIFlBVHH5KdvGVKh3Pv5Cdx2qN4dDM6gK1gPA5QXlqgkZYti+9Kx+Yn xMyg== 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=m45PUsUssGeKRg5gUNnpkhXWBejGpb7afUhEXVzIPiY=; b=jgQw8xk0t2hsM+SITMUAQwWfMd0s2FKb6JiQH/g+0cA3+2UeqZIJDgOT0LOyD+3SgG bNMho7yIri/7+nti5d9hjWiIX2d5wMvLAcsP9GvhH3eEHCOWQ/DZpT5+djSURRV2QpXI imiQRTl5Vuun9RIlouMZ8EwZjMnxVOL3fPy8/mo0E0ijxwK9cZEpSff9AsJV/+R2WmWn kGLmDtcl2bN6Spx9Q5KbxNLZdeeBxQWj0KMaYxgzr++bu+wThLsyG5qTEfhuOzAxgvwr +0PA57O8BHOm4wH1UcsonSbGR1pL/49YzPmnPFkT59hon+37sqB0hLHMEWGnRsYE8269 yyeQ== 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 p14-20020a170907910e00b00934d983a240si1870918ejq.280.2023.04.13.07.19.00; Thu, 13 Apr 2023 07:19:01 -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 DF38268BEAD; Thu, 13 Apr 2023 17:16:13 +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 B68A968BE48 for ; Thu, 13 Apr 2023 17:15:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E49DE2406CB for ; Thu, 13 Apr 2023 16:15:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id t-tLnPLwarvx for ; Thu, 13 Apr 2023 16:15:56 +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 437BD2405F9 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0240C3A042D for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:03 +0200 Message-Id: <20230413141223.17245-5-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/25] fftools/ffmpeg: move a miplaced assignment 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: 3viPQaIULQ/n Changing AVCodecContext.sample_aspect_ratio after the encoder was opened is by itself questionable, but if anywhere it belongs in encoding rather than filtering code. --- fftools/ffmpeg.c | 3 --- fftools/ffmpeg_enc.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c1070485be..700fa5fbe1 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -711,9 +711,6 @@ static int reap_filters(int flush) switch (av_buffersink_get_type(filter)) { case AVMEDIA_TYPE_VIDEO: - if (!ost->frame_aspect_ratio.num) - enc->sample_aspect_ratio = filtered_frame->sample_aspect_ratio; - enc_frame(ost, filtered_frame); break; case AVMEDIA_TYPE_AUDIO: diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index a0779c45ae..0236e50e38 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -653,6 +653,9 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base), enc->time_base.num, enc->time_base.den); } + + if (frame->sample_aspect_ratio.num && !ost->frame_aspect_ratio.num) + enc->sample_aspect_ratio = frame->sample_aspect_ratio; } update_benchmark(NULL); From patchwork Thu Apr 13 14:12:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41148 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1286965pzb; Thu, 13 Apr 2023 07:16:32 -0700 (PDT) X-Google-Smtp-Source: AKy350ZKgoftddRaXWsjMHAdEdjqhfXNHY/FKq89FDe8Cy37ywzVJD5sBtOiDLe2GGv+eEAwN8Qh X-Received: by 2002:a05:6402:156:b0:506:6002:da69 with SMTP id s22-20020a056402015600b005066002da69mr3010744edu.15.1681395392149; Thu, 13 Apr 2023 07:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395392; cv=none; d=google.com; s=arc-20160816; b=WmR7FbOL5Ent3Vi2ymWhd6q6L9kyapnMsXWTVUVzTqko8taTVQR266rADMHOfVtPX5 nuJoHf/L5vlilYppOm1p4q2L8lWlH7XmS6dRKMeACdO+RaiahvEQN6EykBWApVxOX4Nx y2JapevB1ni1s3qyT/FwxH20CDKjL96sDP0MehK18AwI+VZUp1wDwxquHtbnAsxGgpFX mhmq00uE0GN5j/c8mQGwLAd07Kp0GbKvKmHNEnNOGy3G48/BmsqJ4iikATPLU6N6RHaO BZZQxdwwcKKbYhLXUR7kee88yQXSwgJy42P0M6mK64a6wwZzzS9evBavYCFea4EJE2rR Nrtg== 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=LCIcn57DIlW2XAbodNuFrIV4znVQuAAKGBdRQ5I+hII=; b=fXzB3tMlpN8DWgh5g6U3Z3Cd2iXRwAoynw6xX8VrYfdMC8lPOROnFQ3KQHAq2WhH0g /0MN7Wy+adOaI34RyubgYzYIt7WBNxwo8ehGrhv5E/5Zb4dscJ16QcEIMDbpbenbpexO nNKfmJqh7R02o9OKru8XP6t29s6MDtExja/q+oIZiILFmqx7f/6wKkaVyJfd/jn7jQ5i DDMMdgETmz3AY23pSJwsqbloCuv83Dkz1qBv2Lsb/btleqiv/4CTjRWZPHQA8KpC0OUu IYqIkeU8CkkNqeCiJ5la+qX+pFRxWlo3PrBd0GaobLxLrGac+Hgdb0CLRSkcf5NSVQfK y8wQ== 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 b5-20020aa7cd05000000b0050296642330si1802561edw.2.2023.04.13.07.16.31; Thu, 13 Apr 2023 07:16:32 -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 8727268BE1B; Thu, 13 Apr 2023 17:16:03 +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 0B327680A2D for ; Thu, 13 Apr 2023 17:15:55 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C67682404EC for ; Thu, 13 Apr 2023 16:15:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id kaaGPbGWknDy for ; Thu, 13 Apr 2023 16:15:54 +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 2E60C2404F8 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0DF4A3A0567 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:04 +0200 Message-Id: <20230413141223.17245-6-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg: move a check to a more appropriate place 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: N667x1+2+PcO reap_filters() no longer needs to access the encoding context. --- fftools/ffmpeg.c | 21 +-------------------- fftools/ffmpeg_enc.c | 7 +++++++ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 700fa5fbe1..4d4cbf6aaf 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -669,7 +669,6 @@ static int reap_filters(int flush) /* Reap all buffers present in the buffer sinks */ for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { AVFilterContext *filter; - AVCodecContext *enc = ost->enc_ctx; int ret = 0; if (!ost->filter || !ost->filter->graph->graph) @@ -709,25 +708,7 @@ static int reap_filters(int flush) tb.num, tb.den); } - switch (av_buffersink_get_type(filter)) { - case AVMEDIA_TYPE_VIDEO: - enc_frame(ost, filtered_frame); - break; - case AVMEDIA_TYPE_AUDIO: - if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && - avcodec_is_open(enc) && - enc->ch_layout.nb_channels != filtered_frame->ch_layout.nb_channels) { - av_log(NULL, AV_LOG_ERROR, - "Audio filter graph output is not normalized and encoder does not support parameter changes\n"); - break; - } - enc_frame(ost, filtered_frame); - break; - default: - // TODO support subtitle filters - av_assert0(0); - } - + enc_frame(ost, filtered_frame); av_frame_unref(filtered_frame); } } diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 0236e50e38..063053623f 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -789,6 +789,13 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, AVCodecContext *enc = ost->enc_ctx; int ret; + if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && + enc->ch_layout.nb_channels != frame->ch_layout.nb_channels) { + av_log(ost, AV_LOG_ERROR, + "Audio channel count changed and encoder does not support parameter changes\n"); + return; + } + if (frame->pts == AV_NOPTS_VALUE) frame->pts = e->next_pts; else { From patchwork Thu Apr 13 14:12:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41161 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1289041pzb; Thu, 13 Apr 2023 07:18:46 -0700 (PDT) X-Google-Smtp-Source: AKy350ZYXz30hGS5MQGH+M4Jd8WsBcvV03ewMsvQWWNCnjHXA0Ts1SX044LBLGz9+RK4V+oNmp4j X-Received: by 2002:a17:906:194d:b0:94e:7ffb:bc0f with SMTP id b13-20020a170906194d00b0094e7ffbbc0fmr3483494eje.22.1681395526654; Thu, 13 Apr 2023 07:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395526; cv=none; d=google.com; s=arc-20160816; b=UxbTUEKfKsBd0vwegm/JhOC6uOgtaZUaWkDdYJOlLFb0zb2hWRZCWFGmHV8WDBx6eA E0OsF0hv5j2W8PeSWvxHjSEqu5JfEIGmAZBnSk57qjCMihgfhbMVu7Qjw5ihueqQdL1J 5DOk34mAbMXJnk5p5+3Y7GNnHqOiiIQtG/SwQEG8MfhEQaU/3kzS6ZdH/JyW30AaT8SY kWAUUbWHwfvAaTd6B00pPl/cw27ZTE/8apWuYujq4wdd7QBbuJMEzY6XqhBd2crEouvh I/f+pyT04aBCjExOyXqgJXFqnHujFXYl4nBobHWmCtgtppJUuLc8f7ZmdLaaeTk5B8PI 1iLA== 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=75oeVJYMUqC7LsNsu2+NQ4qgiWexYYC4meVjwykd/V8=; b=YsHCMjuA6Ff9p6aN/8PvvruxSSzjz486L+7V2Xsaqwdg17Y+6C36U6/rKknzbnF8lZ NTm45fa7Bnm2GwFQWVukWMHSDcLBH5jaAPho7rXBDNoDKH2qlp46ODtEFmgry8tsfDIu fvZsp0Rj4DQPeHDWAygLueEmifGNmS3wjL1BjQNe9KmHKnmBl2EFNeifYUVtAkcFjHxS q3GOJ22/n6eEbTcZJibzQgXxvW5Ngu0aWOBFhv21ct0pmtFAjoeo4Zl1iSr9gR7bVXkP ZZ9pP8K66yh7WEUt7nB6eLOmh8Ufc2nx1Ubc2mI9lyU7tE3hSK+mYAZ1sAzsxcoYvUrw f88g== 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 r16-20020a170906365000b009497c0571c4si1855122ejb.918.2023.04.13.07.18.45; Thu, 13 Apr 2023 07:18:46 -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 C561D68BED0; Thu, 13 Apr 2023 17:16:12 +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 B629168BE3D for ; Thu, 13 Apr 2023 17:15:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9DBBE2404F5 for ; Thu, 13 Apr 2023 16:15:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id aNab4FFy4iq9 for ; Thu, 13 Apr 2023 16:15:57 +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 50F7A2406CB for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 1A6703A0586 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:05 +0200 Message-Id: <20230413141223.17245-7-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: drop unnecessary indirection 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: sprGcXDlG4gT init_input_stream() can print log messages directly, there is no need to ship them to the caller. Also, log errors to the InputStream and avoid duplicate information in the message. --- fftools/ffmpeg.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4d4cbf6aaf..57bdc12473 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1907,15 +1907,16 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat return *p; } -static int init_input_stream(InputStream *ist, char *error, int error_len) +static int init_input_stream(InputStream *ist) { int ret; if (ist->decoding_needed) { const AVCodec *codec = ist->dec; if (!codec) { - snprintf(error, error_len, "Decoder (codec %s) not found for input stream #%d:%d", - avcodec_get_name(ist->dec_ctx->codec_id), ist->file_index, ist->st->index); + av_log(ist, AV_LOG_ERROR, + "Decoding requested, but no decoder found for: %s\n", + avcodec_get_name(ist->dec_ctx->codec_id)); return AVERROR(EINVAL); } @@ -1941,9 +1942,9 @@ static int init_input_stream(InputStream *ist, char *error, int error_len) ret = hw_device_setup_for_decode(ist); if (ret < 0) { - snprintf(error, error_len, "Device setup failed for " - "decoder on input stream #%d:%d : %s", - ist->file_index, ist->st->index, av_err2str(ret)); + av_log(ist, AV_LOG_ERROR, + "Hardware device setup failed for decoder: %s\n", + av_err2str(ret)); return ret; } @@ -1951,10 +1952,8 @@ static int init_input_stream(InputStream *ist, char *error, int error_len) if (ret == AVERROR_EXPERIMENTAL) abort_codec_experimental(codec, 0); - snprintf(error, error_len, - "Error while opening decoder for input stream " - "#%d:%d : %s", - ist->file_index, ist->st->index, av_err2str(ret)); + av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n", + av_err2str(ret)); return ret; } assert_avoptions(ist->decoder_opts); @@ -1983,7 +1982,6 @@ static int init_output_stream_nofilter(OutputStream *ost) static int transcode_init(void) { int ret = 0; - char error[1024] = {0}; /* init framerate emulation */ for (int i = 0; i < nb_input_files; i++) { @@ -1995,7 +1993,7 @@ static int transcode_init(void) /* init input streams */ for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) - if ((ret = init_input_stream(ist, error, sizeof(error))) < 0) + if ((ret = init_input_stream(ist)) < 0) goto dump_format; /* @@ -2105,10 +2103,8 @@ static int transcode_init(void) av_log(NULL, AV_LOG_INFO, "\n"); } - if (ret) { - av_log(NULL, AV_LOG_ERROR, "%s\n", error); + if (ret) return ret; - } atomic_store(&transcode_init_done, 1); From patchwork Thu Apr 13 14:12:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41149 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1287227pzb; Thu, 13 Apr 2023 07:16:46 -0700 (PDT) X-Google-Smtp-Source: AKy350Zof31jzOXPJXFuO3QN077ZL9gFMFFYugsLqbkcqe1TuOru0UGuO6eIa/wFhxDCsGVKjGj9 X-Received: by 2002:a17:907:802:b0:94a:9673:dd1c with SMTP id wv2-20020a170907080200b0094a9673dd1cmr1854368ejb.20.1681395406239; Thu, 13 Apr 2023 07:16:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395406; cv=none; d=google.com; s=arc-20160816; b=GzHhB7m7n/w2/oD4REt6WNTSUv0yP8Pd0Wp5i4d2cYY+IiB3PUXifG+yfySNDGaUVd kB78F7n7LgbcAFY+3iGLv4yHZabVfFQpCUteMh5kd4qqxNxN8CflJvoiQp008mF4AkVZ h5F4/JjQ0Oxbyrco04+Y1ix3HF/Ui/TvgLICnjPVyYv8TmqQGVMODawstin5hUO6o2nx 1tLlZd8qcEFm2bskmXd/TqzRLAA5ez/ViFGDn8UlSsRmTdO4/Hm4V0L0a2vTtjnBkYnI 2mPfx1+ch2Fw64rJ2C2kCH+CpJ7mm1BDHYWOz+OQORaCuB6cuiW7LG6tVETwRJoDIwe/ esHQ== 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=So1LhHht5bn6cWOCvTQDnV59nUDPqBXRsMNXbx+RcC0=; b=qJwhXq7FrfM8Ovu91TBv+4/90EKQz9mzXk1N9E5z8RNSHy4boYUk3Vh47nG07795XK 7F7NoF+hP8Gn+nNA+mSuyu0ex70pG5CuhSjI/ceRBsTZYkZMrvgHCM2cWmLpSGL++kuW S8RexGYtYegHnNLpGJ7l0JxGzrqGycSMlwQIdcglbwbA6RwrSlokE7V6rEWhayIgWGBD VCUhR+KeJUFz/2JwkAx+/43Sn4h6Q8EwHXIRTG7vGzktozxc8/aWXoqtTO3HolUjIoL4 Q6mW+EO3fYlTt5w7TWDadyQqkem3S7FbWU057QTeckUzIlZGS5xlZTUTpnfWUoJ+rub0 kVZA== 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 mv15-20020a170907838f00b0094bcc67fcb4si1941440ejc.693.2023.04.13.07.16.45; Thu, 13 Apr 2023 07:16:46 -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 9B70F68BE35; Thu, 13 Apr 2023 17:16:04 +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 A2B9168BD76 for ; Thu, 13 Apr 2023 17:15:55 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 697E22404F8 for ; Thu, 13 Apr 2023 16:15:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1-GLA22QGN-p for ; Thu, 13 Apr 2023 16:15:54 +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 34C28240591 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 252B73A038E for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:06 +0200 Message-Id: <20230413141223.17245-8-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/25] fftools/ffmpeg_mux_init: consolidate input stream flagging code 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: xF06FNA1DiBt Makes it easier to see where the input stream is modified from muxer code. --- fftools/ffmpeg_mux_init.c | 42 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index e3d66b9897..dc1dd834e0 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1200,13 +1200,6 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24) av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); - if (ost->ist) { - ost->ist->discard = 0; - ost->ist->st->discard = ost->ist->user_set_discard; - - if (!(ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))) - ist_output_add(ost->ist, ost); - } ost->last_mux_dts = AV_NOPTS_VALUE; MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, @@ -1221,6 +1214,25 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, default: new_stream_unknown (mux, o, ost); break; } + if (ost->ist) { + ost->ist->discard = 0; + ost->ist->st->discard = ost->ist->user_set_discard; + + if (ost->enc) + ost->ist->decoding_needed |= DECODING_FOR_OST; + + if (ost->enc && + (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + ret = init_simple_filtergraph(ost->ist, ost); + if (ret < 0) { + av_log(ost, AV_LOG_ERROR, + "Error initializing a simple filtergraph\n"); + exit_program(1); + } + } else + ist_output_add(ost->ist, ost); + } + if (ost->ist && !ost->enc) { ret = streamcopy_init(mux, o, ost); if (ret < 0) @@ -2407,25 +2419,9 @@ int of_open(const OptionsContext *o, const char *filename) /* check if all codec options have been used */ validate_enc_avopt(mux, o->g->codec_opts); - /* set the decoding_needed flags and create simple filtergraphs */ for (int i = 0; i < of->nb_streams; i++) { OutputStream *ost = of->streams[i]; - if (ost->enc_ctx && ost->ist) { - InputStream *ist = ost->ist; - ist->decoding_needed |= DECODING_FOR_OST; - - if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || - ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - err = init_simple_filtergraph(ist, ost); - if (err < 0) { - av_log(ost, AV_LOG_ERROR, - "Error initializing a simple filtergraph\n"); - exit_program(1); - } - } - } - /* set the filter output constraints */ if (ost->filter) { const AVCodec *c = ost->enc_ctx->codec; From patchwork Thu Apr 13 14:12:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41155 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1288412pzb; Thu, 13 Apr 2023 07:18:04 -0700 (PDT) X-Google-Smtp-Source: AKy350bfuObpAIYH4OcaSkwuST3sPZSWOuSU8IirIUcFGwNXU7l3h6+ohGarNcS5E18vzUriMo1n X-Received: by 2002:a17:907:210d:b0:930:9f89:65ef with SMTP id qn13-20020a170907210d00b009309f8965efmr2922533ejb.11.1681395484540; Thu, 13 Apr 2023 07:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395484; cv=none; d=google.com; s=arc-20160816; b=fmVdCy5o3c2l0mwSyrQ9/Xgx8oZJ1Blp4buqS1kNB71lgB7d78XnHUbazPViD+tYO0 r+l26WWyMQ7ID8a7k9gnj3N+r4MoAlN9P4Jifxwwe+86g7N7cYCj6cUjztFvKgGhDrxd OtTOa/3ensRSFLsTcd2vNE07xhAbG6m3NnuTxz9jUi9Pq9TC4EE3oZH7ExSW1RmJ3WMf VHUZ134olSiT1kSx0bRZHYqpqPmr0YHiqSKJ195dzt7V9Ewf6rU0VN0al+cwwKpZSZZ9 0iMMg2Cex4TcZJxGvb4oyTYgUOE4zL9E5D7TDV5okhWsrFQycvVldb75WXDoZ5abSAWe lmIQ== 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=aF8wG3G/uohGr0E3o3qY1lXA+yMMsw0YCKF/srfIk30=; b=SY++8NjVpnawvGBaZXbY5WfuS0XGOqmloDQJz6ETCVTzHxaMxUjUB9zmjgE/gF2gRJ CswI6KdFer2jUU11PjS9s3XVOpwFOBMXCuzQ6G8IGrGIjk8BBAvxE1XR3NrP7w2q8URv 2h4Hk13mFjZ5Xj/WLH0yTNrfxvWuZbAT/pb9s+5roJcDJZcWqs3+PEaclmihd+OY4kCZ T9Q3NxC5+sgECRklv7PojdP+SLqHx38X9gbchpIFugVkQ8REAl3zTUfrl5NbHzvr8wPY +7yRAPHj/n59PqAYYBB+uwrbF6nxB9kt0i9EVZOJTSUNqs3k7Laba/yWQ+ozGxFtLNNj VAuA== 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 n19-20020aa7db53000000b00501d70c10bbsi1917402edt.72.2023.04.13.07.18.04; Thu, 13 Apr 2023 07:18:04 -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 0D54268BEC0; Thu, 13 Apr 2023 17:16:10 +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 5CBA868BE34 for ; Thu, 13 Apr 2023 17:15:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 84E4D2405B5 for ; Thu, 13 Apr 2023 16:15:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tE84ITRLB44G for ; Thu, 13 Apr 2023 16:15:55 +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 4147F2405EC for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3006A3A039B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:07 +0200 Message-Id: <20230413141223.17245-9-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: add a function adding a destination filter for InputStream 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: 4hwJLMhRT/4M This way filtering code does not directly mess with InputStream internals. Will become more useful in following commits. --- fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 6 ++++++ fftools/ffmpeg_filter.c | 8 +++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 17076f018d..d25377514e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -880,6 +880,7 @@ void ifile_close(InputFile **f); int ifile_get_packet(InputFile *f, AVPacket **pkt); void ist_output_add(InputStream *ist, OutputStream *ost); +void ist_filter_add(InputStream *ist, InputFilter *ifilter); /* iterate over all input streams in all input files; * pass NULL to start iteration */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index b9849d1669..2d46dbf876 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -567,6 +567,12 @@ void ist_output_add(InputStream *ist, OutputStream *ost) ist->outputs[ist->nb_outputs - 1] = ost; } +void ist_filter_add(InputStream *ist, InputFilter *ifilter) +{ + GROW_ARRAY(ist->filters, ist->nb_filters); + ist->filters[ist->nb_filters - 1] = ifilter; +} + static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 584f51ac3f..d2a185cf98 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -212,12 +212,11 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) if (!ifilter->frame_queue) report_and_exit(AVERROR(ENOMEM)); - GROW_ARRAY(ist->filters, ist->nb_filters); - ist->filters[ist->nb_filters - 1] = ifilter; - GROW_ARRAY(filtergraphs, nb_filtergraphs); filtergraphs[nb_filtergraphs - 1] = fg; + ist_filter_add(ist, ifilter); + return 0; } @@ -319,8 +318,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) if (!ifilter->frame_queue) report_and_exit(AVERROR(ENOMEM)); - GROW_ARRAY(ist->filters, ist->nb_filters); - ist->filters[ist->nb_filters - 1] = ifilter; + ist_filter_add(ist, ifilter); } static int read_binary(const char *path, uint8_t **data, int *len) From patchwork Thu Apr 13 14:12:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41159 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1289814pzb; Thu, 13 Apr 2023 07:19:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ZEWT/06uLx09/i4a3GaNuWOpqb622kWlpTasV7Oh6IHbdSXnG1RGsHFz45R4nI323uI7XT X-Received: by 2002:a17:906:49d9:b0:94a:4c55:e714 with SMTP id w25-20020a17090649d900b0094a4c55e714mr2495655ejv.76.1681395584302; Thu, 13 Apr 2023 07:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395584; cv=none; d=google.com; s=arc-20160816; b=DXE14UOgVsdHW+dDNAcZ59feTb4qqpQOKTIe02XUGxtj1+Z8ISQ+5Uomuc9VLs0Ko5 N3sRdyWsKt7HgG26/60HP3kdmj1R/CC9IV6L+XT8skeV2ka+330WxTuNeklN8pz/nEwK FpdWfWxyM5ygK3HHCNpva51Bp4A4LKW1/3Z5SmlIHwnGX+Gwn4dZTc0uJkIwCqUJqSUJ t1DeLGa4nOWXtkhWlvBworyaBx4vHd5zkRFTzh0N4loH8D0gbicgqu5Wrz+p0jvGjPT4 jijEScX/Mu8KmaRZ6MKfPvO0qW3qpQOispeP3lnn8S3YDc66JJAFDqRxwapK+c+BsDXy +bIg== 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=4kikUTkZpkl0Rs6ISoW/JdEQy/76E+xeHH2Z7Ph+AFI=; b=wyUtsrN82MftNXbK9GTYenL4YpGJyixzb3XBrD0i44pAoc5bPOL0ZzOOS3klx9qSJT CTQ/v2WCRRSgKvm1ajgqyZQEG+Wr0/vjzWOoFPEotd6Ydhb7mWTrUb0obNG56xwKT+V8 VC/C1laqMQgkVOV4g6IBeNoQRpTv3G2U2GJi6o27f6+FR9InlKgxeCZMuNilIoqDeeID BgiZbjhGAoRUDhGF0BxN3AifWIp+L5SeNZrYJCBmYkqHr1qlNJvpw4Yy1JM93G1kNVXg FhtjVHuPvaC7w3jP+Lj86+7DV90ArJGWp1x313LLviaLh8ymlST+V0PDuS4sg5c7P+27 rvVQ== 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 wl24-20020a170907311800b0094e987b24b1si1701944ejb.1008.2023.04.13.07.19.43; Thu, 13 Apr 2023 07:19:44 -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 ED13668BEE6; Thu, 13 Apr 2023 17:16:16 +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 47E5868BE34 for ; Thu, 13 Apr 2023 17:16:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A979C2405F9 for ; Thu, 13 Apr 2023 16:15:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id pqzQ1cz7meHK for ; Thu, 13 Apr 2023 16:15:57 +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 4A61A2406CA for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3BAAA3A03E5 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:08 +0200 Message-Id: <20230413141223.17245-10-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/25] fftools/ffmpeg: stop setting InputStream fields from muxing/filtering code 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: vlIThfZOWQ5v Set InputStream.decoding_needed/discard/etc. only from ist_{filter,output},add() functions. Reduces the knowledge of InputStream internals in muxing/filtering code. --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_demux.c | 13 ++++++++++++- fftools/ffmpeg_filter.c | 8 ++------ fftools/ffmpeg_mux_init.c | 6 ------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d25377514e..c73fc8a459 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -880,7 +880,7 @@ void ifile_close(InputFile **f); int ifile_get_packet(InputFile *f, AVPacket **pkt); void ist_output_add(InputStream *ist, OutputStream *ost); -void ist_filter_add(InputStream *ist, InputFilter *ifilter); +void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple); /* iterate over all input streams in all input files; * pass NULL to start iteration */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 2d46dbf876..d15a714e90 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -561,14 +561,25 @@ void ifile_close(InputFile **pf) av_freep(pf); } +static void ist_use(InputStream *ist, int decoding_needed) +{ + ist->discard = 0; + ist->st->discard = ist->user_set_discard; + ist->decoding_needed |= decoding_needed; +} + void ist_output_add(InputStream *ist, OutputStream *ost) { + ist_use(ist, ost->enc ? DECODING_FOR_OST : 0); + GROW_ARRAY(ist->outputs, ist->nb_outputs); ist->outputs[ist->nb_outputs - 1] = ost; } -void ist_filter_add(InputStream *ist, InputFilter *ifilter) +void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) { + ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER); + GROW_ARRAY(ist->filters, ist->nb_filters); ist->filters[ist->nb_filters - 1] = ifilter; } diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index d2a185cf98..1d88d2e3b1 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -215,7 +215,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) GROW_ARRAY(filtergraphs, nb_filtergraphs); filtergraphs[nb_filtergraphs - 1] = fg; - ist_filter_add(ist, ifilter); + ist_filter_add(ist, ifilter, 1); return 0; } @@ -303,10 +303,6 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) } av_assert0(ist); - ist->discard = 0; - ist->decoding_needed |= DECODING_FOR_FILTER; - ist->st->discard = AVDISCARD_NONE; - ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); ifilter->ist = ist; ifilter->graph = fg; @@ -318,7 +314,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) if (!ifilter->frame_queue) report_and_exit(AVERROR(ENOMEM)); - ist_filter_add(ist, ifilter); + ist_filter_add(ist, ifilter, 0); } static int read_binary(const char *path, uint8_t **data, int *len) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index dc1dd834e0..e3d8f5e386 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1215,12 +1215,6 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, } if (ost->ist) { - ost->ist->discard = 0; - ost->ist->st->discard = ost->ist->user_set_discard; - - if (ost->enc) - ost->ist->decoding_needed |= DECODING_FOR_OST; - if (ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { ret = init_simple_filtergraph(ost->ist, ost); From patchwork Thu Apr 13 14:12:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41166 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1290460pzb; Thu, 13 Apr 2023 07:20:31 -0700 (PDT) X-Google-Smtp-Source: AKy350ZTOb8okYALkVXwak33HkcaWcQ+Kr56ViPm+M9ClXuydXJmHnfF3Zs9C5FMSI5f3d1dHVxB X-Received: by 2002:a17:906:4743:b0:932:fc34:88f with SMTP id j3-20020a170906474300b00932fc34088fmr3196726ejs.11.1681395631264; Thu, 13 Apr 2023 07:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395631; cv=none; d=google.com; s=arc-20160816; b=fMWMzI1H5cf9u81tfS/bXuFhXiF24DKV/rZ5epihoLW9cXINzGdMBLmJ0yWyurHRJH bHkXeMgoZg1JbQS3ZOpNjeru3p467Z6dPy7QQbJVrH1eBqgIKcGm0sDBhu+8YQ9A2Fgi duaV38CTI9nCJ57SAZ6xuprmxZ2TZv41hlOxEqb0ZxiKzyeDJxPJkAJtDycRdFagKpOH sHG+SACakTY9GDsG7qRQgYoMo2Vt29XM0ppVMbY6iAs6+F3VfA44Y9aLu/W7uRs8RGpO +BWFbY7ofYwqw4Jps7Pf5R+u9jfzXWilmaqaXIx+B4FIFg/9fhN9Gmir+wBvNNJzLl9N 7/yA== 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=9jg4Slni8zFH3OBybOtjutUWFwmfz3PXvtfZuHxD0tQ=; b=Seh9wB0o+lWyBs6Op0sqiHLDdZW4oXu/Ca6zXKnmUa9SPCwGqboD/4BmN0wC0+j1Pc zDG0MV9mI/DbuoEeW9YDhCycJ08xtEC8+bQAk644/3eBuPME8WjtMI/PfavWlFSHEKNU Ay05FRdnFil4oq/TGwQtvczsYhwONWifEuAccJK0HF5JpxGnCPwYcJ5O2Aph2idL8+8Z kK2NynRsQpddeKH2DMILyOJi6RMBSTwzqiedqHsGuVnFkFZgIAdf/9rjPaDmzq+AfpYG Vo2ZflOswmRv2LuipOVtTNHU1k4LTXXDIZtmD1Ff9GhvCn8bfK63Qs4BcT9hvSt7OA8J Ifqg== 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 wl7-20020a170907310700b008d89608d4a2si1843566ejb.204.2023.04.13.07.20.30; Thu, 13 Apr 2023 07:20:31 -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 0E3BA68BEF8; Thu, 13 Apr 2023 17:16:20 +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 E5C2168BE6B for ; Thu, 13 Apr 2023 17:16:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 28BBC2404EC for ; Thu, 13 Apr 2023 16:16:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id EjKoSVcuWmQU for ; Thu, 13 Apr 2023 16:15:57 +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 5661F2406CC for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 467DB3A038E for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:09 +0200 Message-Id: <20230413141223.17245-11-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/25] fftools/ffmpeg: move opening decoders to a new 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: opiQFagmo4AC All decoding code will be moved to this file in the future. --- fftools/Makefile | 1 + fftools/ffmpeg.c | 111 +---------------------------------- fftools/ffmpeg.h | 2 + fftools/ffmpeg_dec.c | 135 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 110 deletions(-) create mode 100644 fftools/ffmpeg_dec.c diff --git a/fftools/Makefile b/fftools/Makefile index 9939c7095c..56820e6bc8 100644 --- a/fftools/Makefile +++ b/fftools/Makefile @@ -10,6 +10,7 @@ ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF)) ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) OBJS-ffmpeg += \ + fftools/ffmpeg_dec.o \ fftools/ffmpeg_demux.o \ fftools/ffmpeg_enc.o \ fftools/ffmpeg_filter.o \ diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 57bdc12473..d8b06eb724 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -621,11 +621,6 @@ void assert_avoptions(AVDictionary *m) } } -static void abort_codec_experimental(const AVCodec *c, int encoder) -{ - exit_program(1); -} - void update_benchmark(const char *fmt, ...) { if (do_benchmark_all) { @@ -1858,110 +1853,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo return !eof_reached; } -static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts) -{ - InputStream *ist = s->opaque; - const enum AVPixelFormat *p; - int ret; - - for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(*p); - const AVCodecHWConfig *config = NULL; - int i; - - if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) - break; - - if (ist->hwaccel_id == HWACCEL_GENERIC || - ist->hwaccel_id == HWACCEL_AUTO) { - for (i = 0;; i++) { - config = avcodec_get_hw_config(s->codec, i); - if (!config) - break; - if (!(config->methods & - AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)) - continue; - if (config->pix_fmt == *p) - break; - } - } - if (config && config->device_type == ist->hwaccel_device_type) { - ret = hwaccel_decode_init(s); - if (ret < 0) { - if (ist->hwaccel_id == HWACCEL_GENERIC) { - av_log(NULL, AV_LOG_FATAL, - "%s hwaccel requested for input stream #%d:%d, " - "but cannot be initialized.\n", - av_hwdevice_get_type_name(config->device_type), - ist->file_index, ist->st->index); - return AV_PIX_FMT_NONE; - } - continue; - } - - ist->hwaccel_pix_fmt = *p; - break; - } - } - - return *p; -} - -static int init_input_stream(InputStream *ist) -{ - int ret; - - if (ist->decoding_needed) { - const AVCodec *codec = ist->dec; - if (!codec) { - av_log(ist, AV_LOG_ERROR, - "Decoding requested, but no decoder found for: %s\n", - avcodec_get_name(ist->dec_ctx->codec_id)); - return AVERROR(EINVAL); - } - - ist->dec_ctx->opaque = ist; - ist->dec_ctx->get_format = get_format; - - if (ist->dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE && - (ist->decoding_needed & DECODING_FOR_OST)) { - av_dict_set(&ist->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE); - if (ist->decoding_needed & DECODING_FOR_FILTER) - av_log(NULL, AV_LOG_WARNING, "Warning using DVB subtitles for filtering and output at the same time is not fully supported, also see -compute_edt [0|1]\n"); - } - - /* Useful for subtitles retiming by lavf (FIXME), skipping samples in - * audio, and video decoders such as cuvid or mediacodec */ - ist->dec_ctx->pkt_timebase = ist->st->time_base; - - if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) - av_dict_set(&ist->decoder_opts, "threads", "auto", 0); - /* Attached pics are sparse, therefore we would not want to delay their decoding till EOF. */ - if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC) - av_dict_set(&ist->decoder_opts, "threads", "1", 0); - - ret = hw_device_setup_for_decode(ist); - if (ret < 0) { - av_log(ist, AV_LOG_ERROR, - "Hardware device setup failed for decoder: %s\n", - av_err2str(ret)); - return ret; - } - - if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { - if (ret == AVERROR_EXPERIMENTAL) - abort_codec_experimental(codec, 0); - - av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n", - av_err2str(ret)); - return ret; - } - assert_avoptions(ist->decoder_opts); - } - - return 0; -} - static int init_output_stream_nofilter(OutputStream *ost) { int ret = 0; @@ -1993,7 +1884,7 @@ static int transcode_init(void) /* init input streams */ for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) - if ((ret = init_input_stream(ist)) < 0) + if (ist->decoding_needed && (ret = dec_open(ist)) < 0) goto dump_format; /* diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index c73fc8a459..5833c13812 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -829,6 +829,8 @@ AVBufferRef *hw_device_for_filter(void); int hwaccel_decode_init(AVCodecContext *avctx); +int dec_open(InputStream *ist); + int enc_alloc(Encoder **penc, const AVCodec *codec); void enc_free(Encoder **penc); diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c new file mode 100644 index 0000000000..ccf558649c --- /dev/null +++ b/fftools/ffmpeg_dec.c @@ -0,0 +1,135 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/dict.h" +#include "libavutil/error.h" +#include "libavutil/log.h" +#include "libavutil/pixdesc.h" +#include "libavutil/pixfmt.h" + +#include "libavcodec/avcodec.h" +#include "libavcodec/codec.h" + +#include "ffmpeg.h" + +static void abort_codec_experimental(const AVCodec *c, int encoder) +{ + exit_program(1); +} + +static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts) +{ + InputStream *ist = s->opaque; + const enum AVPixelFormat *p; + int ret; + + for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(*p); + const AVCodecHWConfig *config = NULL; + int i; + + if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) + break; + + if (ist->hwaccel_id == HWACCEL_GENERIC || + ist->hwaccel_id == HWACCEL_AUTO) { + for (i = 0;; i++) { + config = avcodec_get_hw_config(s->codec, i); + if (!config) + break; + if (!(config->methods & + AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)) + continue; + if (config->pix_fmt == *p) + break; + } + } + if (config && config->device_type == ist->hwaccel_device_type) { + ret = hwaccel_decode_init(s); + if (ret < 0) { + if (ist->hwaccel_id == HWACCEL_GENERIC) { + av_log(NULL, AV_LOG_FATAL, + "%s hwaccel requested for input stream #%d:%d, " + "but cannot be initialized.\n", + av_hwdevice_get_type_name(config->device_type), + ist->file_index, ist->st->index); + return AV_PIX_FMT_NONE; + } + continue; + } + + ist->hwaccel_pix_fmt = *p; + break; + } + } + + return *p; +} + +int dec_open(InputStream *ist) +{ + const AVCodec *codec = ist->dec; + int ret; + + if (!codec) { + av_log(ist, AV_LOG_ERROR, + "Decoding requested, but no decoder found for: %s\n", + avcodec_get_name(ist->dec_ctx->codec_id)); + return AVERROR(EINVAL); + } + + ist->dec_ctx->opaque = ist; + ist->dec_ctx->get_format = get_format; + + if (ist->dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE && + (ist->decoding_needed & DECODING_FOR_OST)) { + av_dict_set(&ist->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE); + if (ist->decoding_needed & DECODING_FOR_FILTER) + av_log(NULL, AV_LOG_WARNING, "Warning using DVB subtitles for filtering and output at the same time is not fully supported, also see -compute_edt [0|1]\n"); + } + + /* Useful for subtitles retiming by lavf (FIXME), skipping samples in + * audio, and video decoders such as cuvid or mediacodec */ + ist->dec_ctx->pkt_timebase = ist->st->time_base; + + if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) + av_dict_set(&ist->decoder_opts, "threads", "auto", 0); + /* Attached pics are sparse, therefore we would not want to delay their decoding till EOF. */ + if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC) + av_dict_set(&ist->decoder_opts, "threads", "1", 0); + + ret = hw_device_setup_for_decode(ist); + if (ret < 0) { + av_log(ist, AV_LOG_ERROR, + "Hardware device setup failed for decoder: %s\n", + av_err2str(ret)); + return ret; + } + + if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { + if (ret == AVERROR_EXPERIMENTAL) + abort_codec_experimental(codec, 0); + + av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n", + av_err2str(ret)); + return ret; + } + assert_avoptions(ist->decoder_opts); + + return 0; +} From patchwork Thu Apr 13 14:12:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41165 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1290213pzb; Thu, 13 Apr 2023 07:20:14 -0700 (PDT) X-Google-Smtp-Source: AKy350a9KCo9cTZshxuv61dvjtnNUWSqE/YVCDds31m34FJPAkk86PRx+K1WO9MPcPO8n+MOfvI5 X-Received: by 2002:a17:906:3159:b0:932:1af9:7386 with SMTP id e25-20020a170906315900b009321af97386mr2803143eje.27.1681395614403; Thu, 13 Apr 2023 07:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395614; cv=none; d=google.com; s=arc-20160816; b=Ysp3pF/EJQIsAkxMeUS938zQPoi4E6eGQIcpBYpsdjqfiY8btXCZCrDMUcPiwB9UPr t4pUOFGBUI/rt8cJEUzocZxSx2y6gg5xSgYyUj0zgrtzrcSW2JIsQMkaDukOrS9B9dTR aZ/4Unbc1o+Gjaj9IYni1zhzZMcMdEhU5W0XXSH3hM3Yu2GielYrR38M/NrEJv4jDK4S gvszPttLrUTD3N/Bc518TukrDxzcLG5LdgIYStKryTrWsKQmHetYzQVCF13EqXf74puq L40NIhl6+9/vhMraVeTI4u9Go8Ah9mqBnf/72VM41o93ulGsOGh5UDzsXgwQLks2hwcL lC5g== 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=HvTUswTv9sJsigdqYw6Itul3KVyKXKh0TPganZt2klM=; b=OqMPZ9ehLoJSwynF9UyYN4QHWdH9+UH+iTs0Tan64okdRDdjk8pSd01XJLA/ixu569 OQTYnPxpc/wzxpU+VuNKGwJgVAnltNIGhFQ7k21qatSSYtb9ZA2DROkfioDVIwby+/6M 9IPiq9vFAq5cxnrcpCseHrsrBX6Odb0re1GoYk7gSslqwDsaGQqrLoxIPYJJ98qWUoZG tX7kyPhoCaKum7TaOF8JwwbnLHA8R33i9WHYqtzaqZ0KkxezON/UGq9DYxWomkTgfcw0 yvMKcyZFJXHy+kIomoc/Wz5riBa62MMRGfub7OAg5cpSJMUg5Yb4dtCVW87oD9YpV84G 95hg== 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 fg1-20020a1709069c4100b0094bcb53bc1dsi1911895ejc.1048.2023.04.13.07.20.14; Thu, 13 Apr 2023 07:20:14 -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 10BC068BEF5; Thu, 13 Apr 2023 17:16:19 +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 DB45B68BE53 for ; Thu, 13 Apr 2023 17:16:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CE4D92406CE for ; Thu, 13 Apr 2023 16:15:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id camQMyObnyi4 for ; Thu, 13 Apr 2023 16:15:59 +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 638772406CD for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 525AF3A039B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:10 +0200 Message-Id: <20230413141223.17245-12-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/25] fftools/ffmpeg_dec: reindent after previous commit 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: /tXlZ376monF --- fftools/ffmpeg_dec.c | 80 ++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index ccf558649c..d6fd0de126 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -83,53 +83,53 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat int dec_open(InputStream *ist) { - const AVCodec *codec = ist->dec; + const AVCodec *codec = ist->dec; int ret; - if (!codec) { - av_log(ist, AV_LOG_ERROR, - "Decoding requested, but no decoder found for: %s\n", - avcodec_get_name(ist->dec_ctx->codec_id)); - return AVERROR(EINVAL); - } + if (!codec) { + av_log(ist, AV_LOG_ERROR, + "Decoding requested, but no decoder found for: %s\n", + avcodec_get_name(ist->dec_ctx->codec_id)); + return AVERROR(EINVAL); + } - ist->dec_ctx->opaque = ist; - ist->dec_ctx->get_format = get_format; + ist->dec_ctx->opaque = ist; + ist->dec_ctx->get_format = get_format; - if (ist->dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE && - (ist->decoding_needed & DECODING_FOR_OST)) { - av_dict_set(&ist->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE); - if (ist->decoding_needed & DECODING_FOR_FILTER) - av_log(NULL, AV_LOG_WARNING, "Warning using DVB subtitles for filtering and output at the same time is not fully supported, also see -compute_edt [0|1]\n"); - } + if (ist->dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE && + (ist->decoding_needed & DECODING_FOR_OST)) { + av_dict_set(&ist->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE); + if (ist->decoding_needed & DECODING_FOR_FILTER) + av_log(NULL, AV_LOG_WARNING, "Warning using DVB subtitles for filtering and output at the same time is not fully supported, also see -compute_edt [0|1]\n"); + } - /* Useful for subtitles retiming by lavf (FIXME), skipping samples in - * audio, and video decoders such as cuvid or mediacodec */ - ist->dec_ctx->pkt_timebase = ist->st->time_base; - - if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) - av_dict_set(&ist->decoder_opts, "threads", "auto", 0); - /* Attached pics are sparse, therefore we would not want to delay their decoding till EOF. */ - if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC) - av_dict_set(&ist->decoder_opts, "threads", "1", 0); - - ret = hw_device_setup_for_decode(ist); - if (ret < 0) { - av_log(ist, AV_LOG_ERROR, - "Hardware device setup failed for decoder: %s\n", - av_err2str(ret)); - return ret; - } + /* Useful for subtitles retiming by lavf (FIXME), skipping samples in + * audio, and video decoders such as cuvid or mediacodec */ + ist->dec_ctx->pkt_timebase = ist->st->time_base; + + if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) + av_dict_set(&ist->decoder_opts, "threads", "auto", 0); + /* Attached pics are sparse, therefore we would not want to delay their decoding till EOF. */ + if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC) + av_dict_set(&ist->decoder_opts, "threads", "1", 0); + + ret = hw_device_setup_for_decode(ist); + if (ret < 0) { + av_log(ist, AV_LOG_ERROR, + "Hardware device setup failed for decoder: %s\n", + av_err2str(ret)); + return ret; + } - if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { - if (ret == AVERROR_EXPERIMENTAL) - abort_codec_experimental(codec, 0); + if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { + if (ret == AVERROR_EXPERIMENTAL) + abort_codec_experimental(codec, 0); - av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n", - av_err2str(ret)); - return ret; - } - assert_avoptions(ist->decoder_opts); + av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n", + av_err2str(ret)); + return ret; + } + assert_avoptions(ist->decoder_opts); return 0; } From patchwork Thu Apr 13 14:12:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41164 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1289623pzb; Thu, 13 Apr 2023 07:19:29 -0700 (PDT) X-Google-Smtp-Source: AKy350bBJD3hQvLtY4dJbn0o8t6PE7M/a+izdJcgpWiafjlScV2YXC9QrCKE366wK+CEgpWS9DHN X-Received: by 2002:a17:906:686:b0:94e:1069:151d with SMTP id u6-20020a170906068600b0094e1069151dmr2927504ejb.10.1681395569564; Thu, 13 Apr 2023 07:19:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395569; cv=none; d=google.com; s=arc-20160816; b=GZTH1IoccHp5UaraLF6Kgz7DVLyRx1hzSHg1QPt09Qz1JV37quTiRQIheZq2xj6TSw iAjzGZBBzuDsJvxDlMLsV0H9c9Riw+bfDXPshBHL2VqRLZMA2lF+Tgzzf2n6ra1OPFVg pNW79nisM9rK9Og7empG2n1nk7bJnEMKQ18GGMOji/PXcL9uZi1O0qDC9GkhH+VLZbpk 73PJSMXVbqECSw9fo7eA6hEHxarbpjicRbJfyE7SeOkqzJqQv6lU72nnCukODNL8NaFW eP6JjzuzRNv0BX2O2L/pzrVuIzJ+Qafoaq/E+fucwmAYbPWNaMfyy/dJGWeP5LPXt/7d 9NTg== 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=sgDmmqNnWar36B9N3lIkXsMCRTmHuDsvg1aMZ7CC5Fo=; b=rFRfig0TCV0XmBC7SMyiSBscD96EEB1I8ROfzSXtz0PRtgOpPYiveo8qe3NC9ewTuV /CoYuYvlaSBy7/t4Q/Wm+YHC88i3Y+S6xqapIYDyQlNQY0bA6vE4zy1wwE8jQoi8qpr9 yYE8rV6VFOhlLGtaF8GS5u185o/oCAG7eX3zNTBK4hNNYtyBGSnO9sA8T7P7xKknCS21 Nt+G25F4gZZMdFOfrtiVCUSmbaehrY6ZI3yEgs+WURy6gKLVcVJi2HRa5FsF+OW1Ritj 6zdKGsCsj4KjGbxYDSiK5tTrNsVcQnB7AYCiYMdhQjWcnT1RhBhq978ayveDby0FVHXR ZF+w== 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 d25-20020aa7d5d9000000b0050679ba247esi251161eds.497.2023.04.13.07.19.29; Thu, 13 Apr 2023 07:19:29 -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 E12A268BEDD; Thu, 13 Apr 2023 17:16:15 +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 48C6B68BE48 for ; Thu, 13 Apr 2023 17:16:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2D3382406CA for ; Thu, 13 Apr 2023 16:15:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id HJyDJUmf-QoT for ; Thu, 13 Apr 2023 16:15:58 +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 6F4142406CE for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5EF253A0404 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:11 +0200 Message-Id: <20230413141223.17245-13-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/25] fftools/ffmpeg_dec: drop useless abort_codec_experimental() 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: 6lxSwjrwcuGd It does nothing beyond exit_program(). --- fftools/ffmpeg_dec.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index d6fd0de126..658e7418e9 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -27,11 +27,6 @@ #include "ffmpeg.h" -static void abort_codec_experimental(const AVCodec *c, int encoder) -{ - exit_program(1); -} - static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts) { InputStream *ist = s->opaque; @@ -123,7 +118,7 @@ int dec_open(InputStream *ist) if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { if (ret == AVERROR_EXPERIMENTAL) - abort_codec_experimental(codec, 0); + exit_program(1); av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n", av_err2str(ret)); From patchwork Thu Apr 13 14:12:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41151 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1287705pzb; Thu, 13 Apr 2023 07:17:13 -0700 (PDT) X-Google-Smtp-Source: AKy350atNxQDtseFIAmNhbh6ef0pwzOJSUWeUGQQcu8Aanid1l3MgJZYXGWHWE2J9Kdiyo1PkB3h X-Received: by 2002:aa7:cac5:0:b0:504:b45a:5f99 with SMTP id l5-20020aa7cac5000000b00504b45a5f99mr2130224edt.19.1681395432952; Thu, 13 Apr 2023 07:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395432; cv=none; d=google.com; s=arc-20160816; b=c6DMYU+tuMlBvB02ZpjQLGDwoY1tfCnf4l3DTuyTNBox2QRx5nS2m09uisxNMJyJy5 KGD551+I07L5GE59G3Y4zhmcCh9W52RJqMv46mHbpeKIeOk0SmnaaIuo+3mpk7mWsqzu P1AwY21wVl91ZSZANz8lnF8DURypj5wyYtz+3lXWB1hCpFsQf3rH51jbyLpvROg2l0at p3RJhXpAE3z6aD7rRtAytF37GBV7dC6/7wedbziRZ//xY/k8Pez3AE3hkyEZOwSWXl62 PYpBvCXjSRu0wMs+TSAVQzyiOk7POeOOYQAAVVubTifd8Y0LNvxXpvpggX+MtFFavgI+ izIg== 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=uj1XdCbcxzkSs79Ga7G5B6KO1Z+WtFxPRscDFamxkig=; b=i+VgjbLwZB02A6fo2RYWqfqyg2aDbUj9/DicBquVyXrCJqSGubcdOsqPMbhq1PvJpf qqoEAu+xaLorV2yCn3P9T2G/CBfLFrtKCXz1dA8hPprzIxAWSubqoVy6XtZMN1VhpgV2 hDaIJTzGcGYBSK/Ij+oQpfL0GHCkTJNxA9z0VMU9rqRPtMjv49RCyhyDvj7RnTop+VzS jDQadG8/lcBDv0PJuTNIzKysFY8MtVtO/KsyRIKvF7JYVKpJrf2LmEmWabot6LotMrMe Voegc9QYnb9XPGf8/YziFTy4VG/+WaglAzTnoTpXNzh7z4l/5PWPZLmJRCX/F1sTwDYe dFUg== 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 t2-20020aa7d4c2000000b0050481d3d65asi1808082edr.681.2023.04.13.07.17.12; Thu, 13 Apr 2023 07:17:12 -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 709BD68BE7A; Thu, 13 Apr 2023 17:16:06 +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 8096568BDA5 for ; Thu, 13 Apr 2023 17:16:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 568642406CC for ; Thu, 13 Apr 2023 16:16:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id IBhbw92ywsmQ for ; Thu, 13 Apr 2023 16:15:59 +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 79C872406CF for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6A7603A03E5 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:12 +0200 Message-Id: <20230413141223.17245-14-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg: open decoders right after we know they are needed 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: Ih1J1iq1Ok6M Will allow initializing subtitle encoding earlier. --- fftools/ffmpeg.c | 5 ----- fftools/ffmpeg_demux.c | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d8b06eb724..900d6e5e83 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1882,11 +1882,6 @@ static int transcode_init(void) ifile->streams[j]->start = av_gettime_relative(); } - /* init input streams */ - for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) - if (ist->decoding_needed && (ret = dec_open(ist)) < 0) - goto dump_format; - /* * initialize stream copy and subtitle/data streams. * Encoded AVFrame based streams will get initialized when the first AVFrame diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index d15a714e90..91609509b2 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -566,6 +566,12 @@ static void ist_use(InputStream *ist, int decoding_needed) ist->discard = 0; ist->st->discard = ist->user_set_discard; ist->decoding_needed |= decoding_needed; + + if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) { + int ret = dec_open(ist); + if (ret < 0) + report_and_exit(ret); + } } void ist_output_add(InputStream *ist, OutputStream *ost) From patchwork Thu Apr 13 14:12:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41152 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1287880pzb; Thu, 13 Apr 2023 07:17:26 -0700 (PDT) X-Google-Smtp-Source: AKy350YS3Gpe84xVfoqWIT6COzpXk+0o+yYFZZK7FLMmlTJSPvPr9w857GLVFKeYktAYhtQHZ1vh X-Received: by 2002:a17:906:4f91:b0:932:83fa:d2fe with SMTP id o17-20020a1709064f9100b0093283fad2femr3203420eju.12.1681395445772; Thu, 13 Apr 2023 07:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395445; cv=none; d=google.com; s=arc-20160816; b=sqRnL4po6jligQDoH1bj1lcuLeXcV4EzpFDd1MnsN57hfHeKUSOAZoR8rik2+0Cv5e 7Waq5omfDOLMjA0WKV8jrpt9Kh1a0RmE/i7IwMCj1xMWP+YwF8af/4LsqP/u5YP64DQH St0uP1KcguE9/ZzqobRhbvPj42ovHswejZC4fcVGPtyX5rOkP8lJ2KbUQlIfF2vq9By7 sbV6Nye1psMn83mxYQ2py6VODOVYjn/gSwjvJiH0Y62vnm4/tVptZQiN/Bo0LsG1KSoB gIGW8bpw7joUkR6itO6pvl3jJcstt1zhjGJo099IlLjCOgmQTpWjTDgBPXpnNg+yUEJS IJWQ== 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=xtrSUt+e2zJR36DSRMg7Mc8+p1F6lscrmkjly//5PNA=; b=Ih4g78qM64nNepi/OeXE7wRc6mDks0xeku8efpS+NdfyC2MZeAsX7ReZNQe7XySHmY cHnODJnXc2KXMD7p/k0TPZy7i5PYKuhBzVxZkJUkGhheqthxns2gwxctnOSYaiDJ+VTQ xFsYJpore6GlD0u87WgjC1Csu6uPn5TYi5ksNwi1wHe17WuSQERtJUa95n1/SGJpo2Fr z9WQpBca7Zw+5JOPYZNX3tkokmzL/TaJIXoeqa5dvz9pH5Fp072s+DLHmCX5Qd/stlLJ wZafmw/ZpqgL/OIDj8CWpk5NN6RD0sLKulBGsabbbq1xcEHxlklFo1thq0EvbHYupemp q69A== 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 fe24-20020a1709072a5800b0094e4c2fbb2bsi1925617ejc.656.2023.04.13.07.17.25; Thu, 13 Apr 2023 07:17:25 -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 4248968BE45; Thu, 13 Apr 2023 17:16:07 +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 82C9E68BDCA for ; Thu, 13 Apr 2023 17:16:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EB6132404F8 for ; Thu, 13 Apr 2023 16:16:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Q9lh9K24Ss4P for ; Thu, 13 Apr 2023 16:16: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 853492406D0 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 755923A038E for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:13 +0200 Message-Id: <20230413141223.17245-15-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/25] fftools/ffmpeg: initialize no-filter streams earlier 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: DoaBX/An57mq There is no reason to postpone it until transcode_init() anymore, it can be done right at the end of of_open(). --- fftools/ffmpeg.c | 34 ---------------------------------- fftools/ffmpeg_mux_init.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 900d6e5e83..33b2f72d90 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1853,23 +1853,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo return !eof_reached; } -static int init_output_stream_nofilter(OutputStream *ost) -{ - int ret = 0; - - if (ost->enc_ctx) { - ret = enc_open(ost, NULL); - if (ret < 0) - return ret; - } else { - ret = of_stream_init(output_files[ost->file_index], ost); - if (ret < 0) - return ret; - } - - return ret; -} - static int transcode_init(void) { int ret = 0; @@ -1882,22 +1865,6 @@ static int transcode_init(void) ifile->streams[j]->start = av_gettime_relative(); } - /* - * initialize stream copy and subtitle/data streams. - * Encoded AVFrame based streams will get initialized when the first AVFrame - * is received in do_video_out - */ - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { - if (ost->enc_ctx && - (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || - ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) - continue; - - ret = init_output_stream_nofilter(ost); - if (ret < 0) - goto dump_format; - } - /* discard unused programs */ for (int i = 0; i < nb_input_files; i++) { InputFile *ifile = input_files[i]; @@ -1914,7 +1881,6 @@ static int transcode_init(void) } } - dump_format: /* dump the stream mapping */ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index e3d8f5e386..bc14cabad4 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2314,6 +2314,23 @@ static void validate_enc_avopt(Muxer *mux, const AVDictionary *codec_avopt) av_dict_free(&unused_opts); } +static int init_output_stream_nofilter(OutputStream *ost) +{ + int ret = 0; + + if (ost->enc_ctx) { + ret = enc_open(ost, NULL); + if (ret < 0) + return ret; + } else { + ret = of_stream_init(output_files[ost->file_index], ost); + if (ret < 0) + return ret; + } + + return ret; +} + static const char *output_file_item_name(void *obj) { const Muxer *mux = obj; @@ -2509,6 +2526,21 @@ int of_open(const OptionsContext *o, const char *filename) of->url = filename; + /* initialize stream copy and subtitle/data streams. + * Encoded AVFrame based streams will get initialized when the first AVFrame + * is received in do_video_out + */ + for (int i = 0; i < of->nb_streams; i++) { + OutputStream *ost = of->streams[i]; + + if (ost->filter) + continue; + + err = init_output_stream_nofilter(ost); + if (err < 0) + report_and_exit(err); + } + /* write the header for files with no streams */ if (of->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) { int ret = mux_check_init(mux); From patchwork Thu Apr 13 14:12:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41153 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1288057pzb; Thu, 13 Apr 2023 07:17:38 -0700 (PDT) X-Google-Smtp-Source: AKy350adK4njPa677sDlqfNXEvUSGfxkOVRuP8UL27RlT56igvE+b+97fb/pXWzi4DjTzdYx99cz X-Received: by 2002:a17:906:4c47:b0:94a:4d06:3de3 with SMTP id d7-20020a1709064c4700b0094a4d063de3mr2957516ejw.72.1681395458225; Thu, 13 Apr 2023 07:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395458; cv=none; d=google.com; s=arc-20160816; b=SNN4Mxq5avd50/l4H1QouK9+VwK7d3j7MXvONScVfZhmR9AqNGpJpdeZW+lxtOti4y wm3elUC2xEcZLufLuZB0LveXk0q3pNqZj17xP8MaWF8Wgkz6Oo1expt30DLYDkrieoFE o54GFOsgTsAK2Wfbzts1E1vXXsJXexTaRUycfzchTkuagGcecd5ksODZH2hpDbONeGup 6y7Y0hnk591Kla8JyZBeXdoJWztNdS4s3T92bK0HV+DqkohllO5x90qd1I1N7Ko7c7nm GpfFzcAorVEmA1qoyVkSlt14rX6LddytV4u3+uB9U+d3TwabARL7QWaQNCiRmqyrLzro aIzg== 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=TbK9Ej3+wwmAyp88Z3LhUDsX3kO5LTasEvjmzvliyH8=; b=DHbRsHxcMeJApBIsbFAsdB8T5R+LbLeYNnzjmbozAaxmGTYwxDKnqAuyePG1QvXCqU Ol+vDEDZeENLNjafXqj60S2uD25Fovh/wlv5ljIgBDeaNn72X86FhKekw4EAAna6UQ29 9gVKhiJv7S9RPoyJHafBt+sx3ZA1/ot6OgCqxl594yjgudAY0W0Gx0cbvLFQhJGTr7sR Aqlzt+4/qh3OMnGQy7PwHtKetCXlUkOkggCS7yz5w60sxDp7Puha90NW8RacS+UCnZtz Mdvj0CKVtJ3OYyaiDtCHIuPaFXU9JMSXRpaKQnEoYOhh/msBbcSBw+CF9RI+m1BEJmSd PM4w== 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 ay15-20020a170907900f00b0094e6ded38d7si1921609ejc.0.2023.04.13.07.17.37; Thu, 13 Apr 2023 07:17:38 -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 2D8AB68BE8A; Thu, 13 Apr 2023 17:16:08 +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 DB0C968BD88 for ; Thu, 13 Apr 2023 17:16:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A95582404F8 for ; Thu, 13 Apr 2023 16:16:01 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id o8ickMjBnUmN for ; Thu, 13 Apr 2023 16:16: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 915A5240705 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 812C63A039B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:14 +0200 Message-Id: <20230413141223.17245-16-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: store stream media type in OutputStream 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: zNQGD2O8wJHs Reduces access to a deeply nested muxer property OutputStream.st->codecpar->codec_type for this fundamental and immutable stream property. Besides making the code shorter, this will allow making the AVStream (OutputStream.st) private to the muxer in the future. --- fftools/ffmpeg.c | 4 ++-- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_mux.c | 11 +++++------ fftools/ffmpeg_mux_init.c | 26 ++++++++++++-------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 33b2f72d90..30b42b4fde 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -748,12 +748,12 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti 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) { + if (vid && ost->type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (!vid && ost->type == AVMEDIA_TYPE_VIDEO) { float fps; uint64_t frame_number = atomic_load(&ost->packets_written); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 5833c13812..f08f5db49e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -578,6 +578,8 @@ typedef struct Encoder Encoder; typedef struct OutputStream { const AVClass *class; + enum AVMediaType type; + int file_index; /* file index */ int index; /* stream index in the output file */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index b316925115..eb64d8c3ff 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -62,7 +62,6 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) { MuxStream *ms = ms_from_ost(ost); AVFormatContext *s = mux->fc; - AVStream *st = ost->st; int64_t fs; uint64_t frame_num; int ret; @@ -74,10 +73,10 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) goto fail; } - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP) + if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP) pkt->pts = pkt->dts = AV_NOPTS_VALUE; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (ost->type == AVMEDIA_TYPE_VIDEO) { if (ost->frame_rate.num && ost->is_cfr) { if (pkt->duration > 0) av_log(ost, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n"); @@ -101,12 +100,12 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) - FFMIN3(pkt->pts, pkt->dts, ms->last_mux_dts + 1) - FFMAX3(pkt->pts, pkt->dts, ms->last_mux_dts + 1); } - if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) && + if ((ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO || ost->type == AVMEDIA_TYPE_SUBTITLE) && pkt->dts != AV_NOPTS_VALUE && ms->last_mux_dts != AV_NOPTS_VALUE) { int64_t max = ms->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT); if (pkt->dts < max) { - int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG; + int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG; if (exit_on_error) loglevel = AV_LOG_ERROR; av_log(s, loglevel, "Non-monotonous DTS in output stream " @@ -136,7 +135,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) if (debug_ts) { av_log(ost, AV_LOG_INFO, "muxer <- type:%s " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s size:%d\n", - av_get_media_type_string(st->codecpar->codec_type), + av_get_media_type_string(ost->type), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base), av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ost->st->time_base), diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index bc14cabad4..129973d9f0 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -108,7 +108,7 @@ static int check_opt_bitexact(void *ctx, const AVDictionary *opts, static int choose_encoder(const OptionsContext *o, AVFormatContext *s, OutputStream *ost, const AVCodec **enc) { - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; char *codec_name = NULL; *enc = NULL; @@ -117,7 +117,7 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s, MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st); if (!codec_name) { ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url, - NULL, ost->st->codecpar->codec_type); + NULL, ost->type); *enc = avcodec_find_encoder(ost->st->codecpar->codec_id); if (!*enc) { av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed " @@ -127,7 +127,7 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s, return AVERROR_ENCODER_NOT_FOUND; } } else if (strcmp(codec_name, "copy")) { - *enc = find_codec_or_die(ost, codec_name, ost->st->codecpar->codec_type, 1); + *enc = find_codec_or_die(ost, codec_name, ost->type, 1); ost->st->codecpar->codec_id = (*enc)->id; } } @@ -410,6 +410,7 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) ms->ost.file_index = mux->of.index; ms->ost.index = mux->of.nb_streams - 1; + ms->ost.type = type; ms->ost.class = &output_stream_class; @@ -422,8 +423,6 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost) { - AVStream *st = ost->st; - if (ost->filters_script && ost->filters) { av_log(ost, AV_LOG_ERROR, "Both -filter and -filter_script set\n"); exit_program(1); @@ -434,8 +433,7 @@ static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc, else if (ost->filters) return av_strdup(ost->filters); - return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? - "null" : "anull"); + return av_strdup(ost->type == AVMEDIA_TYPE_VIDEO ? "null" : "anull"); } static void check_streamcopy_filters(const OptionsContext *o, AVFormatContext *oc, @@ -1594,7 +1592,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u for (int i = 0; i < oc->nb_streams; i++) { OutputStream *ost = of->streams[i]; MuxStream *ms = ms_from_ost(ost); - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; ost->sq_idx_encode = -1; ost->sq_idx_mux = -1; @@ -1628,7 +1626,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u for (int i = 0; i < oc->nb_streams; i++) { OutputStream *ost = of->streams[i]; MuxStream *ms = ms_from_ost(ost); - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; if (!IS_AV_ENC(ost, type)) continue; @@ -1657,7 +1655,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u for (int i = 0; i < oc->nb_streams; i++) { OutputStream *ost = of->streams[i]; MuxStream *ms = ms_from_ost(ost); - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; if (!IS_INTERLEAVED(type)) continue; @@ -2113,7 +2111,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - nb_streams[ost->st->codecpar->codec_type]++; + nb_streams[ost->type]++; MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st); @@ -2123,7 +2121,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) ost->st->disposition = ost->ist->st->disposition; if (ost->st->disposition & AV_DISPOSITION_DEFAULT) - have_default[ost->st->codecpar->codec_type] = 1; + have_default[ost->type] = 1; } } @@ -2146,7 +2144,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) // "Suitable" means the first of that type, skipping attached pictures. for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; if (nb_streams[type] < 2 || have_default[type] || ost->st->disposition & AV_DISPOSITION_ATTACHED_PIC) @@ -2239,7 +2237,7 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st); - if (!(ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + if (!(ost->type == AVMEDIA_TYPE_VIDEO && ost->enc_ctx && forced_keyframes)) continue; From patchwork Thu Apr 13 14:12:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41158 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1290696pzb; Thu, 13 Apr 2023 07:20:48 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgMXyohvABUmSmtT8E0/Pjdq6QTArIYvCNy0qw8cO3HIEqjZBxmbz6hGg2LxLodggrFv7U X-Received: by 2002:aa7:c90d:0:b0:504:9379:718a with SMTP id b13-20020aa7c90d000000b005049379718amr2283406edt.38.1681395648288; Thu, 13 Apr 2023 07:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395648; cv=none; d=google.com; s=arc-20160816; b=wiIxAGNQmKTQVrY464gevA6r/OhW1JS8x7bxrWVrYhCI+JeWOPAQjYbODjkqGxLReW w8V0OvqruK7vCxWAwQOl2/qsdMq3fGVz0JD38fFw4+pbXekDsnjCTU9noGmZZ5EZGhIP uJPd30lY16dZdGOIG7FhSYpdWo7ag+1mbKWcWvR1uGLbOoAUeGBEjJvsXk7G8HD0onx+ TQWuoLULxjyv/J6T/2J+Hm1ut5mBJw3Fs5tB2PAohDX/wWFh1MapEVzFa6iDABCpKFjL Imu0JCMH9L5oZB4Y5ZRZD4ZZffweY+mMrUefMXIOAA9nuv5xS6cwg8/V6FwcB0KwB1M8 8cGw== 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=wzBDxdGBkLuqs/wOcm8w+QqJbYEjR3k/CeOBp2CEYI0=; b=SnwPM5spBOu7692HNNIKmiVorbEtpjDMBS0IVYi4zDpy1/xpmyQ5WrEBkJQm+M5Zp1 81fnQlQ5BoAhLQKuguYhH37/2cgxgnAF9EVbpE49JlLOsv5gHMSYSStdVFOWaoQwjXQn 3jaddXVQ4GJN7RlrJKtGDIuFQ+TwzHrQamncqGLf1jMr+yKx6S5iMdgcjVc5uNb9x2Ro Nb4j6HKUgqdAFVyLU+ufGzG3eUFr8y5BcBgfDdm+BtX7a4hZecDFVDXLVUONL4IRyBK9 R23ls/8aQEgNKCgwS/5RS6faxIJXrqYkwFIzEFKXFVR5Fe7bFdXSdW/p6ydYyuJHXV6+ ys+A== 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 w4-20020a50fa84000000b0050480f6caf9si1893226edr.62.2023.04.13.07.20.47; Thu, 13 Apr 2023 07:20:48 -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 4859F68BEFF; Thu, 13 Apr 2023 17:16:21 +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 EE9CF68BEAB for ; Thu, 13 Apr 2023 17:16:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BCB292406CC for ; Thu, 13 Apr 2023 16:16:02 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 9fVoOqOLYqIB for ; Thu, 13 Apr 2023 16:16: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 9CA1C240706 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8CEA13A03E5 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:15 +0200 Message-Id: <20230413141223.17245-17-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/25] fftools/ffmpeg: add muxer-input codec parameters to OutputStream 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: 7hTzmUiZXv++ It stores codec parameters of the stream submitted to the muxer, which may be different from the codec parameters in AVStream due to bitstream filtering. This avoids the confusing back and forth synchronisation between the encoder, bitstream filters, and the muxer, now information flows only in one direction. It also reduces the need for non-muxing code to access AVStream. --- fftools/ffmpeg.h | 6 ++++++ fftools/ffmpeg_enc.c | 2 +- fftools/ffmpeg_mux.c | 6 ++++-- fftools/ffmpeg_mux_init.c | 21 +++++++++++++-------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index f08f5db49e..8ec0f1b3f3 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -583,6 +583,12 @@ typedef struct OutputStream { int file_index; /* file index */ int index; /* stream index in the output file */ + /** + * Codec parameters for packets submitted to the muxer (i.e. before + * bitstream filtering, if any). + */ + AVCodecParameters *par_in; + /* input stream that is the source for this output stream; * may be NULL for streams with no well-defined source, e.g. * attachments or outputs from complex filtergraphs */ diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 063053623f..2462f53a82 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -354,7 +354,7 @@ int enc_open(OutputStream *ost, AVFrame *frame) av_log(ost, AV_LOG_WARNING, "The bitrate parameter is set too low." " It takes bits/s as argument, not kbits/s\n"); - ret = avcodec_parameters_from_context(ost->st->codecpar, ost->enc_ctx); + ret = avcodec_parameters_from_context(ost->par_in, ost->enc_ctx); if (ret < 0) { av_log(ost, AV_LOG_FATAL, "Error initializing the output stream codec context.\n"); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index eb64d8c3ff..40b439eea2 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -556,9 +556,9 @@ static int bsf_init(MuxStream *ms) int ret; if (!ctx) - return 0; + return avcodec_parameters_copy(ost->st->codecpar, ost->par_in); - ret = avcodec_parameters_copy(ctx->par_in, ost->st->codecpar); + ret = avcodec_parameters_copy(ctx->par_in, ost->par_in); if (ret < 0) return ret; @@ -768,6 +768,8 @@ static void ost_free(OutputStream **post) av_fifo_freep2(&ms->muxing_queue); } + avcodec_parameters_free(&ost->par_in); + av_bsf_free(&ms->bsf_ctx); av_frame_free(&ost->filtered_frame); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 129973d9f0..33d5268949 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -116,19 +116,19 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s, if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) { MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st); if (!codec_name) { - ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url, + ost->par_in->codec_id = av_guess_codec(s->oformat, NULL, s->url, NULL, ost->type); - *enc = avcodec_find_encoder(ost->st->codecpar->codec_id); + *enc = avcodec_find_encoder(ost->par_in->codec_id); if (!*enc) { av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed " "Default encoder for format %s (codec %s) is " "probably disabled. Please choose an encoder manually.\n", - s->oformat->name, avcodec_get_name(ost->st->codecpar->codec_id)); + s->oformat->name, avcodec_get_name(ost->par_in->codec_id)); return AVERROR_ENCODER_NOT_FOUND; } } else if (strcmp(codec_name, "copy")) { *enc = find_codec_or_die(ost, codec_name, ost->type, 1); - ost->st->codecpar->codec_id = (*enc)->id; + ost->par_in->codec_id = (*enc)->id; } } @@ -844,7 +844,7 @@ static int streamcopy_init(const Muxer *mux, const OptionsContext *o, const InputStream *ist = ost->ist; const InputFile *ifile = input_files[ist->file_index]; - AVCodecParameters *par = ost->st->codecpar; + AVCodecParameters *par = ost->par_in; uint32_t codec_tag = par->codec_tag; AVCodecContext *codec_ctx = NULL; @@ -995,6 +995,10 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, ms = mux_stream_alloc(mux, type); ost = &ms->ost; + ost->par_in = avcodec_parameters_alloc(); + if (!ost->par_in) + report_and_exit(AVERROR(ENOMEM)); + ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0); if (!ms->muxing_queue) report_and_exit(AVERROR(ENOMEM)); @@ -1003,6 +1007,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, ost->st = st; ost->ist = ist; ost->kf.ref_pts = AV_NOPTS_VALUE; + ost->par_in->codec_type = type; st->codecpar->codec_type = type; ret = choose_encoder(o, oc, ost, &enc); @@ -1166,7 +1171,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, uint32_t tag = strtol(codec_tag, &next, 0); if (*next) tag = AV_RL32(codec_tag); - ost->st->codecpar->codec_tag = tag; + ost->par_in->codec_tag = tag; if (ost->enc_ctx) ost->enc_ctx->codec_tag = tag; } @@ -1520,8 +1525,8 @@ static void of_add_attachments(Muxer *mux, const OptionsContext *o) ost = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL); ost->attachment_filename = o->attachments[i]; - ost->st->codecpar->extradata = attachment; - ost->st->codecpar->extradata_size = len; + ost->par_in->extradata = attachment; + ost->par_in->extradata_size = len; p = strrchr(o->attachments[i], '/'); av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE); From patchwork Thu Apr 13 14:12:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41154 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1288225pzb; Thu, 13 Apr 2023 07:17:51 -0700 (PDT) X-Google-Smtp-Source: AKy350bsx7qQbIs9tIfl5DLtadNhsuCuq+0n0i2dR4t+OgHQ4I8W/0nPQhyp85V7XTuMHVKkBK9A X-Received: by 2002:a17:906:480f:b0:94a:7225:92f with SMTP id w15-20020a170906480f00b0094a7225092fmr2751587ejq.11.1681395471409; Thu, 13 Apr 2023 07:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395471; cv=none; d=google.com; s=arc-20160816; b=O/2+pawHEGGkoCaojbSjntrOAgy/j5N+nSssVg+UfP0cYmr/kM2G/eJzcdLZx1G9Ij Fu0luBQZuJI9mbMheMDTvhLPF6AfJKI7wPfpRdBx0OQeqF4AoASEBEP21rYPsTzWzQpB WpSUDlppbHk1aTxmMos86Nm0gO7TY1oFHsVNwE1cJlqER7fmpnYeAWBAPP1aHmgr2Vli NcYyJgL1Ya1BRpApI4DTscSf9u6waajjJsgdmgQn4pRIf1MLJ79wI5Llq7Lnj4+up8B6 ve/Q+jcAx0wiyaL2ScX+rmkHXss8PP9GVB7qoXs/0a5y5Ar2utu/9jF1tUfjosEKNNBd ULdg== 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=eCgRPup9df0XV6uB+VCFNZ26QDqZdLRmCIsM0A2+RCM=; b=YCxxI58odSANdPhqAIHzs4abqgWiRePE5zfrvx/9CI4Rnr/d6ITNFmwxJNQn0M0Sxz UQzBs4zDZbKHTG7XnO8mfaZ5OVsri6Sk4LLP34gTAGMmfTtXkVcxVLTB+cOxVrfiGwpy KDSNUK1NWX5SEvgDl+80p0NtRMQFTMU269H+qD/kS9y1v4a0JYQuq+m7TbS2b9/VesQR N9MEIha27usKF/+IaekO4kDWKBKSwzU5BOMC1wEROQ29GE/MooFCoP7iwdBYVHeVW1Ms q8bvyEe73gRVSpbvY66E+eQgwBHhmOTtVy5oSNZ2Fzs8ZA3bVjpBgu0yWUcQGFLy/qTX lq+A== 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 mf23-20020a1709071a5700b0094a698a7a28si1831754ejc.666.2023.04.13.07.17.50; Thu, 13 Apr 2023 07:17:51 -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 2584368BEBC; Thu, 13 Apr 2023 17:16: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 BB28068BE0A for ; Thu, 13 Apr 2023 17:16:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7A0482404F8 for ; Thu, 13 Apr 2023 16:16:02 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id o5qu4u-HZUhe for ; Thu, 13 Apr 2023 16:16:01 +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 A7B13240D03 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 986CF3A038E for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:16 +0200 Message-Id: <20230413141223.17245-18-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/25] fftools/ffmpeg: move do_streamcopy() to ffmpeg_mux 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: AQRqyXxGyOAP do_streamcopy() is muxing code, so this is a more appropriate place for this. The last uses of InputStream in it will be removed in following commits. --- fftools/ffmpeg.c | 81 +------------------------------------------- fftools/ffmpeg.h | 7 ++++ fftools/ffmpeg_mux.c | 76 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 80 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 30b42b4fde..92cc98b089 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -914,85 +914,6 @@ int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *pa return 0; } -/** - * @param dts predicted packet dts in AV_TIME_BASE_Q - */ -static void do_streamcopy(InputStream *ist, OutputStream *ost, - const AVPacket *pkt, int64_t dts) -{ - OutputFile *of = output_files[ost->file_index]; - int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; - int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase); - AVPacket *opkt = ost->pkt; - - av_packet_unref(opkt); - // EOF: flush output bitstream filters. - if (!pkt) { - of_output_packet(of, opkt, ost, 1); - return; - } - - if (!ost->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) && - !ost->copy_initial_nonkeyframes) - return; - - if (!ost->streamcopy_started) { - if (!ost->copy_prior_start && - (pkt->pts == AV_NOPTS_VALUE ? - dts < ost->ts_copy_start : - pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, pkt->time_base))) - return; - - if (of->start_time != AV_NOPTS_VALUE && dts < of->start_time) - return; - } - - if (of->recording_time != INT64_MAX && - dts >= of->recording_time + start_time) { - close_output_stream(ost); - return; - } - - if (av_packet_ref(opkt, pkt) < 0) - exit_program(1); - - opkt->time_base = ost->mux_timebase; - - if (pkt->pts != AV_NOPTS_VALUE) - opkt->pts = av_rescale_q(pkt->pts, pkt->time_base, opkt->time_base) - ost_tb_start_time; - - if (pkt->dts == AV_NOPTS_VALUE) { - opkt->dts = av_rescale_q(dts, AV_TIME_BASE_Q, opkt->time_base); - } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - int duration = av_get_audio_frame_duration2(ist->par, pkt->size); - if(!duration) - duration = ist->par->frame_size; - opkt->dts = av_rescale_delta(pkt->time_base, pkt->dts, - (AVRational){1, ist->par->sample_rate}, duration, - &ist->filter_in_rescale_delta_last, opkt->time_base); - /* dts will be set immediately afterwards to what pts is now */ - opkt->pts = opkt->dts - ost_tb_start_time; - } else - opkt->dts = av_rescale_q(pkt->dts, pkt->time_base, opkt->time_base); - opkt->dts -= ost_tb_start_time; - - opkt->duration = av_rescale_q(pkt->duration, pkt->time_base, opkt->time_base); - - { - int ret = trigger_fix_sub_duration_heartbeat(ost, pkt); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, - "Subtitle heartbeat logic failed in %s! (%s)\n", - __func__, av_err2str(ret)); - exit_program(1); - } - } - - of_output_packet(of, opkt, ost, 0); - - ost->streamcopy_started = 1; -} - static void check_decode_result(InputStream *ist, int *got_output, int ret) { if (*got_output || ret<0) @@ -1847,7 +1768,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo continue; } - do_streamcopy(ist, ost, pkt, ist->dts); + of_streamcopy(ist, ost, pkt, ist->dts); } return !eof_reached; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8ec0f1b3f3..46b4614ec4 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -872,6 +872,13 @@ void of_enc_stats_close(void); * must be supplied in this case. */ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof); + +/** + * @param dts predicted packet dts in AV_TIME_BASE_Q + */ +void of_streamcopy(InputStream *ist, OutputStream *ost, + const AVPacket *pkt, int64_t dts); + int64_t of_filesize(OutputFile *of); int ifile_open(const OptionsContext *o, const char *filename); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 40b439eea2..96ed50f73c 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -378,6 +378,82 @@ fail: } +void of_streamcopy(InputStream *ist, OutputStream *ost, + const AVPacket *pkt, int64_t dts) +{ + OutputFile *of = output_files[ost->file_index]; + int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; + int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase); + AVPacket *opkt = ost->pkt; + + av_packet_unref(opkt); + // EOF: flush output bitstream filters. + if (!pkt) { + of_output_packet(of, opkt, ost, 1); + return; + } + + if (!ost->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) && + !ost->copy_initial_nonkeyframes) + return; + + if (!ost->streamcopy_started) { + if (!ost->copy_prior_start && + (pkt->pts == AV_NOPTS_VALUE ? + dts < ost->ts_copy_start : + pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, pkt->time_base))) + return; + + if (of->start_time != AV_NOPTS_VALUE && dts < of->start_time) + return; + } + + if (of->recording_time != INT64_MAX && + dts >= of->recording_time + start_time) { + close_output_stream(ost); + return; + } + + if (av_packet_ref(opkt, pkt) < 0) + exit_program(1); + + opkt->time_base = ost->mux_timebase; + + if (pkt->pts != AV_NOPTS_VALUE) + opkt->pts = av_rescale_q(pkt->pts, pkt->time_base, opkt->time_base) - ost_tb_start_time; + + if (pkt->dts == AV_NOPTS_VALUE) { + opkt->dts = av_rescale_q(dts, AV_TIME_BASE_Q, opkt->time_base); + } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + int duration = av_get_audio_frame_duration2(ist->par, pkt->size); + if(!duration) + duration = ist->par->frame_size; + opkt->dts = av_rescale_delta(pkt->time_base, pkt->dts, + (AVRational){1, ist->par->sample_rate}, duration, + &ist->filter_in_rescale_delta_last, opkt->time_base); + /* dts will be set immediately afterwards to what pts is now */ + opkt->pts = opkt->dts - ost_tb_start_time; + } else + opkt->dts = av_rescale_q(pkt->dts, pkt->time_base, opkt->time_base); + opkt->dts -= ost_tb_start_time; + + opkt->duration = av_rescale_q(pkt->duration, pkt->time_base, opkt->time_base); + + { + int ret = trigger_fix_sub_duration_heartbeat(ost, pkt); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Subtitle heartbeat logic failed in %s! (%s)\n", + __func__, av_err2str(ret)); + exit_program(1); + } + } + + of_output_packet(of, opkt, ost, 0); + + ost->streamcopy_started = 1; +} + static int thread_stop(Muxer *mux) { void *ret; From patchwork Thu Apr 13 14:12:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41167 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1290919pzb; Thu, 13 Apr 2023 07:21:05 -0700 (PDT) X-Google-Smtp-Source: AKy350b6WAX6fN08DdpIB64AaRM+dlsv8y69dGtqotXW+04VfEow1LAEGityIP6qZhSlGzRswJGS X-Received: by 2002:a17:906:fa0c:b0:94a:785e:6a46 with SMTP id lo12-20020a170906fa0c00b0094a785e6a46mr3161125ejb.24.1681395665482; Thu, 13 Apr 2023 07:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395665; cv=none; d=google.com; s=arc-20160816; b=N4mpQH304+eO4LQad9vjTxq7mD5iag+pLHq+6LOuNj8QVKWlsK2m9Je+vlA58dQyGf oJ84S3thvejBm/yQFRxwR82SUlAGThx7Ud0tDnDttzLy0+nBAXef01taJbUGUeQHFjjM 8GAxMi0724ClFQpBqtjgImbUFBBt3ZRJCFqJeDa8WHh1QDwtxZnh0zztL6FANMGd3RG9 sBDxyc/8C4CmhXSiNj20FSgxl3RvxO10xQhq71sN2CFiqvG7Na/y8bqZexVrfOxW0iTV B96VXFjJkvKqz+MKEtOJzttE6dY3QPO+XaTB/0OTJNOtPsr5ZNecZUtx3h6tvD+385AP Rh7A== 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=faaBt8wgeyVwl/4eFom8wgDfK/SVCsZmiQilA3wsYXY=; b=YGs35YqFu1Jz27ltpNjBu5GgINjbN1fgK03HXTkTWfRRPsSn6RfprpjOuPuGkqVSro Y+pUS8Ejup2YLc9YvQvlWmYIuHByY0XyRt1BCYsVybpwC/MmMylSsY2kXKBg0AMI0vXh 1pmyPRnSDPM9RvLe13ehseUoy8VnKLfgzSPMcJozZYIUkGmD40hth0GLwUYTzdbmdse4 UOaaT1M2SJew172LmpYjub9ARIggpyVOpCLpJAONLqNcyDvYCOaijrlhtXLlvYBpDxwm vmvI/LQNNN88trGtIeni0C6Ced3TA+jOF77+JePiG23jPILOQoE7yVWlj5JpEAaGNTEa 8Dqw== 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 ft31-20020a170907801f00b0094ecfcf52desi13953ejc.869.2023.04.13.07.21.05; Thu, 13 Apr 2023 07:21:05 -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 807DB68BF06; Thu, 13 Apr 2023 17:16:22 +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 2DB8768BEAB for ; Thu, 13 Apr 2023 17:16:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F1EED2404F8 for ; Thu, 13 Apr 2023 16:16:02 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Pe3ZI_TXyYPL for ; Thu, 13 Apr 2023 16:16:02 +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 B2B74240D0E for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A369C3A039B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:17 +0200 Message-Id: <20230413141223.17245-19-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg_mux: use output stream parameters in of_streamcopy() 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: JHhEvHqjBLFB They should always be the same as the input stream parameters, but this reduces the need to access InputStream in muxing code. --- fftools/ffmpeg_mux.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 96ed50f73c..db6ad9d589 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -425,11 +425,11 @@ void of_streamcopy(InputStream *ist, OutputStream *ost, if (pkt->dts == AV_NOPTS_VALUE) { opkt->dts = av_rescale_q(dts, AV_TIME_BASE_Q, opkt->time_base); } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - int duration = av_get_audio_frame_duration2(ist->par, pkt->size); + int duration = av_get_audio_frame_duration2(ost->par_in, pkt->size); if(!duration) - duration = ist->par->frame_size; + duration = ost->par_in->frame_size; opkt->dts = av_rescale_delta(pkt->time_base, pkt->dts, - (AVRational){1, ist->par->sample_rate}, duration, + (AVRational){1, ost->par_in->sample_rate}, duration, &ist->filter_in_rescale_delta_last, opkt->time_base); /* dts will be set immediately afterwards to what pts is now */ opkt->pts = opkt->dts - ost_tb_start_time; From patchwork Thu Apr 13 14:12:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41168 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1291139pzb; Thu, 13 Apr 2023 07:21:22 -0700 (PDT) X-Google-Smtp-Source: AKy350ZTM9O5SFfMDhzSqj6Blw03ib7xIbdj8CMtChmmdd8GToIuKps3hTcghOZQNjHP6mNNn7iD X-Received: by 2002:aa7:d04e:0:b0:505:7d54:db93 with SMTP id n14-20020aa7d04e000000b005057d54db93mr3042465edo.21.1681395682034; Thu, 13 Apr 2023 07:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395682; cv=none; d=google.com; s=arc-20160816; b=bYXv7Q6ykE1IKP0I2DT/DTmRmttVhc1kdStaqjkdvZVWQgcBe2kA1I1s4Bt6Rv4qJ5 VMj0V2FUj/vxgkuVg/HsRHmV5KOnUaDbpS95dUlycU7mC3bv9MiO/aWnX62nkddye4Hg LiDUKKNSPbc0qKgm2NEYFMt/Fni1DvtAjIrPcBPiKh1fwqgGsDgORwrrFEzPU41hR8Gs dQ7n3FFwSbCcrGfVHeZZ6jJDan5I/EoNiszj8Gldz4TII25uYrVEdYEscAQN6bcSrnX0 ZBPnAR2rnPeFXHOlCc9VPOrJZXSxphRUXAuCLAowHSFGv26tQvwshcLeSnQZk+GZo1GK PmHg== 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=7xYnsXZWWD3Eg9vojiKRVGNpXH2HAUfBfO77vMZGG4s=; b=PI2QawlzZUb2efqwaIB8Luv6Q1ufe2+F3CFX84lVwptnFmdAMCSIcaY8hn5WWYVcGS rB4VxHSAgOPiNIhFNbgtwVS+VvJkSsdqi1nou+IXi10ruCBIoSqoxrTSGDtYUz+ynkOu BLR33hgmM1PC9SPrE7JoQnX+D6ZENRHmOfEHW84isZKag9MkRAqN+ye+PXI5kY277vq4 lxtqwgxJcWLC35/cmnMCfBhWyfUZBCcuSZ3vMnrbNGYHa2fb8MIHZe+4JF6gwDz1LUQs fpDwCpYf3WnCBEV9091w530g/FduEYal8AjM/FYX1rPeDOMjz2iSlP7vAZnmzw+HqT74 KRng== 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 ep21-20020a1709069b5500b009094a93d9b7si1964238ejc.990.2023.04.13.07.21.21; Thu, 13 Apr 2023 07:21:22 -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 8C9F268BF11; Thu, 13 Apr 2023 17:16:23 +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 836FD68BE34 for ; Thu, 13 Apr 2023 17:16:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4C4102406CD for ; Thu, 13 Apr 2023 16:16:03 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id AfnQyxTUrenO for ; Thu, 13 Apr 2023 16:16:02 +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 BDD41240D1A for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AECC73A03E5 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:18 +0200 Message-Id: <20230413141223.17245-20-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/25] fftools/ffmpeg_mux: stop using filter_in_rescale_delta_last for streamcopy 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: AMYVX7rc7GVk That field was added to store timestamp conversion state for audio decoding code. Later it started being used by streamcopy as well, but that use is wrong because, for a given input stream, both decoding and an arbitrary number of streamcopies may be performed simultaneously. They would then all overwrite the same state variable. Store this state in MuxStream instead. This is the last use of InputStream in of_streamcopy(), so the ist parameter can now be removed. --- fftools/ffmpeg.c | 2 +- fftools/ffmpeg.h | 3 +-- fftools/ffmpeg_mux.c | 6 +++--- fftools/ffmpeg_mux.h | 3 +++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 92cc98b089..67c504470a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1768,7 +1768,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo continue; } - of_streamcopy(ist, ost, pkt, ist->dts); + of_streamcopy(ost, pkt, ist->dts); } return !eof_reached; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 46b4614ec4..6ad3245166 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -876,8 +876,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) /** * @param dts predicted packet dts in AV_TIME_BASE_Q */ -void of_streamcopy(InputStream *ist, OutputStream *ost, - const AVPacket *pkt, int64_t dts); +void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts); int64_t of_filesize(OutputFile *of); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index db6ad9d589..8c710c2eac 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -378,10 +378,10 @@ fail: } -void of_streamcopy(InputStream *ist, OutputStream *ost, - const AVPacket *pkt, int64_t dts) +void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) { OutputFile *of = output_files[ost->file_index]; + MuxStream *ms = ms_from_ost(ost); int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase); AVPacket *opkt = ost->pkt; @@ -430,7 +430,7 @@ void of_streamcopy(InputStream *ist, OutputStream *ost, duration = ost->par_in->frame_size; opkt->dts = av_rescale_delta(pkt->time_base, pkt->dts, (AVRational){1, ost->par_in->sample_rate}, duration, - &ist->filter_in_rescale_delta_last, opkt->time_base); + &ms->ts_rescale_delta_last, opkt->time_base); /* dts will be set immediately afterwards to what pts is now */ opkt->pts = opkt->dts - ost_tb_start_time; } else diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 3fab74b2ed..e8c4ea4847 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -64,6 +64,9 @@ typedef struct MuxStream { * used for making up missing dts values */ int64_t last_mux_dts; + // audio streamcopy - state for av_rescale_delta() + int64_t ts_rescale_delta_last; + // combined size of all the packets sent to the muxer uint64_t data_size_mux; } MuxStream; From patchwork Thu Apr 13 14:12:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41170 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1291798pzb; Thu, 13 Apr 2023 07:22:04 -0700 (PDT) X-Google-Smtp-Source: AKy350a0SWVkxXkO/pkaUSTxMx9HenIdtv5c1aqWpP8iWgcPr0qkClUb3MyDcTfbwDiEAoVubTR0 X-Received: by 2002:a17:906:16c7:b0:931:f9f8:d4ea with SMTP id t7-20020a17090616c700b00931f9f8d4eamr2888008ejd.53.1681395724681; Thu, 13 Apr 2023 07:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395724; cv=none; d=google.com; s=arc-20160816; b=KMoX/93ehPFkVRPEKH00Vm0jMhnvtcg4xco+kF4oqQAZnKv1ttq//QnIr89qTAW56j 8PTlJsTu+gPX9C37cL11W6BO4mxpCDOP/WELo+o1GH0lElscGjuNKVncb2+JXildw0gP Wa19ZQvdD2MIS4MOOJPwmA+OLBG8NtEfvv4sHY5rJGIJCnzCBb624PWTIu0X1lAByXAi ZEu3AEaqLqAdSOsIHeyJASQARQXaflEuHBuzDtRejbICb5zADqd9zVGJAwsG5wOWI2TH DCpGFa8AjBYLBki8Q8gaA689eHVmHD4qNpH+EoTrHUmJDzNQdiURnvMfwgdc7V9CTLvO vs4w== 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=sUySkzQqxhO4+RnpJZIbMDY2SjLt7AuTYKuA81Lf/Qg=; b=SyE4WIdJrQEFvSuWPlqBh6v6a2w2F1Uo/DYHlMHym1U+LDB+EzmZ593zBharO9dRjx E+dGWSD2CjsQT/xBW1ia0+NVqqBdM0eCsg9W1wXpumE1mKtopJgotWSsGNDQ0MkYBHCN qAc+hqKYUJmPhJFbFcteThHmlCXq0MCgEUCg3OwHJbxCo4hShWiVLqVkoM9QaC33Aoeo SRfhR7skKBY2+qjC7vDyCETwsZsMFlu3h2G/KohMqZraOIT4K3hgfD+52AKOiI31MQDV qFCg8Sfz3N1w7EaqI16+5NQXgh2ry/VfUNyLO7NAvEqtknO9Yh9smqP4f0NKUOOtivBs Az0g== 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 l15-20020a170907914f00b0094e3d6f1bc5si1834376ejs.297.2023.04.13.07.22.03; Thu, 13 Apr 2023 07:22:04 -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 A1C9768BF1F; Thu, 13 Apr 2023 17:16:25 +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 1ED5468BEB3 for ; Thu, 13 Apr 2023 17:16:04 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D57CC2406D0 for ; Thu, 13 Apr 2023 16:16:03 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id R_7GshfUWMxK for ; Thu, 13 Apr 2023 16:16: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 C937B240D1B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B9A823A038E for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:19 +0200 Message-Id: <20230413141223.17245-21-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg_mux: make ts_copy_start private to muxing code 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: f5PboLp4rfb0 It is no longer used outside of ffmpeg_mux* --- fftools/ffmpeg.h | 5 ----- fftools/ffmpeg_mux.c | 4 ++-- fftools/ffmpeg_mux.h | 5 +++++ fftools/ffmpeg_mux_init.c | 10 ++++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6ad3245166..e626fac18a 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -598,11 +598,6 @@ typedef struct OutputStream { /* dts of the last packet sent to the muxing queue, in AV_TIME_BASE_Q */ int64_t last_mux_dts; - // timestamp from which the streamcopied streams should start, - // in AV_TIME_BASE_Q; - // everything before it should be discarded - int64_t ts_copy_start; - // the timebase of the packets sent to the muxer AVRational mux_timebase; AVRational enc_timebase; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 8c710c2eac..d832116c12 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -400,8 +400,8 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) if (!ost->streamcopy_started) { if (!ost->copy_prior_start && (pkt->pts == AV_NOPTS_VALUE ? - dts < ost->ts_copy_start : - pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, pkt->time_base))) + dts < ms->ts_copy_start : + pkt->pts < av_rescale_q(ms->ts_copy_start, AV_TIME_BASE_Q, pkt->time_base))) return; if (of->start_time != AV_NOPTS_VALUE && dts < of->start_time) diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index e8c4ea4847..25cf1b547f 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -60,6 +60,11 @@ typedef struct MuxStream { /* Threshold after which max_muxing_queue_size will be in effect */ size_t muxing_queue_data_threshold; + // timestamp from which the streamcopied streams should start, + // in AV_TIME_BASE_Q; + // everything before it should be discarded + int64_t ts_copy_start; + /* dts of the last packet sent to the muxer, in the stream timebase * used for making up missing dts values */ int64_t last_mux_dts; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 33d5268949..48efaef664 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -841,6 +841,8 @@ static void new_stream_subtitle(Muxer *mux, const OptionsContext *o, static int streamcopy_init(const Muxer *mux, const OptionsContext *o, OutputStream *ost) { + MuxStream *ms = ms_from_ost(ost); + const InputStream *ist = ost->ist; const InputFile *ifile = input_files[ist->file_index]; @@ -907,11 +909,11 @@ static int streamcopy_init(const Muxer *mux, const OptionsContext *o, ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); if (!ost->copy_prior_start) { - ost->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ? - 0 : mux->of.start_time; + ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ? + 0 : mux->of.start_time; if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) { - ost->ts_copy_start = FFMAX(ost->ts_copy_start, - ifile->start_time + ifile->ts_offset); + ms->ts_copy_start = FFMAX(ms->ts_copy_start, + ifile->start_time + ifile->ts_offset); } } From patchwork Thu Apr 13 14:12:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41169 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1291455pzb; Thu, 13 Apr 2023 07:21:42 -0700 (PDT) X-Google-Smtp-Source: AKy350Z8rgvuzgQA+J0GF3psWp+F5dYC9pArh5yWouMb3TercsfDC+n6Ev3zmgkqmmetnt/KP0IV X-Received: by 2002:a17:906:8e8e:b0:93e:5baa:d443 with SMTP id ru14-20020a1709068e8e00b0093e5baad443mr2834709ejc.63.1681395701989; Thu, 13 Apr 2023 07:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395701; cv=none; d=google.com; s=arc-20160816; b=fCkzX0z9lbAuf/tLnPokgJ8PW27PIJ9fFHMeUvsblBUiOLhY3gj7i9mxeWj9eFDMke gAOLgxeSVK30Y9dK2fdDTFjH8eVJhliYpXKAqPcr9PZZb3gvSmQ6bdBp13hK4goGgyag hXXiy7fsqv2Jt8jWrYRKySFfBmRtWq1+ABw/pgFbJZOjIcG0kCkekeJXxYmyNZwGj/Px Rd1i0txgrkVdOqekzQo3Xrgv+7nZzezU1AE963KTgj78FAgDL2HngF9Guoa9K0ygihLz PVgO5Z45oUeD+U8TyDcNJtVabHTv0cPn8t5U83yC3ld6jqKgR0CCd0+kiOcnziGS5mVm 5cyw== 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=qJ3F09cxp+mRLfwv4lWv5i2aYqPr6mixs1W8vSjsz14=; b=kJsE5Wo6BWuBoFac/PKQFmRPCAsDLQ0Pjy22YiJ7hj27f/4kjocLEYpuO00QQ9Nh3D RqErCO9Zsk4AUzRBnk6tXf/KDbnjbyihUNmDyOohmnTJqQxpEe/eum7t9cQTA8W8bkCr dWRir2VcS9dHkT+DFyC+/Pnrlic8N07LwW2WXuMXRfNoKKxfAu63kjTSTmDynpJ/0AAP 8sSJNjzG9mbsWnVYjjy7hFR+yffXE002/6NtedYHW5HmKpsJMny++Gd7e/R9GMmQkQlP 5rrfIbQRQy7+ws2ctyY1VKVUwKOi9PXyIrljp7/kEaezws0EnFRZEz0OpLwgrfJhi91z 1tfQ== 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 fc10-20020a1709073a4a00b0094e8adc1eb7si1808855ejc.672.2023.04.13.07.21.41; Thu, 13 Apr 2023 07:21:41 -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 914BC68BF18; Thu, 13 Apr 2023 17:16: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 A8E2C68BE34 for ; Thu, 13 Apr 2023 17:16:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6ED3B2406CF for ; Thu, 13 Apr 2023 16:16:03 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id C045EE9Gj96v for ; Thu, 13 Apr 2023 16:16: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 D2D43240D1C for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C45393A039B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:20 +0200 Message-Id: <20230413141223.17245-22-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/25] fftools/ffmpeg_mux: make streamcopy_started private to muxing code 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: YN7FUWMMJtZD It is no longer used outside of ffmpeg_mux* --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_mux.c | 6 +++--- fftools/ffmpeg_mux.h | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index e626fac18a..cc72b1cb6e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -658,7 +658,6 @@ typedef struct OutputStream { int inputs_done; const char *attachment_filename; - int streamcopy_started; int copy_initial_nonkeyframes; int copy_prior_start; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index d832116c12..01ccac55ce 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -393,11 +393,11 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) return; } - if (!ost->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) && + if (!ms->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) && !ost->copy_initial_nonkeyframes) return; - if (!ost->streamcopy_started) { + if (!ms->streamcopy_started) { if (!ost->copy_prior_start && (pkt->pts == AV_NOPTS_VALUE ? dts < ms->ts_copy_start : @@ -451,7 +451,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) of_output_packet(of, opkt, ost, 0); - ost->streamcopy_started = 1; + ms->streamcopy_started = 1; } static int thread_stop(Muxer *mux) diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 25cf1b547f..0938a261ee 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -74,6 +74,8 @@ typedef struct MuxStream { // combined size of all the packets sent to the muxer uint64_t data_size_mux; + + int streamcopy_started; } MuxStream; typedef struct Muxer { From patchwork Thu Apr 13 14:12:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41163 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1289439pzb; Thu, 13 Apr 2023 07:19:15 -0700 (PDT) X-Google-Smtp-Source: AKy350ZL6HsVqimcDf8AC4rlRQsLj/dq42jO7efmaNkPsYPVy9v0wUSgJ7zgFHi+9/TnKi33SzH2 X-Received: by 2002:a17:907:6b8e:b0:94a:56ec:7f12 with SMTP id rg14-20020a1709076b8e00b0094a56ec7f12mr3067950ejc.30.1681395555200; Thu, 13 Apr 2023 07:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395555; cv=none; d=google.com; s=arc-20160816; b=crUbvI68N71/DUtSRDpOTM+/oP7lbBScH7qcTO/m6sPfMqZ3p5B3utH6IoU5z3vTpz 8b8ktXSVV7w8vZJwyfgLCbvMxKUL+xQbnLc7ej44qmGMbaQ1jZpwERG5Xzun4MM5UtM5 k4wZeoEyAf4iqGvLfOfBv0WL18uolNzmK9CPFuWLTllLQ4l5yGQbu6uykZLSA2LucNoH 2dLS9tJDMzaweqFHhWXzkqrtoT/TjVUQh+qMfiD3lizso4CwSfW194hVIVvOipRnaaT6 FtwrPGoGMPwahOnU8TG6ra4vrTIsdpTvAe3BkGpgci9QTM5lJcnQ5Dc5d6vQGZzdpjTJ lVvA== 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=kNty7dsZd3+/kNJ11aIPigM6ao4mzuLS9eT23bX119k=; b=sSataTl23EpRM2EjSpnU+/Q7vWtu26/RgSXT3afnW/dTQ9GEuW9TWpmkUj/iaf9mQF sj1jW8CnwSPi/KzybODCk3JYNhLaCOAc2jrb5XL2IpN7U0ofGPxTJqCUKOhWmCiU6j7S v1mrUYh8oaNObSNeWRW7xa8Y8YrmDgxV5a5WoCNblV9Z+safKvqmXQnlz5mAhXpbrthH rOUplP24i6so5QW2+iTONN74vkN6adngVa5ojm9S3Wc46S0EDtO4K4emXkiwziD07B26 xUStMRz+ymAqYkO+7CJP+C4Zw727lEU+YYIQwXnvvnsU7j/zPYxxywMP4d2QtGbWHhAt lWgg== 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 fd20-20020a1709072a1400b0094e7224b495si1798112ejc.544.2023.04.13.07.19.14; Thu, 13 Apr 2023 07:19:15 -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 E0E2568BED5; Thu, 13 Apr 2023 17:16:14 +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 D2DCE68BE4A for ; Thu, 13 Apr 2023 17:16:04 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9A0BF2405EC for ; Thu, 13 Apr 2023 16:16:04 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Cs2EkvpE2YbJ for ; Thu, 13 Apr 2023 16:16: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 DEFAE240D1E for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id CF0293A03E5 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:21 +0200 Message-Id: <20230413141223.17245-23-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/25] fftools/ffmpeg_mux: make copy_prior_start private to muxing code 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: GmVBSPDd5M9X It is no longer used outside of ffmpeg_mux* --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_mux.c | 2 +- fftools/ffmpeg_mux.h | 1 + fftools/ffmpeg_mux_init.c | 6 +++--- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index cc72b1cb6e..25c33cf207 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -659,7 +659,6 @@ typedef struct OutputStream { const char *attachment_filename; int copy_initial_nonkeyframes; - int copy_prior_start; int keep_pix_fmt; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 01ccac55ce..f52205cf30 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -398,7 +398,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) return; if (!ms->streamcopy_started) { - if (!ost->copy_prior_start && + if (!ms->copy_prior_start && (pkt->pts == AV_NOPTS_VALUE ? dts < ms->ts_copy_start : pkt->pts < av_rescale_q(ms->ts_copy_start, AV_TIME_BASE_Q, pkt->time_base))) diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 0938a261ee..81c4698161 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -75,6 +75,7 @@ typedef struct MuxStream { // combined size of all the packets sent to the muxer uint64_t data_size_mux; + int copy_prior_start; int streamcopy_started; } MuxStream; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 48efaef664..bfa84f5a28 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -908,7 +908,7 @@ static int streamcopy_init(const Muxer *mux, const OptionsContext *o, if (ost->st->duration <= 0 && ist->st->duration > 0) ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - if (!ost->copy_prior_start) { + if (!ms->copy_prior_start) { ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ? 0 : mux->of.start_time; if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) { @@ -1156,8 +1156,8 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, } } - ost->copy_prior_start = -1; - MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st); + ms->copy_prior_start = -1; + MATCH_PER_STREAM_OPT(copy_prior_start, i, ms->copy_prior_start, oc ,st); MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st); if (bsfs && *bsfs) { From patchwork Thu Apr 13 14:12:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41157 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1288810pzb; Thu, 13 Apr 2023 07:18:33 -0700 (PDT) X-Google-Smtp-Source: AKy350beg+Pynh4dzcH0/bDZt/FFOFDArObBv2l5j0TZNjKKYlhDuD9hssbNSbamcPh5Rv2WeQyZ X-Received: by 2002:a17:906:35cf:b0:93f:fbe:ed17 with SMTP id p15-20020a17090635cf00b0093f0fbeed17mr2946268ejb.62.1681395512815; Thu, 13 Apr 2023 07:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395512; cv=none; d=google.com; s=arc-20160816; b=HCuXFh/9L/9RPue7wEIIthq/dG5kR7JVV5roTMrMUgw5JZXgK+Eoug3gxIfpzoKDMq 3Pki7noc00cNnAFfApBZtk+y/cS/fXWnFnHYS1+O2WBopyLPJLgnMvj2YQRMLpyunD7V 4Hlnmu54fZmb4orFINnGJtrWp8uHw035NFpaR6PlBN7OmQ8GZiP8DJqT6ORRq/GyC9BE hjTbdnp4tWWs/nFrGATh1AMCZoZrFG9YKsvjc8DXejqABFffQ00lNmwPDqnhC/Cn9Yjk r0BzkEH1OReMeDodtQ2u2r56DYZH2wPUghXna/DqX0R2UMajNPZUjv9X7oIjnrBZvllO N+YA== 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=mNnWZDl2LFVfQx3gezgTT5lU+dbLjdWsIB/nB+byPNw=; b=V6OzBF7ym+Re1Eti9CWmB5/RtVEjz0zOyT1ZNnnYACMN6Ugo1z3JJjsi/NVS5oM05J aGT2y8cQxed+ZozAHCimQ4n8otFNIh8078ju+r0vBmybOjkLcbL255jhCofFsDCggw95 t+4vn2T0l6pSIBtKCI3dDX9yj5O7UkRxdncLKx1hQvxj1/6YOFffCtT4ZTy+NTzpdFcN 5V3k0XVqfh9eL7+Xqr9ZNyz3W24wyYcTAH5NwoO0jEWwBOcVtjrpqzarWrJ0giZt4gcn /RTFbXVL0nl5Q1y6OtBqkrQ884yg3P177WkTxaa6TyPQ0aerG0o4PewGI7iZTcmAGyL8 TnCg== 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 fh3-20020a1709073a8300b0094a6b4b6a7bsi1816780ejc.158.2023.04.13.07.18.32; Thu, 13 Apr 2023 07:18:32 -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 DBA8068BE6F; Thu, 13 Apr 2023 17:16:11 +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 9942468BDEE for ; Thu, 13 Apr 2023 17:16:04 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 676BE2405B5 for ; Thu, 13 Apr 2023 16:16:04 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 3-RqoerZnteL for ; Thu, 13 Apr 2023 16:16: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 E943C240D1F for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D9D163A0404 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:22 +0200 Message-Id: <20230413141223.17245-24-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/25] fftools/ffmpeg_mux: make copy_initial_nonkeyframes private to muxing code 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: Cf4nXQ1Af/CT It is no longer used outside of ffmpeg_mux* --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_mux.c | 2 +- fftools/ffmpeg_mux.h | 1 + fftools/ffmpeg_mux_init.c | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 25c33cf207..494ea4abd3 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -658,7 +658,6 @@ typedef struct OutputStream { int inputs_done; const char *attachment_filename; - int copy_initial_nonkeyframes; int keep_pix_fmt; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index f52205cf30..7778510d2c 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -394,7 +394,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) } if (!ms->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) && - !ost->copy_initial_nonkeyframes) + !ms->copy_initial_nonkeyframes) return; if (!ms->streamcopy_started) { diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 81c4698161..7e0454dfba 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -75,6 +75,7 @@ typedef struct MuxStream { // combined size of all the packets sent to the muxer uint64_t data_size_mux; + int copy_initial_nonkeyframes; int copy_prior_start; int streamcopy_started; } MuxStream; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index bfa84f5a28..5b3606084e 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1208,7 +1208,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, ost->last_mux_dts = AV_NOPTS_VALUE; MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, - ost->copy_initial_nonkeyframes, oc, st); + ms->copy_initial_nonkeyframes, oc, st); switch (type) { case AVMEDIA_TYPE_VIDEO: new_stream_video (mux, o, ost); break; From patchwork Thu Apr 13 14:12:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41160 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1290006pzb; Thu, 13 Apr 2023 07:19:59 -0700 (PDT) X-Google-Smtp-Source: AKy350aTD+Mp0nFpqXlXFpxRnjogGgKsMeOKP7se8LuA8rb1LwfSKBys1AygZ9UBL1hR9f6vm1Ms X-Received: by 2002:a17:907:8c1a:b0:8af:2a97:91d4 with SMTP id ta26-20020a1709078c1a00b008af2a9791d4mr2888697ejc.14.1681395598699; Thu, 13 Apr 2023 07:19:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681395598; cv=none; d=google.com; s=arc-20160816; b=abqYy9umsXnyOewMn4eHzOMozJIRcRNGnFjR2jLegaLJ4HoHsrT/dinCmi2c7Fz5vY fFGI8jpGLG39zud3XqKOLgNZdOInbkCFIHHbZlE0hMIdmnsNU5+znQyVc8bB9SFJtBCn QuJWGEM50DAgzZcwejNqbn3q7cQ7TilMr7jRXGpe8Ge1/LQppdP+OYmaqBixskzUTTns w0u5xNUwT29BSqFR6PFpmMLCLQWwUpPzILJmI+oqdSOun7mb0NQywFKKsKmBUBRLD6k7 4v0PYIRN8XXn9jpAuhSfhJrPT33fRCEIQQF2GAvJGE0S+OtekFXdZcKxhSGQnoqIaYB2 pmww== 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=T1JN/SBtbiahhn78zoOQvTRj54pT2F4epvwhzk5EOXY=; b=y3UYWTWObyPd2tM3I0aRIsN42m7mgNxLLxgJj04yb+fymSa+JgHyF1CTTHXc+BPOBd tuZIUIUlpQCjB4a6K3eaDfpoLVVhTdHA/OiE7VkUD9sFxgywEgng4Ognw83ocg8UBuSB igI3sUN827c3kzXF4lR0obHGv5RIJcUkCsAPQZJaX3AE9q1qKJIvk907OPVol6k6+wM4 g98PJzxmPIx02jcJfVummKOhT2m/d33gKhl6ESStZZqZL/zNoqIR8lSnUi+DRsxFkZRI qkjdOjNsMMBHKtYSGClOpZNVIhjHmpL2rSsieYk6J+0zFzlostz/gxoLiGZthqbbaCW3 2QZQ== 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 vw13-20020a170907058d00b0094ec66ee7efsi316247ejb.488.2023.04.13.07.19.58; Thu, 13 Apr 2023 07:19:58 -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 1FF3D68BEEF; Thu, 13 Apr 2023 17:16: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 4D7FA68BE5A for ; Thu, 13 Apr 2023 17:16:05 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 078C22404F5 for ; Thu, 13 Apr 2023 16:16:05 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id DxG3hL18Le7A for ; Thu, 13 Apr 2023 16:16:04 +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 00C2D2404EE for ; Thu, 13 Apr 2023 16:15:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E48B33A039B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:23 +0200 Message-Id: <20230413141223.17245-25-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 25/25] fftools/ffmpeg_enc: make data_size_enc private to encoding code 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: 6Pl76XeTp5Vi It is no longer used outside of ffmpeg_enc.c --- fftools/ffmpeg.h | 2 -- fftools/ffmpeg_enc.c | 14 ++++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 494ea4abd3..a9302a95f0 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -662,8 +662,6 @@ typedef struct OutputStream { int keep_pix_fmt; /* stats */ - // combined size of all the packets received from the encoder - uint64_t data_size_enc; // number of packets send to the muxer atomic_uint_least64_t packets_written; // number of frames/samples sent to the encoder diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 2462f53a82..45bf4b127f 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -56,6 +56,9 @@ struct Encoder { int64_t frames_prev_hist[3]; AVFrame *sq_frame; + + // combined size of all the packets received from the encoder + uint64_t data_size; }; static uint64_t dup_warning = 1000; @@ -513,6 +516,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num) { + Encoder *e = ost->enc; AVIOContext *io = es->io; AVRational tb = frame ? frame->time_base : pkt->time_base; int64_t pts = frame ? frame->pts : pkt->pts; @@ -564,7 +568,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, } case ENC_STATS_AVG_BITRATE: { double duration = pkt->dts * av_q2d(tb); - avio_printf(io, "%g", duration > 0 ? 8.0 * ost->data_size_enc / duration : -1.); + avio_printf(io, "%g", duration > 0 ? 8.0 * e->data_size / duration : -1.); continue; } default: av_assert0(0); @@ -577,6 +581,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) { + Encoder *e = ost->enc; const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, NULL); AVCodecContext *enc = ost->enc_ctx; @@ -624,14 +629,15 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write ti1 = 0.01; bitrate = (pkt->size * 8) / av_q2d(enc->time_base) / 1000.0; - avg_bitrate = (double)(ost->data_size_enc * 8) / ti1 / 1000.0; + avg_bitrate = (double)(e->data_size * 8) / ti1 / 1000.0; fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", - (double)ost->data_size_enc / 1024, ti1, bitrate, avg_bitrate); + (double)e->data_size / 1024, ti1, bitrate, avg_bitrate); fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); } static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) { + Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; AVPacket *pkt = ost->pkt; const char *type_desc = av_get_media_type_string(enc->codec_type); @@ -725,7 +731,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) exit_program(1); } - ost->data_size_enc += pkt->size; + e->data_size += pkt->size; ost->packets_encoded++;