From patchwork Tue Oct 18 12:36:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38796 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083749pzb; Tue, 18 Oct 2022 05:41:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5oPJL6eTirrD4EmJNuNFSsZ8E5DoIwECgRd/9hF42janrxeUSttYbUYvi9+WWSi5bLCDEo X-Received: by 2002:a05:6402:e01:b0:442:dd7e:f49d with SMTP id h1-20020a0564020e0100b00442dd7ef49dmr2382297edh.355.1666096874068; Tue, 18 Oct 2022 05:41:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096874; cv=none; d=google.com; s=arc-20160816; b=qd3ZqT2smIj48rRzwZ/8lFHpPcxiQwqaDXo092k+ZUvabHfaltHyM2jQKI9U4DRG4e GzD2xCXjbGsVgLFuoZPf9uT1NpoT9g7EP/WhcREPQ7+aOkfY11lLWdOqzV/at/yQJAAc D5h2/thr/E9Xi3cyiIc3E8qCrOxXe/7J0mn42iW97gJJqdsvNy0OulQwm5kw0r37Fck3 xhxAJUlu87CEY+yqUs71NWN0eba5zF2lcvOa4yiPxJy8r0uT3V6ve5G0SV7Hxn7kUwuR 3E3JjUJwANorz0eHKCPqN/4q38w+5TvVYYnjAPMXz0vRCFW3a5/s++nHY4FxX3PgWEYA k8oA== 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=xYinw7LyBF6SqGAaj7u/Y22kTEzmtkVwYDyELKfd+P8=; b=J5mhToK1C/T4WqajD1w+LTw5j0oa7c4y5IZacunBDTBRtyDjImJ4Cp/BPzp2/Qt3w7 MAha8/p1gY19jG1DSxVn+C0BV9wIG4PfnpJKfU+1GCgIqmX2fRtNCL1S66Nf5x99wKRl 2Mqc5sKixV+AOy/VfRMZS4AXwaihAsRXTPgaJJbTLBblh4oOnWRBH/snBiNd3gnaxY51 i7P9tBv7LxhC0Nttg9RY1KJvedU/bM+wNuWFDpCLywViVV7Q2bVTvSf2rxXV89Put8Af XpAbUGt/pw/IAd9hZ7WEbbAy25OEbv78HwmSj3I+DcW5QAf/52SLqGZQh1EwYCRaaolq 3lxQ== 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 l5-20020a170906794500b0078e1d213831si13551822ejo.122.2022.10.18.05.41.13; Tue, 18 Oct 2022 05:41: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 EA8C068BDD6; Tue, 18 Oct 2022 15:38:41 +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 0367568BD5D for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1C5622404F8 for ; Tue, 18 Oct 2022 14:38:17 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id lN1XmPQR8WQc for ; Tue, 18 Oct 2022 14:38:13 +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 8562C2400F4 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 933563A0212 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:42 +0200 Message-Id: <20221018123701.25002-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/20] fftools/ffmpeg_opt: move opening input files to ffmpeg_demux.c 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: APiMuP99l3rM This is similar to what was done before for output files and will allow introducing demuxer-private state in future commits Unlike for muxing, the code is moved to existing ffmpeg_demux.c rather than to a new file. The reason is just file size - the demuxing code is much smaller than muxing. --- fftools/ffmpeg.h | 4 + fftools/ffmpeg_demux.c | 608 +++++++++++++++++++++++++++++++++++++++++ fftools/ffmpeg_opt.c | 606 +--------------------------------------- 3 files changed, 614 insertions(+), 604 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 91c5cfa3ab..085a775a43 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -678,6 +678,8 @@ extern int input_stream_potentially_available; extern int ignore_unknown_streams; extern int copy_unknown_streams; +extern int recast_media; + #if FFMPEG_OPT_PSNR extern int do_psnr; #endif @@ -745,6 +747,8 @@ int64_t of_filesize(OutputFile *of); AVChapter * const * of_get_chapters(OutputFile *of, unsigned int *nb_chapters); +int ifile_open(OptionsContext *o, const char *filename); + /** * Get next input packet from the demuxer. * diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 6e89f5999a..d2b0bc9a6d 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -19,7 +19,12 @@ #include "ffmpeg.h" #include "libavutil/avassert.h" +#include "libavutil/avstring.h" #include "libavutil/error.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" #include "libavutil/time.h" #include "libavutil/timestamp.h" #include "libavutil/thread.h" @@ -29,6 +34,17 @@ #include "libavformat/avformat.h" +static const char *const opt_name_discard[] = {"discard", NULL}; +static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL}; +static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL}; +static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL}; +static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL}; +static const char *const opt_name_ts_scale[] = {"itsscale", NULL}; +static const char *const opt_name_hwaccels[] = {"hwaccel", NULL}; +static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL}; +static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL}; +static const char *const opt_name_autorotate[] = {"autorotate", NULL}; + typedef struct DemuxMsg { AVPacket *pkt; int looping; @@ -397,3 +413,595 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) *pkt = msg.pkt; return 0; } + +static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st, + enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) + +{ + char *codec_name = NULL; + + MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st); + if (codec_name) { + const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); + st->codecpar->codec_id = codec->id; + if (recast_media && st->codecpar->codec_type != codec->type) + st->codecpar->codec_type = codec->type; + return codec; + } else { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + hwaccel_id == HWACCEL_GENERIC && + hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) { + const AVCodec *c; + void *i = NULL; + + while ((c = av_codec_iterate(&i))) { + const AVCodecHWConfig *config; + + if (c->id != st->codecpar->codec_id || + !av_codec_is_decoder(c)) + continue; + + for (int j = 0; config = avcodec_get_hw_config(c, j); j++) { + if (config->device_type == hwaccel_device_type) { + av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n", + c->name, av_hwdevice_get_type_name(hwaccel_device_type)); + return c; + } + } + } + } + + return avcodec_find_decoder(st->codecpar->codec_id); + } +} + +static int guess_input_channel_layout(InputStream *ist) +{ + AVCodecContext *dec = ist->dec_ctx; + + if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { + char layout_name[256]; + + if (dec->ch_layout.nb_channels > ist->guess_layout_max) + return 0; + av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels); + if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + return 0; + av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name)); + av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream " + "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name); + } + return 1; +} + +/* Add all the streams from the given input file to the global + * list of input streams. */ +static void add_input_streams(OptionsContext *o, AVFormatContext *ic) +{ + int i, ret; + + for (i = 0; i < ic->nb_streams; i++) { + AVStream *st = ic->streams[i]; + AVCodecParameters *par = st->codecpar; + InputStream *ist; + char *framerate = NULL, *hwaccel_device = NULL; + const char *hwaccel = NULL; + char *hwaccel_output_format = NULL; + char *codec_tag = NULL; + char *next; + char *discard_str = NULL; + const AVClass *cc = avcodec_get_class(); + const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, + 0, AV_OPT_SEARCH_FAKE_OBJ); + + ist = ALLOC_ARRAY_ELEM(input_streams, nb_input_streams); + ist->st = st; + ist->file_index = nb_input_files; + ist->discard = 1; + st->discard = AVDISCARD_ALL; + ist->nb_samples = 0; + ist->first_dts = AV_NOPTS_VALUE; + ist->min_pts = INT64_MAX; + ist->max_pts = INT64_MIN; + + ist->ts_scale = 1.0; + MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st); + + ist->autorotate = 1; + MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st); + + MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st); + if (codec_tag) { + uint32_t tag = strtol(codec_tag, &next, 0); + if (*next) + tag = AV_RL32(codec_tag); + st->codecpar->codec_tag = tag; + } + + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st); + MATCH_PER_STREAM_OPT(hwaccel_output_formats, str, + hwaccel_output_format, ic, st); + + if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) { + av_log(NULL, AV_LOG_WARNING, + "WARNING: defaulting hwaccel_output_format to cuda for compatibility " + "with old commandlines. This behaviour is DEPRECATED and will be removed " + "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n"); + ist->hwaccel_output_format = AV_PIX_FMT_CUDA; + } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) { + av_log(NULL, AV_LOG_WARNING, + "WARNING: defaulting hwaccel_output_format to qsv for compatibility " + "with old commandlines. This behaviour is DEPRECATED and will be removed " + "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n"); + ist->hwaccel_output_format = AV_PIX_FMT_QSV; + } else if (hwaccel_output_format) { + ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format); + if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) { + av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output " + "format: %s", hwaccel_output_format); + } + } else { + ist->hwaccel_output_format = AV_PIX_FMT_NONE; + } + + if (hwaccel) { + // The NVDEC hwaccels use a CUDA device, so remap the name here. + if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid")) + hwaccel = "cuda"; + + if (!strcmp(hwaccel, "none")) + ist->hwaccel_id = HWACCEL_NONE; + else if (!strcmp(hwaccel, "auto")) + ist->hwaccel_id = HWACCEL_AUTO; + else { + enum AVHWDeviceType type = av_hwdevice_find_type_by_name(hwaccel); + if (type != AV_HWDEVICE_TYPE_NONE) { + ist->hwaccel_id = HWACCEL_GENERIC; + ist->hwaccel_device_type = type; + } + + if (!ist->hwaccel_id) { + av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n", + hwaccel); + av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: "); + type = AV_HWDEVICE_TYPE_NONE; + while ((type = av_hwdevice_iterate_types(type)) != + AV_HWDEVICE_TYPE_NONE) + av_log(NULL, AV_LOG_FATAL, "%s ", + av_hwdevice_get_type_name(type)); + av_log(NULL, AV_LOG_FATAL, "\n"); + exit_program(1); + } + } + } + + MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st); + if (hwaccel_device) { + ist->hwaccel_device = av_strdup(hwaccel_device); + if (!ist->hwaccel_device) + report_and_exit(AVERROR(ENOMEM)); + } + + ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE; + } + + ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type); + ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec); + + ist->reinit_filters = -1; + MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st); + + MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st); + ist->user_set_discard = AVDISCARD_NONE; + + if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) || + (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) || + (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) || + (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)) + ist->user_set_discard = AVDISCARD_ALL; + + if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) { + av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n", + discard_str); + exit_program(1); + } + + ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; + ist->prev_pkt_pts = AV_NOPTS_VALUE; + + ist->dec_ctx = avcodec_alloc_context3(ist->dec); + if (!ist->dec_ctx) + report_and_exit(AVERROR(ENOMEM)); + + ret = avcodec_parameters_to_context(ist->dec_ctx, par); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n"); + exit_program(1); + } + + ist->decoded_frame = av_frame_alloc(); + if (!ist->decoded_frame) + report_and_exit(AVERROR(ENOMEM)); + + ist->pkt = av_packet_alloc(); + if (!ist->pkt) + report_and_exit(AVERROR(ENOMEM)); + + if (o->bitexact) + ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT; + + switch (par->codec_type) { + case AVMEDIA_TYPE_VIDEO: + // avformat_find_stream_info() doesn't set this for us anymore. + ist->dec_ctx->framerate = st->avg_frame_rate; + + MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st); + if (framerate && av_parse_video_rate(&ist->framerate, + framerate) < 0) { + av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n", + framerate); + exit_program(1); + } + + ist->top_field_first = -1; + MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st); + + ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL); + + break; + case AVMEDIA_TYPE_AUDIO: + ist->guess_layout_max = INT_MAX; + MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st); + guess_input_channel_layout(ist); + break; + case AVMEDIA_TYPE_DATA: + case AVMEDIA_TYPE_SUBTITLE: { + char *canvas_size = NULL; + MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st); + MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st); + if (canvas_size && + av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) { + av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size); + exit_program(1); + } + break; + } + case AVMEDIA_TYPE_ATTACHMENT: + case AVMEDIA_TYPE_UNKNOWN: + break; + default: + abort(); + } + + ist->par = avcodec_parameters_alloc(); + if (!ist->par) + report_and_exit(AVERROR(ENOMEM)); + + ret = avcodec_parameters_from_context(ist->par, ist->dec_ctx); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n"); + exit_program(1); + } + } +} + +static void dump_attachment(AVStream *st, const char *filename) +{ + int ret; + AVIOContext *out = NULL; + const AVDictionaryEntry *e; + + if (!st->codecpar->extradata_size) { + av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n", + nb_input_files - 1, st->index); + return; + } + if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0))) + filename = e->value; + if (!*filename) { + av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag" + "in stream #%d:%d.\n", nb_input_files - 1, st->index); + exit_program(1); + } + + assert_file_overwrite(filename); + + if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) { + av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n", + filename); + exit_program(1); + } + + avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size); + avio_flush(out); + avio_close(out); +} + +int ifile_open(OptionsContext *o, const char *filename) +{ + InputFile *f; + AVFormatContext *ic; + const AVInputFormat *file_iformat = NULL; + int err, i, ret; + int64_t timestamp; + AVDictionary *unused_opts = NULL; + const AVDictionaryEntry *e = NULL; + char * video_codec_name = NULL; + char * audio_codec_name = NULL; + char *subtitle_codec_name = NULL; + char * data_codec_name = NULL; + int scan_all_pmts_set = 0; + + if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { + o->stop_time = INT64_MAX; + av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n"); + } + + if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) { + int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time; + if (o->stop_time <= start_time) { + av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n"); + exit_program(1); + } else { + o->recording_time = o->stop_time - start_time; + } + } + + if (o->format) { + if (!(file_iformat = av_find_input_format(o->format))) { + av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format); + exit_program(1); + } + } + + if (!strcmp(filename, "-")) + filename = "pipe:"; + + stdin_interaction &= strncmp(filename, "pipe:", 5) && + strcmp(filename, "/dev/stdin"); + + /* get default parameters from command line */ + ic = avformat_alloc_context(); + if (!ic) + report_and_exit(AVERROR(ENOMEM)); + if (o->nb_audio_sample_rate) { + av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0); + } + if (o->nb_audio_channels) { + const AVClass *priv_class; + if (file_iformat && (priv_class = file_iformat->priv_class) && + av_opt_find(&priv_class, "ch_layout", NULL, 0, + AV_OPT_SEARCH_FAKE_OBJ)) { + char buf[32]; + snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i); + av_dict_set(&o->g->format_opts, "ch_layout", buf, 0); + } + } + if (o->nb_audio_ch_layouts) { + const AVClass *priv_class; + if (file_iformat && (priv_class = file_iformat->priv_class) && + av_opt_find(&priv_class, "ch_layout", NULL, 0, + AV_OPT_SEARCH_FAKE_OBJ)) { + av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0); + } + } + if (o->nb_frame_rates) { + const AVClass *priv_class; + /* set the format-level framerate option; + * this is important for video grabbers, e.g. x11 */ + if (file_iformat && (priv_class = file_iformat->priv_class) && + av_opt_find(&priv_class, "framerate", NULL, 0, + AV_OPT_SEARCH_FAKE_OBJ)) { + av_dict_set(&o->g->format_opts, "framerate", + o->frame_rates[o->nb_frame_rates - 1].u.str, 0); + } + } + if (o->nb_frame_sizes) { + av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0); + } + if (o->nb_frame_pix_fmts) + av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0); + + MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v"); + MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a"); + MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s"); + MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d"); + + if (video_codec_name) + ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0); + if (audio_codec_name) + ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0); + if (subtitle_codec_name) + ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0); + if (data_codec_name) + ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0); + + ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE; + ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE; + ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE; + ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE; + + ic->flags |= AVFMT_FLAG_NONBLOCK; + if (o->bitexact) + ic->flags |= AVFMT_FLAG_BITEXACT; + ic->interrupt_callback = int_cb; + + if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) { + av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE); + scan_all_pmts_set = 1; + } + /* open the input file with generic avformat function */ + err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts); + if (err < 0) { + print_error(filename, err); + if (err == AVERROR_PROTOCOL_NOT_FOUND) + av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename); + exit_program(1); + } + if (scan_all_pmts_set) + av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); + remove_avoptions(&o->g->format_opts, o->g->codec_opts); + assert_avoptions(o->g->format_opts); + + /* apply forced codec ids */ + for (i = 0; i < ic->nb_streams; i++) + choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE); + + if (o->find_stream_info) { + AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts); + int orig_nb_streams = ic->nb_streams; + + /* If not enough info to get the stream parameters, we decode the + first frames to get it. (used in mpeg case for example) */ + ret = avformat_find_stream_info(ic, opts); + + for (i = 0; i < orig_nb_streams; i++) + av_dict_free(&opts[i]); + av_freep(&opts); + + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename); + if (ic->nb_streams == 0) { + avformat_close_input(&ic); + exit_program(1); + } + } + } + + if (o->start_time != AV_NOPTS_VALUE && o->start_time_eof != AV_NOPTS_VALUE) { + av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename); + o->start_time_eof = AV_NOPTS_VALUE; + } + + if (o->start_time_eof != AV_NOPTS_VALUE) { + if (o->start_time_eof >= 0) { + av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n"); + exit_program(1); + } + if (ic->duration > 0) { + o->start_time = o->start_time_eof + ic->duration; + if (o->start_time < 0) { + av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename); + o->start_time = AV_NOPTS_VALUE; + } + } else + av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename); + } + timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time; + /* add the stream start time */ + if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE) + timestamp += ic->start_time; + + /* if seeking requested, we execute it */ + if (o->start_time != AV_NOPTS_VALUE) { + int64_t seek_timestamp = timestamp; + + if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) { + int dts_heuristic = 0; + for (i=0; inb_streams; i++) { + const AVCodecParameters *par = ic->streams[i]->codecpar; + if (par->video_delay) { + dts_heuristic = 1; + break; + } + } + if (dts_heuristic) { + seek_timestamp -= 3*AV_TIME_BASE / 23; + } + } + ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0); + if (ret < 0) { + av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n", + filename, (double)timestamp / AV_TIME_BASE); + } + } + + /* update the current parameters so that they match the one of the input stream */ + add_input_streams(o, ic); + + /* dump the file content */ + av_dump_format(ic, nb_input_files, filename, 0); + + f = ALLOC_ARRAY_ELEM(input_files, nb_input_files); + + f->ctx = ic; + f->index = nb_input_files - 1; + f->ist_index = nb_input_streams - ic->nb_streams; + f->start_time = o->start_time; + f->recording_time = o->recording_time; + f->input_sync_ref = o->input_sync_ref; + f->input_ts_offset = o->input_ts_offset; + f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp); + f->nb_streams = ic->nb_streams; + f->rate_emu = o->rate_emu; + f->accurate_seek = o->accurate_seek; + f->loop = o->loop; + f->duration = 0; + f->time_base = (AVRational){ 1, 1 }; + + f->readrate = o->readrate ? o->readrate : 0.0; + if (f->readrate < 0.0f) { + av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", f->index, f->readrate); + exit_program(1); + } + if (f->readrate && f->rate_emu) { + av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", f->index, f->readrate); + f->rate_emu = 0; + } + + f->thread_queue_size = o->thread_queue_size; + + /* check if all codec options have been used */ + unused_opts = strip_specifiers(o->g->codec_opts); + for (i = f->ist_index; i < nb_input_streams; i++) { + e = NULL; + while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e, + AV_DICT_IGNORE_SUFFIX))) + av_dict_set(&unused_opts, e->key, NULL, 0); + } + + e = NULL; + while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) { + const AVClass *class = avcodec_get_class(); + const AVOption *option = av_opt_find(&class, e->key, NULL, 0, + AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ); + const AVClass *fclass = avformat_get_class(); + const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0, + AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ); + if (!option || foption) + continue; + + + if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) { + av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for " + "input file #%d (%s) is not a decoding option.\n", e->key, + option->help ? option->help : "", f->index, + filename); + exit_program(1); + } + + av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for " + "input file #%d (%s) has not been used for any stream. The most " + "likely reason is either wrong type (e.g. a video option with " + "no video streams) or that it is a private option of some decoder " + "which was not actually used for any stream.\n", e->key, + option->help ? option->help : "", f->index, filename); + } + av_dict_free(&unused_opts); + + for (i = 0; i < o->nb_dump_attachment; i++) { + int j; + + for (j = 0; j < ic->nb_streams; j++) { + AVStream *st = ic->streams[j]; + + if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1) + dump_attachment(st, o->dump_attachment[i].u.str); + } + } + + input_stream_potentially_available = 1; + + return 0; +} diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 7fdbf08a18..38916304bc 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -54,18 +54,8 @@ const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL}; const char *const opt_name_frame_rates[] = {"r", NULL}; -static const char *const opt_name_ts_scale[] = {"itsscale", NULL}; -static const char *const opt_name_hwaccels[] = {"hwaccel", NULL}; -static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL}; -static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL}; -static const char *const opt_name_autorotate[] = {"autorotate", NULL}; const char *const opt_name_codec_tags[] = {"tag", "atag", "vtag", "stag", NULL}; const char *const opt_name_top_field_first[] = {"top", NULL}; -static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL}; -static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL}; -static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL}; -static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL}; -static const char *const opt_name_discard[] = {"discard", NULL}; HWDevice *filter_hw_device; @@ -107,7 +97,7 @@ int do_psnr = 0; int input_stream_potentially_available = 0; int ignore_unknown_streams = 0; int copy_unknown_streams = 0; -static int recast_media = 0; +int recast_media = 0; static void uninit_options(OptionsContext *o) { @@ -624,278 +614,6 @@ const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int en return codec; } -static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st, - enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) - -{ - char *codec_name = NULL; - - MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st); - if (codec_name) { - const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); - st->codecpar->codec_id = codec->id; - if (recast_media && st->codecpar->codec_type != codec->type) - st->codecpar->codec_type = codec->type; - return codec; - } else { - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - hwaccel_id == HWACCEL_GENERIC && - hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) { - const AVCodec *c; - void *i = NULL; - - while ((c = av_codec_iterate(&i))) { - const AVCodecHWConfig *config; - - if (c->id != st->codecpar->codec_id || - !av_codec_is_decoder(c)) - continue; - - for (int j = 0; config = avcodec_get_hw_config(c, j); j++) { - if (config->device_type == hwaccel_device_type) { - av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n", - c->name, av_hwdevice_get_type_name(hwaccel_device_type)); - return c; - } - } - } - } - - return avcodec_find_decoder(st->codecpar->codec_id); - } -} - -static int guess_input_channel_layout(InputStream *ist) -{ - AVCodecContext *dec = ist->dec_ctx; - - if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { - char layout_name[256]; - - if (dec->ch_layout.nb_channels > ist->guess_layout_max) - return 0; - av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels); - if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) - return 0; - av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name)); - av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream " - "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name); - } - return 1; -} - -/* Add all the streams from the given input file to the global - * list of input streams. */ -static void add_input_streams(OptionsContext *o, AVFormatContext *ic) -{ - int i, ret; - - for (i = 0; i < ic->nb_streams; i++) { - AVStream *st = ic->streams[i]; - AVCodecParameters *par = st->codecpar; - InputStream *ist; - char *framerate = NULL, *hwaccel_device = NULL; - const char *hwaccel = NULL; - char *hwaccel_output_format = NULL; - char *codec_tag = NULL; - char *next; - char *discard_str = NULL; - const AVClass *cc = avcodec_get_class(); - const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, - 0, AV_OPT_SEARCH_FAKE_OBJ); - - ist = ALLOC_ARRAY_ELEM(input_streams, nb_input_streams); - ist->st = st; - ist->file_index = nb_input_files; - ist->discard = 1; - st->discard = AVDISCARD_ALL; - ist->nb_samples = 0; - ist->first_dts = AV_NOPTS_VALUE; - ist->min_pts = INT64_MAX; - ist->max_pts = INT64_MIN; - - ist->ts_scale = 1.0; - MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st); - - ist->autorotate = 1; - MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st); - - MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st); - if (codec_tag) { - uint32_t tag = strtol(codec_tag, &next, 0); - if (*next) - tag = AV_RL32(codec_tag); - st->codecpar->codec_tag = tag; - } - - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st); - MATCH_PER_STREAM_OPT(hwaccel_output_formats, str, - hwaccel_output_format, ic, st); - - if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) { - av_log(NULL, AV_LOG_WARNING, - "WARNING: defaulting hwaccel_output_format to cuda for compatibility " - "with old commandlines. This behaviour is DEPRECATED and will be removed " - "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n"); - ist->hwaccel_output_format = AV_PIX_FMT_CUDA; - } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) { - av_log(NULL, AV_LOG_WARNING, - "WARNING: defaulting hwaccel_output_format to qsv for compatibility " - "with old commandlines. This behaviour is DEPRECATED and will be removed " - "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n"); - ist->hwaccel_output_format = AV_PIX_FMT_QSV; - } else if (hwaccel_output_format) { - ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format); - if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) { - av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output " - "format: %s", hwaccel_output_format); - } - } else { - ist->hwaccel_output_format = AV_PIX_FMT_NONE; - } - - if (hwaccel) { - // The NVDEC hwaccels use a CUDA device, so remap the name here. - if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid")) - hwaccel = "cuda"; - - if (!strcmp(hwaccel, "none")) - ist->hwaccel_id = HWACCEL_NONE; - else if (!strcmp(hwaccel, "auto")) - ist->hwaccel_id = HWACCEL_AUTO; - else { - enum AVHWDeviceType type = av_hwdevice_find_type_by_name(hwaccel); - if (type != AV_HWDEVICE_TYPE_NONE) { - ist->hwaccel_id = HWACCEL_GENERIC; - ist->hwaccel_device_type = type; - } - - if (!ist->hwaccel_id) { - av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n", - hwaccel); - av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: "); - type = AV_HWDEVICE_TYPE_NONE; - while ((type = av_hwdevice_iterate_types(type)) != - AV_HWDEVICE_TYPE_NONE) - av_log(NULL, AV_LOG_FATAL, "%s ", - av_hwdevice_get_type_name(type)); - av_log(NULL, AV_LOG_FATAL, "\n"); - exit_program(1); - } - } - } - - MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st); - if (hwaccel_device) { - ist->hwaccel_device = av_strdup(hwaccel_device); - if (!ist->hwaccel_device) - report_and_exit(AVERROR(ENOMEM)); - } - - ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE; - } - - ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type); - ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec); - - ist->reinit_filters = -1; - MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st); - - MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st); - ist->user_set_discard = AVDISCARD_NONE; - - if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) || - (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) || - (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) || - (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)) - ist->user_set_discard = AVDISCARD_ALL; - - if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) { - av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n", - discard_str); - exit_program(1); - } - - ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; - ist->prev_pkt_pts = AV_NOPTS_VALUE; - - ist->dec_ctx = avcodec_alloc_context3(ist->dec); - if (!ist->dec_ctx) - report_and_exit(AVERROR(ENOMEM)); - - ret = avcodec_parameters_to_context(ist->dec_ctx, par); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n"); - exit_program(1); - } - - ist->decoded_frame = av_frame_alloc(); - if (!ist->decoded_frame) - report_and_exit(AVERROR(ENOMEM)); - - ist->pkt = av_packet_alloc(); - if (!ist->pkt) - report_and_exit(AVERROR(ENOMEM)); - - if (o->bitexact) - ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT; - - switch (par->codec_type) { - case AVMEDIA_TYPE_VIDEO: - // avformat_find_stream_info() doesn't set this for us anymore. - ist->dec_ctx->framerate = st->avg_frame_rate; - - MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st); - if (framerate && av_parse_video_rate(&ist->framerate, - framerate) < 0) { - av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n", - framerate); - exit_program(1); - } - - ist->top_field_first = -1; - MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st); - - ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL); - - break; - case AVMEDIA_TYPE_AUDIO: - ist->guess_layout_max = INT_MAX; - MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st); - guess_input_channel_layout(ist); - break; - case AVMEDIA_TYPE_DATA: - case AVMEDIA_TYPE_SUBTITLE: { - char *canvas_size = NULL; - MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st); - MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st); - if (canvas_size && - av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) { - av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size); - exit_program(1); - } - break; - } - case AVMEDIA_TYPE_ATTACHMENT: - case AVMEDIA_TYPE_UNKNOWN: - break; - default: - abort(); - } - - ist->par = avcodec_parameters_alloc(); - if (!ist->par) - report_and_exit(AVERROR(ENOMEM)); - - ret = avcodec_parameters_from_context(ist->par, ist->dec_ctx); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n"); - exit_program(1); - } - } -} - void assert_file_overwrite(const char *filename) { const char *proto_name = avio_find_protocol_name(filename); @@ -939,326 +657,6 @@ void assert_file_overwrite(const char *filename) } } -static void dump_attachment(AVStream *st, const char *filename) -{ - int ret; - AVIOContext *out = NULL; - const AVDictionaryEntry *e; - - if (!st->codecpar->extradata_size) { - av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n", - nb_input_files - 1, st->index); - return; - } - if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0))) - filename = e->value; - if (!*filename) { - av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag" - "in stream #%d:%d.\n", nb_input_files - 1, st->index); - exit_program(1); - } - - assert_file_overwrite(filename); - - if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) { - av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n", - filename); - exit_program(1); - } - - avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size); - avio_flush(out); - avio_close(out); -} - -static int open_input_file(OptionsContext *o, const char *filename) -{ - InputFile *f; - AVFormatContext *ic; - const AVInputFormat *file_iformat = NULL; - int err, i, ret; - int64_t timestamp; - AVDictionary *unused_opts = NULL; - const AVDictionaryEntry *e = NULL; - char * video_codec_name = NULL; - char * audio_codec_name = NULL; - char *subtitle_codec_name = NULL; - char * data_codec_name = NULL; - int scan_all_pmts_set = 0; - - if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { - o->stop_time = INT64_MAX; - av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n"); - } - - if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) { - int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time; - if (o->stop_time <= start_time) { - av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n"); - exit_program(1); - } else { - o->recording_time = o->stop_time - start_time; - } - } - - if (o->format) { - if (!(file_iformat = av_find_input_format(o->format))) { - av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format); - exit_program(1); - } - } - - if (!strcmp(filename, "-")) - filename = "pipe:"; - - stdin_interaction &= strncmp(filename, "pipe:", 5) && - strcmp(filename, "/dev/stdin"); - - /* get default parameters from command line */ - ic = avformat_alloc_context(); - if (!ic) - report_and_exit(AVERROR(ENOMEM)); - if (o->nb_audio_sample_rate) { - av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0); - } - if (o->nb_audio_channels) { - const AVClass *priv_class; - if (file_iformat && (priv_class = file_iformat->priv_class) && - av_opt_find(&priv_class, "ch_layout", NULL, 0, - AV_OPT_SEARCH_FAKE_OBJ)) { - char buf[32]; - snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i); - av_dict_set(&o->g->format_opts, "ch_layout", buf, 0); - } - } - if (o->nb_audio_ch_layouts) { - const AVClass *priv_class; - if (file_iformat && (priv_class = file_iformat->priv_class) && - av_opt_find(&priv_class, "ch_layout", NULL, 0, - AV_OPT_SEARCH_FAKE_OBJ)) { - av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0); - } - } - if (o->nb_frame_rates) { - const AVClass *priv_class; - /* set the format-level framerate option; - * this is important for video grabbers, e.g. x11 */ - if (file_iformat && (priv_class = file_iformat->priv_class) && - av_opt_find(&priv_class, "framerate", NULL, 0, - AV_OPT_SEARCH_FAKE_OBJ)) { - av_dict_set(&o->g->format_opts, "framerate", - o->frame_rates[o->nb_frame_rates - 1].u.str, 0); - } - } - if (o->nb_frame_sizes) { - av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0); - } - if (o->nb_frame_pix_fmts) - av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0); - - MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v"); - MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a"); - MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s"); - MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d"); - - if (video_codec_name) - ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0); - if (audio_codec_name) - ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0); - if (subtitle_codec_name) - ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0); - if (data_codec_name) - ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0); - - ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE; - ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE; - ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE; - ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE; - - ic->flags |= AVFMT_FLAG_NONBLOCK; - if (o->bitexact) - ic->flags |= AVFMT_FLAG_BITEXACT; - ic->interrupt_callback = int_cb; - - if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) { - av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE); - scan_all_pmts_set = 1; - } - /* open the input file with generic avformat function */ - err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts); - if (err < 0) { - print_error(filename, err); - if (err == AVERROR_PROTOCOL_NOT_FOUND) - av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename); - exit_program(1); - } - if (scan_all_pmts_set) - av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); - remove_avoptions(&o->g->format_opts, o->g->codec_opts); - assert_avoptions(o->g->format_opts); - - /* apply forced codec ids */ - for (i = 0; i < ic->nb_streams; i++) - choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE); - - if (o->find_stream_info) { - AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts); - int orig_nb_streams = ic->nb_streams; - - /* If not enough info to get the stream parameters, we decode the - first frames to get it. (used in mpeg case for example) */ - ret = avformat_find_stream_info(ic, opts); - - for (i = 0; i < orig_nb_streams; i++) - av_dict_free(&opts[i]); - av_freep(&opts); - - if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename); - if (ic->nb_streams == 0) { - avformat_close_input(&ic); - exit_program(1); - } - } - } - - if (o->start_time != AV_NOPTS_VALUE && o->start_time_eof != AV_NOPTS_VALUE) { - av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename); - o->start_time_eof = AV_NOPTS_VALUE; - } - - if (o->start_time_eof != AV_NOPTS_VALUE) { - if (o->start_time_eof >= 0) { - av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n"); - exit_program(1); - } - if (ic->duration > 0) { - o->start_time = o->start_time_eof + ic->duration; - if (o->start_time < 0) { - av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename); - o->start_time = AV_NOPTS_VALUE; - } - } else - av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename); - } - timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time; - /* add the stream start time */ - if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE) - timestamp += ic->start_time; - - /* if seeking requested, we execute it */ - if (o->start_time != AV_NOPTS_VALUE) { - int64_t seek_timestamp = timestamp; - - if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) { - int dts_heuristic = 0; - for (i=0; inb_streams; i++) { - const AVCodecParameters *par = ic->streams[i]->codecpar; - if (par->video_delay) { - dts_heuristic = 1; - break; - } - } - if (dts_heuristic) { - seek_timestamp -= 3*AV_TIME_BASE / 23; - } - } - ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0); - if (ret < 0) { - av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n", - filename, (double)timestamp / AV_TIME_BASE); - } - } - - /* update the current parameters so that they match the one of the input stream */ - add_input_streams(o, ic); - - /* dump the file content */ - av_dump_format(ic, nb_input_files, filename, 0); - - f = ALLOC_ARRAY_ELEM(input_files, nb_input_files); - - f->ctx = ic; - f->index = nb_input_files - 1; - f->ist_index = nb_input_streams - ic->nb_streams; - f->start_time = o->start_time; - f->recording_time = o->recording_time; - f->input_sync_ref = o->input_sync_ref; - f->input_ts_offset = o->input_ts_offset; - f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp); - f->nb_streams = ic->nb_streams; - f->rate_emu = o->rate_emu; - f->accurate_seek = o->accurate_seek; - f->loop = o->loop; - f->duration = 0; - f->time_base = (AVRational){ 1, 1 }; - - f->readrate = o->readrate ? o->readrate : 0.0; - if (f->readrate < 0.0f) { - av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", f->index, f->readrate); - exit_program(1); - } - if (f->readrate && f->rate_emu) { - av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", f->index, f->readrate); - f->rate_emu = 0; - } - - f->thread_queue_size = o->thread_queue_size; - - /* check if all codec options have been used */ - unused_opts = strip_specifiers(o->g->codec_opts); - for (i = f->ist_index; i < nb_input_streams; i++) { - e = NULL; - while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e, - AV_DICT_IGNORE_SUFFIX))) - av_dict_set(&unused_opts, e->key, NULL, 0); - } - - e = NULL; - while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) { - const AVClass *class = avcodec_get_class(); - const AVOption *option = av_opt_find(&class, e->key, NULL, 0, - AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ); - const AVClass *fclass = avformat_get_class(); - const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0, - AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ); - if (!option || foption) - continue; - - - if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) { - av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for " - "input file #%d (%s) is not a decoding option.\n", e->key, - option->help ? option->help : "", f->index, - filename); - exit_program(1); - } - - av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for " - "input file #%d (%s) has not been used for any stream. The most " - "likely reason is either wrong type (e.g. a video option with " - "no video streams) or that it is a private option of some decoder " - "which was not actually used for any stream.\n", e->key, - option->help ? option->help : "", f->index, filename); - } - av_dict_free(&unused_opts); - - for (i = 0; i < o->nb_dump_attachment; i++) { - int j; - - for (j = 0; j < ic->nb_streams; j++) { - AVStream *st = ic->streams[j]; - - if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1) - dump_attachment(st, o->dump_attachment[i].u.str); - } - } - - input_stream_potentially_available = 1; - - return 0; -} - /* read file contents into a string */ char *read_file(const char *filename) { @@ -1847,7 +1245,7 @@ int ffmpeg_parse_options(int argc, char **argv) term_init(); /* open input files */ - ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file); + ret = open_files(&octx.groups[GROUP_INFILE], "input", ifile_open); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error opening input files: "); goto fail; From patchwork Tue Oct 18 12:36:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38778 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2082690pzb; Tue, 18 Oct 2022 05:38:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6hnIrovUxOwGZTRjp4tJ58Rzzfco+ZSpyRQP3QH5AdzWLgd58ZGX9st9I5hZRPQw3DPvFE X-Received: by 2002:a17:906:4fcb:b0:791:9a26:376f with SMTP id i11-20020a1709064fcb00b007919a26376fmr2232286ejw.431.1666096715767; Tue, 18 Oct 2022 05:38:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096715; cv=none; d=google.com; s=arc-20160816; b=AGsC54UXoa2RdWqL9mM+SEt2g6DWhUohIPy5qLpSI//53DAmt24EkB4lLE7Wgfr3Q2 xkKzDT/W/h9iJklPT6oLXnI6DTMQomvnsiOZCQWJKQjDqxn8BGFDtHPbTKDnMQyM55FB cocmPLL87cXROfoS9Sf5f+IE18JlrpFvgelqkvcvox5xXwljZCnNc2/uhAVrwkkzIykF DwvZhH1omMDg0YTqmml+o02irXsExJ4g6gXuTq58DbmKLSoaWwQM1AQgAEheepy2dAD4 TDxmNaNYqt2szk+QRjfHbBLR7fChknU0jHFpCHsdEh9yddjmoD2RgCu6gkJ6rQaXIT4V NsfA== 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=hDQfewsgqxUZMn0iJDBpiGmnWDWSU9ZsRKunHqcmxNc=; b=S9xN5lX60t2bppfbNX2eJfklbw6leQl+wPYKKfzSjSM+br5WzGgT5Zcf71IUjP3HyF IxaL7B/68s6JCeHzRu2ZOQVdAWS0ota+411cV0a6tljo1EUY6gL/p+yqSu/KjTuYzO7i l1h8+WwvqLZl5Q8EkeYlSnS4BMrzbw+CYcxiOfmVFpi3322wpE1RKMbj0F87soaJoYI3 B2IlTOLpmHY0d8303qPylIqyG2PfypkeumtujzUon2t+s/95gjtcnw14g0Yrf214ZIcR UzHS8ZwHGJLbh53ltC+JdrGNMjSTSsUXyF0fjq6aBa68lJ6XUKECxaIOkMI+OTAxgEn9 GH6w== 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 b31-20020a509f22000000b00453aa9656a3si9967467edf.466.2022.10.18.05.38.35; Tue, 18 Oct 2022 05:38:35 -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 85ABF68B7F8; Tue, 18 Oct 2022 15:38: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 59F9468BCE1 for ; Tue, 18 Oct 2022 15:38:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D82B42404F5 for ; Tue, 18 Oct 2022 14:38:14 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id M8k-vKm9jS7G for ; Tue, 18 Oct 2022 14:38:14 +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 935FC2404E4 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 999BE3A0922 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:43 +0200 Message-Id: <20221018123701.25002-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/20] fftools/ffmpeg_demux: add demuxer private data 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: ybDdPxP7OKac Move InputFile.loop into it. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_demux.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 085a775a43..35410ec4a1 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -434,7 +434,6 @@ typedef struct InputFile { int eof_reached; /* true if eof reached */ int eagain; /* true if last read attempt returned EAGAIN */ int ist_index; /* index of first stream in input_streams */ - int loop; /* set number of times input stream should be looped */ int64_t duration; /* actual duration of the longest stream in a file at the moment when looping happens */ AVRational time_base; /* time base of the duration */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index d2b0bc9a6d..f92500abf9 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -45,6 +45,13 @@ static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL}; static const char *const opt_name_autorotate[] = {"autorotate", NULL}; +typedef struct Demuxer { + InputFile f; + + /* number of times input stream should be looped */ + int loop; +} Demuxer; + typedef struct DemuxMsg { AVPacket *pkt; int looping; @@ -53,6 +60,11 @@ typedef struct DemuxMsg { int repeat_pict; } DemuxMsg; +static Demuxer *demuxer_from_ifile(InputFile *f) +{ + return (Demuxer*)f; +} + static void report_new_stream(InputFile *file, const AVPacket *pkt) { AVStream *st = file->ctx->streams[pkt->stream_index]; @@ -84,8 +96,9 @@ static void ifile_duration_update(InputFile *f, InputStream *ist, } } -static int seek_to_start(InputFile *ifile) +static int seek_to_start(Demuxer *d) { + InputFile *ifile = &d->f; AVFormatContext *is = ifile->ctx; InputStream *ist; int ret; @@ -127,8 +140,8 @@ static int seek_to_start(InputFile *ifile) } } - if (ifile->loop > 0) - ifile->loop--; + if (d->loop > 0) + d->loop--; return ret; } @@ -195,7 +208,8 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) static void *input_thread(void *arg) { - InputFile *f = arg; + Demuxer *d = arg; + InputFile *f = &d->f; AVPacket *pkt; unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; int ret = 0; @@ -216,12 +230,12 @@ static void *input_thread(void *arg) continue; } if (ret < 0) { - if (f->loop) { + if (d->loop) { /* signal looping to the consumer thread */ msg.looping = 1; ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0); if (ret >= 0) - ret = seek_to_start(f); + ret = seek_to_start(d); if (ret >= 0) continue; @@ -320,6 +334,7 @@ static int init_input_thread(int i) { int ret; InputFile *f = input_files[i]; + Demuxer *d = demuxer_from_ifile(f); if (f->thread_queue_size <= 0) f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); @@ -332,7 +347,7 @@ static int init_input_thread(int i) if (ret < 0) return ret; - if (f->loop) { + if (d->loop) { int nb_audio_dec = 0; for (int i = 0; i < f->nb_streams; i++) { @@ -350,7 +365,7 @@ static int init_input_thread(int i) } } - if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { + if ((ret = pthread_create(&f->thread, NULL, input_thread, d))) { av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); ret = AVERROR(ret); goto fail; @@ -720,6 +735,7 @@ static void dump_attachment(AVStream *st, const char *filename) int ifile_open(OptionsContext *o, const char *filename) { + Demuxer *d; InputFile *f; AVFormatContext *ic; const AVInputFormat *file_iformat = NULL; @@ -923,7 +939,8 @@ int ifile_open(OptionsContext *o, const char *filename) /* dump the file content */ av_dump_format(ic, nb_input_files, filename, 0); - f = ALLOC_ARRAY_ELEM(input_files, nb_input_files); + d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files); + f = &d->f; f->ctx = ic; f->index = nb_input_files - 1; @@ -936,7 +953,7 @@ int ifile_open(OptionsContext *o, const char *filename) f->nb_streams = ic->nb_streams; f->rate_emu = o->rate_emu; f->accurate_seek = o->accurate_seek; - f->loop = o->loop; + d->loop = o->loop; f->duration = 0; f->time_base = (AVRational){ 1, 1 }; From patchwork Tue Oct 18 12:36:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38777 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2082696pzb; Tue, 18 Oct 2022 05:38:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4BNkjQn68V0AvTER58paQZFx4vL+j06ypcI+Xa3PTKN0sU5DgWDJ1vd8y51x9UnaLEibC4 X-Received: by 2002:a17:907:2701:b0:78d:cb12:6d94 with SMTP id w1-20020a170907270100b0078dcb126d94mr2317471ejk.344.1666096705658; Tue, 18 Oct 2022 05:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096705; cv=none; d=google.com; s=arc-20160816; b=aVUaL+EZWZpIneEwcmkrKFNHIYoGcXv+38OCbj1Cv8iSt9yhcmmiDBa2CT0EgktjMY qpYmlw41+zG0UNCDhoLEy1IyxZYn8njOPtW5oBnx6KLR9YzybUFyTmxvf85HimbTuulB /9b1Y2F4f4kpUu8Nk+SyIV7s66ApFiArLKumj+AwRtjU4nntrECpngckK5bwecnn4zG3 cemEAawK4J1Y9aO/XAs25an8czLx9x1Ev6Fsl6PfjR7S/Zm2TOeLIKkHi8KMtDovePNE pgqPUlodJJ2ly02NLfpnfQScnuccJuPY28oeeZg9NRLreFdo/2u94MG5AdNxRTT3KtvA rCnw== 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=x7NIO2+4Tf0s8XbMNEYfDqSeztAdraJi6BU7fdZyEis=; b=GCZt7XdGdhjUbuMG3ZHZmDbUdoqIQUGX3frP298gg+LhOHL7IqjDuAWk7AacsyDQTY pLCxk74wwizVeZx0NwePRhShpvNAOrSt1TFMVzb78ieEzWwzlpBOcIOta14pBH/oNfZh ADMNeZleq+VBCSWx57h4vzzjnhJd9LRLCl/1+pKoe/vuSn40Jr+bbmj8LzQ7qbVbxcs7 NDpYy1gQIRbsLOtmMkP+5e383gC7pIIavI1PfkI+J6F4OrR0r8f0MnAgIjeOsXfqWG8D 0F+oM3CUY+4RLDmNoFCRkbtvDrVJB4kDZr4VQk+v1eBDlGdkkFIeifFc7VGQQqH06LBZ XG5Q== 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 n8-20020a05640205c800b00458e87a1d83si14003797edx.54.2022.10.18.05.38.24; Tue, 18 Oct 2022 05:38: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 782EE68BD1F; Tue, 18 Oct 2022 15:38: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 BBC4B68BCE1 for ; Tue, 18 Oct 2022 15:38:14 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 19976240D0E for ; Tue, 18 Oct 2022 14:38:14 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ss8ochhEmHd5 for ; Tue, 18 Oct 2022 14:38:13 +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 945622404F5 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9B78D3A13D9 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:44 +0200 Message-Id: <20221018123701.25002-3-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/20] fftools/ffmpeg: drop init_input_threads() 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: fTBBxPuzzxS2 Start threads implicitly when ifile_get_packet() is called. Simplifies the demuxer API. --- fftools/ffmpeg.c | 3 --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_demux.c | 24 +++++++++--------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ceb26145a3..aac35026bd 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3910,9 +3910,6 @@ static int transcode(void) timer_start = av_gettime_relative(); - if ((ret = init_input_threads()) < 0) - goto fail; - while (!received_sigterm) { int64_t cur_time= av_gettime_relative(); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 35410ec4a1..b60f415389 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -759,7 +759,6 @@ int ifile_open(OptionsContext *o, const char *filename); * - a negative error code on failure */ int ifile_get_packet(InputFile *f, AVPacket **pkt); -int init_input_threads(void); void free_input_threads(void); #define SPECIFIER_OPT_FMT_str "%s" diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index f92500abf9..aaa91293c3 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -330,11 +330,10 @@ void free_input_threads(void) free_input_thread(i); } -static int init_input_thread(int i) +static int thread_start(Demuxer *d) { int ret; - InputFile *f = input_files[i]; - Demuxer *d = demuxer_from_ifile(f); + InputFile *f = &d->f; if (f->thread_queue_size <= 0) f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); @@ -377,24 +376,19 @@ fail: return ret; } -int init_input_threads(void) -{ - int i, ret; - - for (i = 0; i < nb_input_files; i++) { - ret = init_input_thread(i); - if (ret < 0) - return ret; - } - return 0; -} - int ifile_get_packet(InputFile *f, AVPacket **pkt) { + Demuxer *d = demuxer_from_ifile(f); InputStream *ist; DemuxMsg msg; int ret; + if (!f->in_thread_queue) { + ret = thread_start(d); + if (ret < 0) + return ret; + } + if (f->readrate || f->rate_emu) { int i; int64_t file_start = copy_ts * ( From patchwork Tue Oct 18 12:36:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38786 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083149pzb; Tue, 18 Oct 2022 05:39:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7zv+8t3T/ud6zMZCKSfNTjfv1IFLv30Ks5wdwCgMKlknMFtglwblI1Zvxz5rNE1tWpGBKj X-Received: by 2002:a17:907:3e06:b0:733:693:600e with SMTP id hp6-20020a1709073e0600b007330693600emr2182338ejc.410.1666096777756; Tue, 18 Oct 2022 05:39:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096777; cv=none; d=google.com; s=arc-20160816; b=fghoeuV51hzy1LzVx4GdfsoSMaE69sXpJb5dNUa59cNsVnSY/XBqMrYlzjw27frXyD k6s8U8RjGJhldZTY4pzR4d8bCnfShQ1hvVM/HnG701N/mK7Kk/4v0s+nNYrjEt4jcPhJ yY08G9wS1xIfkgPlD3VubM0rHkbKO11OiD+POXlzynQlQl9fklIjI0j20UaJpH0JRTjB J7iNu6n9ZU7grwXqnpMgtkQw1g06eMM/ntt0/hNhdi7zujygsisczPVaoorw/UoIKguP CrdEX3pFsUmLUwW2txO99ngudjnQzODuTP9P0J4hNBfqkY5K8IrwV6Xccd2KnbhsRLY6 Y2Mw== 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=XGEm+hZMxPHGnOU7AfJ6UiumndODVgMWyZVXqPmi89U=; b=nMrbm/SWQMn22o/zH4x2kzMpByGyp36Ku5ubaqiryFmrgJoqh35XREtD3F86Uz0z84 ZgfbZrCqDGOwKx4Uxr3Xn2e15C5NYm3n+2FFVzaDjTqIQt/4/ZCFayo7o3TwwrbzV1iX Pyt05fJeZd/iycMt3kPOqWFQVVHZnVwfqS6e2EGIKNobEZ4UEw+UoMbXal3qOHBKZNNA Zz1eTUsPcjI4B4ax12yh9JtGlBk/PAaQVjNllOd/kPbToYuoX2ZeRCKteBOaePoO/bsN cqDRnRaIaE3iUbOsIyqts58sT4c5HFb9qrmGm8BruTkCMeEd0m324N9q946HwX9BxD1g uk9Q== 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 i9-20020a1709063c4900b0078db79317bbsi10237458ejg.689.2022.10.18.05.39.36; Tue, 18 Oct 2022 05:39:37 -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 CE86B68BCE1; Tue, 18 Oct 2022 15:38:30 +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 D70B268BD19 for ; Tue, 18 Oct 2022 15:38:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5D3F82404E4 for ; Tue, 18 Oct 2022 14:38:15 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ishFz7QJdNSt for ; Tue, 18 Oct 2022 14:38:14 +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 95F6C2404F7 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A73FA3A13E9 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:45 +0200 Message-Id: <20221018123701.25002-4-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/20] fftools/ffmpeg: move closing the input file into a separate function 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: g5sik70zkKVu For now this is just closing the format context and freeing InputFile, but will contain more in the future. --- fftools/ffmpeg.c | 7 +++---- fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index aac35026bd..d29d2e4e88 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -556,10 +556,9 @@ static void ffmpeg_cleanup(int ret) of_close(&output_files[i]); free_input_threads(); - for (i = 0; i < nb_input_files; i++) { - avformat_close_input(&input_files[i]->ctx); - av_freep(&input_files[i]); - } + for (i = 0; i < nb_input_files; i++) + ifile_close(&input_files[i]); + for (i = 0; i < nb_input_streams; i++) { InputStream *ist = input_streams[i]; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b60f415389..547660d5ef 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -747,6 +747,7 @@ AVChapter * const * of_get_chapters(OutputFile *of, unsigned int *nb_chapters); int ifile_open(OptionsContext *o, const char *filename); +void ifile_close(InputFile **f); /** * Get next input packet from the demuxer. diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index aaa91293c3..d2db0663ab 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -423,6 +423,18 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) return 0; } +void ifile_close(InputFile **pf) +{ + InputFile *f = *pf; + + if (!f) + return; + + avformat_close_input(&f->ctx); + + av_freep(pf); +} + static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) From patchwork Tue Oct 18 12:36:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38781 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2082803pzb; Tue, 18 Oct 2022 05:38:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MHcSdPcJorf11sIZlt7NHQ4Wsb3i17vlUQtLOXW6d+CRHYPoMU+wi3X1Xpgl5tUrw7eXH X-Received: by 2002:a17:907:75f1:b0:78a:f935:647d with SMTP id jz17-20020a17090775f100b0078af935647dmr2225129ejc.587.1666096732845; Tue, 18 Oct 2022 05:38:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096732; cv=none; d=google.com; s=arc-20160816; b=Iq9H6Yl2WQ3KovC0lejXKBxQaKTLcpC9mZ115UL009U/2AH8DRNL1Bsoio/SI/iWdl cwd91ShEtTTIzpcL/S+VZlhE3hum3B7nYIUvDa0exe2wUqRCUN3sbqs7HBasU5/chmMp VphY1xr76Kthf2KRHQWVmluhIDpaOHL60m7doWCxwOsJh6sSOc7/QstfwI4K+czCB45S ILhen4oU198fIKmQEbAgHawttC0OBWvVYqJDFcXQFUErM+MBldcPTE/h6y72DyDTOK83 euP0OH6pxuw5Ts/Ohp/znfdVwJlAXLuEM7KoH3w6ZrWMpDv0ecpbi6VATpuYOZnxKvf+ AIRA== 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=6lBHztwWASQuMkAa3jR9uD0LePo62RtWU5SOZRgjBUc=; b=eAf7/2P/L+bztF/pvvQsOrKvebihibNX02DqDg6XlgERKNyVLD8mFbKI5qMwyNlMTr D0ARDmZAo0Xenm0SPrKgbKtmjxc20vkkv4Ory3i1KWhzEDyuRvt8KYN+WDSHT4cvnjvg rKGAY8V5ypZh/fAf7mj67coIraCeGMFvy5HfyaDE2AZQ83nuLYrcVKw7gYhdjDqJRi1i sK9C6abyqokEpazWG7Xg1Nkk2GEt08TSmakYuXzrXBINYnDAghb6BROJvzvAu/ZEr0k/ rgvN6BQi2MEr13ObhwEQ7+XRK8XZwsfb6THmtagacLc9FAYEVE0sdcmG3rY37mzcId3j /K5Q== 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 c6-20020a05640227c600b0045d4492a8a5si2944619ede.337.2022.10.18.05.38.52; Tue, 18 Oct 2022 05:38:52 -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 96FB368BD69; Tue, 18 Oct 2022 15:38: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 9627368BCF7 for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DD87B2406C7 for ; Tue, 18 Oct 2022 14:38:17 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cZ9psUygAl3y for ; Tue, 18 Oct 2022 14:38:16 +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 A64A32405EC for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A877F3A168C for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:46 +0200 Message-Id: <20221018123701.25002-5-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/20] fftools/ffmpeg: drop free_input_threads() 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: qCHutNPlVqhu Stop demuxer threads in ifile_close() instead. Simplifies the demuxer API. --- fftools/ffmpeg.c | 4 ---- fftools/ffmpeg.h | 1 - fftools/ffmpeg_demux.c | 17 ++++++----------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d29d2e4e88..3ad3fff5cd 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -555,7 +555,6 @@ static void ffmpeg_cleanup(int ret) for (i = 0; i < nb_output_files; i++) of_close(&output_files[i]); - free_input_threads(); for (i = 0; i < nb_input_files; i++) ifile_close(&input_files[i]); @@ -3932,7 +3931,6 @@ static int transcode(void) /* dump report by using the output first video and audio streams */ print_report(0, timer_start, cur_time); } - free_input_threads(); /* at the end of stream, we must flush the decoder buffers */ for (i = 0; i < nb_input_streams; i++) { @@ -3985,8 +3983,6 @@ static int transcode(void) ret = 0; fail: - free_input_threads(); - return ret; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 547660d5ef..823347f670 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -760,7 +760,6 @@ void ifile_close(InputFile **f); * - a negative error code on failure */ int ifile_get_packet(InputFile *f, AVPacket **pkt); -void free_input_threads(void); #define SPECIFIER_OPT_FMT_str "%s" #define SPECIFIER_OPT_FMT_i "%i" diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index d2db0663ab..5c75dd5b23 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -306,12 +306,12 @@ finish: return NULL; } -static void free_input_thread(int i) +static void thread_stop(Demuxer *d) { - InputFile *f = input_files[i]; + InputFile *f = &d->f; DemuxMsg msg; - if (!f || !f->in_thread_queue) + if (!f->in_thread_queue) return; av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); while (av_thread_message_queue_recv(f->in_thread_queue, &msg, 0) >= 0) @@ -322,14 +322,6 @@ static void free_input_thread(int i) av_thread_message_queue_free(&f->audio_duration_queue); } -void free_input_threads(void) -{ - int i; - - for (i = 0; i < nb_input_files; i++) - free_input_thread(i); -} - static int thread_start(Demuxer *d) { int ret; @@ -426,10 +418,13 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) void ifile_close(InputFile **pf) { InputFile *f = *pf; + Demuxer *d = demuxer_from_ifile(f); if (!f) return; + thread_stop(d); + avformat_close_input(&f->ctx); av_freep(pf); From patchwork Tue Oct 18 12:36:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38779 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083581pzb; Tue, 18 Oct 2022 05:40:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lcrIjJ0nok5uYZ4hOB0KlmIlQppq2zkUrZ1HfYiIA3OmUARKZ2Y7nS2G/cAPrK+3WJ3fw X-Received: by 2002:aa7:c98d:0:b0:45c:6451:320e with SMTP id c13-20020aa7c98d000000b0045c6451320emr2442574edt.172.1666096846084; Tue, 18 Oct 2022 05:40:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096846; cv=none; d=google.com; s=arc-20160816; b=EbboGSZftMoOB8p4XIgV+/8YQD7b0hdbzkiMZfvFu8VBMe5c3sYnFjHjkqr/2Zya9X qT24whEdbVXfRclv0kKPMDGa7mkKaPIsRcSE+hvudnkpY7Uds/PWe8tM1QhX9dKUucgc /QMg3ERdtLZvMExYFJ3V/x+gVdKA99+Zm0LNS9TK8REX+LBJjKnZcOsqYETI835Wulhs 5RqP4SRNjYKNTMMokMNjX2BZQJufT+fDdkeKvyKqI/0Qh4KdqwCXlthzpRWfILxBAWyN v485m3dIiUvRdJve5/6rEFT4ALQxy+fearSOHJXbqmAdgZNKyyOhjjyk+o/8n5oaVQYE Wqmw== 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=GSa+oOJk/MHVUzbT2AqpekPzmWpqlLUkxBxNbo6LLpM=; b=M4EZPuqk944tmXEncs2p7x4zt5x22U+qYFKgskX6arOF7XsVgGTrq85PASZ/ucW3dw 1DvXN9ZCksWQzHDrU82xICuh6fM1dgMMFtvzF8BKdTJGUBKozYVkq5KHo4b61USYsqXa DPylFIuDeLZkpNbc5zu0cG9HQYhnSsJx0xsxK9V8lTANSlkuo/bWimMgQeM1lVJ71jgi A0VTzzDvij1tBq1RJm6wLbj0ucffqq+NNuO292EAE9KJHAAmrTQ0le58wJD/FaFXJ1NX aFzmFiYYv3taQPNJ/54qOmYuSMHHMFY8OQLPlGl5bY/Xrls021NGtkXLWy+cSetPScAB /8yA== 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 m10-20020a50cc0a000000b00458d94f1a45si10301524edi.413.2022.10.18.05.40.45; Tue, 18 Oct 2022 05:40: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 8C13D68BDC1; Tue, 18 Oct 2022 15:38:38 +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 0763568BD36 for ; Tue, 18 Oct 2022 15:38:17 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 85D35240591 for ; Tue, 18 Oct 2022 14:38:16 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id g-MQmZmIUwvp for ; Tue, 18 Oct 2022 14:38:15 +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 99C772404F8 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A9EDD3A168D for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:47 +0200 Message-Id: <20221018123701.25002-6-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/20] fftools/ffmpeg: move threading fields from InputFile to Demuxer 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: oHzD2CT3CxVM They are private to the demuxer and do not need to be visible outside of it. --- fftools/ffmpeg.h | 5 ----- fftools/ffmpeg_demux.c | 49 +++++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 823347f670..8c3effdb05 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -455,11 +455,6 @@ typedef struct InputFile { float readrate; int accurate_seek; - AVThreadMessageQueue *in_thread_queue; - pthread_t thread; /* thread reading from this file */ - int non_blocking; /* reading packets from the thread should not block */ - int thread_queue_size; /* maximum number of queued packets */ - /* when looping the input file, this queue is used by decoders to report * the last frame duration back to the demuxer thread */ AVThreadMessageQueue *audio_duration_queue; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 5c75dd5b23..90868de7aa 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -50,6 +50,11 @@ typedef struct Demuxer { /* number of times input stream should be looped */ int loop; + + AVThreadMessageQueue *in_thread_queue; + int thread_queue_size; + pthread_t thread; + int non_blocking; } Demuxer; typedef struct DemuxMsg { @@ -211,7 +216,7 @@ static void *input_thread(void *arg) Demuxer *d = arg; InputFile *f = &d->f; AVPacket *pkt; - unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; + unsigned flags = d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; int ret = 0; pkt = av_packet_alloc(); @@ -233,7 +238,7 @@ static void *input_thread(void *arg) if (d->loop) { /* signal looping to the consumer thread */ msg.looping = 1; - ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0); + ret = av_thread_message_queue_send(d->in_thread_queue, &msg, 0); if (ret >= 0) ret = seek_to_start(d); if (ret >= 0) @@ -278,14 +283,14 @@ static void *input_thread(void *arg) break; } av_packet_move_ref(msg.pkt, pkt); - ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags); + ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags); if (flags && ret == AVERROR(EAGAIN)) { flags = 0; - ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags); + ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags); av_log(f->ctx, AV_LOG_WARNING, "Thread message queue blocking; consider raising the " "thread_queue_size option (current value: %d)\n", - f->thread_queue_size); + d->thread_queue_size); } if (ret < 0) { if (ret != AVERROR_EOF) @@ -299,7 +304,7 @@ static void *input_thread(void *arg) finish: av_assert0(ret < 0); - av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); + av_thread_message_queue_set_err_recv(d->in_thread_queue, ret); av_packet_free(&pkt); @@ -311,14 +316,14 @@ static void thread_stop(Demuxer *d) InputFile *f = &d->f; DemuxMsg msg; - if (!f->in_thread_queue) + if (!d->in_thread_queue) return; - av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); - while (av_thread_message_queue_recv(f->in_thread_queue, &msg, 0) >= 0) + av_thread_message_queue_set_err_send(d->in_thread_queue, AVERROR_EOF); + while (av_thread_message_queue_recv(d->in_thread_queue, &msg, 0) >= 0) av_packet_free(&msg.pkt); - pthread_join(f->thread, NULL); - av_thread_message_queue_free(&f->in_thread_queue); + pthread_join(d->thread, NULL); + av_thread_message_queue_free(&d->in_thread_queue); av_thread_message_queue_free(&f->audio_duration_queue); } @@ -327,14 +332,14 @@ static int thread_start(Demuxer *d) int ret; InputFile *f = &d->f; - if (f->thread_queue_size <= 0) - f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); + if (d->thread_queue_size <= 0) + d->thread_queue_size = (nb_input_files > 1 ? 8 : 1); if (f->ctx->pb ? !f->ctx->pb->seekable : strcmp(f->ctx->iformat->name, "lavfi")) - f->non_blocking = 1; - ret = av_thread_message_queue_alloc(&f->in_thread_queue, - f->thread_queue_size, sizeof(DemuxMsg)); + d->non_blocking = 1; + ret = av_thread_message_queue_alloc(&d->in_thread_queue, + d->thread_queue_size, sizeof(DemuxMsg)); if (ret < 0) return ret; @@ -356,7 +361,7 @@ static int thread_start(Demuxer *d) } } - if ((ret = pthread_create(&f->thread, NULL, input_thread, d))) { + if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) { av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); ret = AVERROR(ret); goto fail; @@ -364,7 +369,7 @@ static int thread_start(Demuxer *d) return 0; fail: - av_thread_message_queue_free(&f->in_thread_queue); + av_thread_message_queue_free(&d->in_thread_queue); return ret; } @@ -375,7 +380,7 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) DemuxMsg msg; int ret; - if (!f->in_thread_queue) { + if (!d->in_thread_queue) { ret = thread_start(d); if (ret < 0) return ret; @@ -400,8 +405,8 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) } } - ret = av_thread_message_queue_recv(f->in_thread_queue, &msg, - f->non_blocking ? + ret = av_thread_message_queue_recv(d->in_thread_queue, &msg, + d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0); if (ret < 0) return ret; @@ -968,7 +973,7 @@ int ifile_open(OptionsContext *o, const char *filename) f->rate_emu = 0; } - f->thread_queue_size = o->thread_queue_size; + d->thread_queue_size = o->thread_queue_size; /* check if all codec options have been used */ unused_opts = strip_specifiers(o->g->codec_opts); From patchwork Tue Oct 18 12:36:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38794 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083636pzb; Tue, 18 Oct 2022 05:40:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6rb+obiH0iFGUbx3d/MKjW4EIMPXgJED/6dzBfsSckWQE3yD7xSO6Yy5kva5RoXxS1JSla X-Received: by 2002:a17:907:b0b:b0:78d:8877:9f9e with SMTP id h11-20020a1709070b0b00b0078d88779f9emr2207804ejl.693.1666096855751; Tue, 18 Oct 2022 05:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096855; cv=none; d=google.com; s=arc-20160816; b=OyI5AyEzVLJWoN28XkwrW+aHtY9IyYPnYXsrumP9jngTcaeg5wHUvqWqBcYtsFe+Mc FFvXZdir7fUic+wDg1t9+ZGq9DBaSLLcoDY1J04p4JPKLOP7fqQ/6rfo5NbN4D1zUv+0 2AuS2JT3AV9bANkp65t3GvRqO1O9YvU/IRI2aRmY8DND+1vuRI4OOXCwCUQULUlo65Ih iUUz7biKHcFvZpfjS9Ju6sQW9vD6EqeDV4qHfaBn9sL/3FrmKdG4NbhB7FxS6SnQwLMX HiRxElaFQCDZk9Y3qD5TVsUhaZuKnXokPdInERHOg0ralPV6kmKlMXnR8z/+UFVI5eBo aLnw== 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=xnHUP/hr7AonnUcNcyCWEyoEukiNhboN7Pt2nb4EYNo=; b=YdrB7pdJTUO+s4QmMf0dxDT37aVIcg0kv9UtEVYl7W0fwgyV6CzIaAIP4SZx2ufasz Xv2ntQwucRhETGpCFVHdVzfxN6UoyM2P9VgLO7+442LQctkaq3Z20G3sgjw67M3dj4TS 1qterp83TWd2I6twG8gAgJEnELJZYJTvMjgi7bs/HqaH3a61lFWZwUCiIDlfZ/5UvBXe Sbn+dpCnLjiLYQw4o2Jrbp/NmJ3HHjnr3AFxoB8VLCGBEjI9Y13Ejmg1k3PR2SqAMaTi avRY/SG9Fk2oPZM1PIUoxWgvBkgLX5SAq9ilJYJ8iti6MlE/oI0f/tSddU9mIsdEpIep aGoA== 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 s15-20020a05640217cf00b00458d63dee39si10103330edy.472.2022.10.18.05.40.55; Tue, 18 Oct 2022 05:40:55 -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 1398368BDCC; Tue, 18 Oct 2022 15:38:40 +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 E91A468BD3C for ; Tue, 18 Oct 2022 15:38:22 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 69D592404F5 for ; Tue, 18 Oct 2022 14:38:22 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6lQ_cE7gmTt3 for ; Tue, 18 Oct 2022 14:38:20 +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 D699E2406D0 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B5B723A1767 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:48 +0200 Message-Id: <20221018123701.25002-7-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/20] fftools/ffmpeg: move duration/time_base from InputFile to Demuxer 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: LuSdnpO0ZkYn They are private to the demuxer and do not need to be visible outside of it. --- fftools/ffmpeg.h | 3 --- fftools/ffmpeg_demux.c | 30 ++++++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8c3effdb05..2f635c779d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -434,9 +434,6 @@ typedef struct InputFile { int eof_reached; /* true if eof reached */ int eagain; /* true if last read attempt returned EAGAIN */ int ist_index; /* index of first stream in input_streams */ - int64_t duration; /* actual duration of the longest stream in a file - at the moment when looping happens */ - AVRational time_base; /* time base of the duration */ int64_t input_ts_offset; int input_sync_ref; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 90868de7aa..fe1b3bd8b7 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -50,6 +50,11 @@ typedef struct Demuxer { /* number of times input stream should be looped */ int loop; + /* actual duration of the longest stream in a file at the moment when + * looping happens */ + int64_t duration; + /* time base of the duration */ + AVRational time_base; AVThreadMessageQueue *in_thread_queue; int thread_queue_size; @@ -84,7 +89,7 @@ static void report_new_stream(InputFile *file, const AVPacket *pkt) file->nb_streams_warn = pkt->stream_index + 1; } -static void ifile_duration_update(InputFile *f, InputStream *ist, +static void ifile_duration_update(Demuxer *d, InputStream *ist, int64_t last_duration) { /* the total duration of the stream, max_pts - min_pts is @@ -93,11 +98,11 @@ static void ifile_duration_update(InputFile *f, InputStream *ist, ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - last_duration) last_duration += ist->max_pts - ist->min_pts; - if (!f->duration || - av_compare_ts(f->duration, f->time_base, + if (!d->duration || + av_compare_ts(d->duration, d->time_base, last_duration, ist->st->time_base) < 0) { - f->duration = last_duration; - f->time_base = ist->st->time_base; + d->duration = last_duration; + d->time_base = ist->st->time_base; } } @@ -126,7 +131,7 @@ static int seek_to_start(Demuxer *d) got_durations++; ist = input_streams[ifile->ist_index + dur.stream_idx]; - ifile_duration_update(ifile, ist, dur.duration); + ifile_duration_update(d, ist, dur.duration); } } else { for (int i = 0; i < ifile->nb_streams; i++) { @@ -141,7 +146,7 @@ static int seek_to_start(Demuxer *d) duration = 1; } - ifile_duration_update(ifile, ist, duration); + ifile_duration_update(d, ist, duration); } } @@ -151,8 +156,9 @@ static int seek_to_start(Demuxer *d) return ret; } -static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) +static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict) { + InputFile *ifile = &d->f; InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index]; const int64_t start_time = ifile->ctx->start_time; int64_t duration; @@ -195,7 +201,7 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) if (pkt->dts != AV_NOPTS_VALUE) pkt->dts *= ist->ts_scale; - duration = av_rescale_q(ifile->duration, ifile->time_base, ist->st->time_base); + duration = av_rescale_q(d->duration, d->time_base, ist->st->time_base); if (pkt->pts != AV_NOPTS_VALUE) { pkt->pts += duration; ist->max_pts = FFMAX(pkt->pts, ist->max_pts); @@ -274,7 +280,7 @@ static void *input_thread(void *arg) } } - ts_fixup(f, pkt, &msg.repeat_pict); + ts_fixup(d, pkt, &msg.repeat_pict); msg.pkt = av_packet_alloc(); if (!msg.pkt) { @@ -960,8 +966,8 @@ int ifile_open(OptionsContext *o, const char *filename) f->rate_emu = o->rate_emu; f->accurate_seek = o->accurate_seek; d->loop = o->loop; - f->duration = 0; - f->time_base = (AVRational){ 1, 1 }; + d->duration = 0; + d->time_base = (AVRational){ 1, 1 }; f->readrate = o->readrate ? o->readrate : 0.0; if (f->readrate < 0.0f) { From patchwork Tue Oct 18 12:36:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38791 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083410pzb; Tue, 18 Oct 2022 05:40:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ktD/UTv5NkCS0wpXfPCszO49YIsoIiwxEVSJ2WUAclfrdHT/oxA8C5p6l39N4Y/VaRNpk X-Received: by 2002:a05:6402:538a:b0:457:b602:d5a6 with SMTP id ew10-20020a056402538a00b00457b602d5a6mr2435478edb.371.1666096819303; Tue, 18 Oct 2022 05:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096819; cv=none; d=google.com; s=arc-20160816; b=mLzESDufhNMfVUtMR0Bi398JRalK/QNy8F6RdmEtAWQpVluuYGVRYZQou/E2mzQptA TbTOfVPoD7zHp4vmzaIkn/y8umxVo4wQVygI7X47L9wR5eaEfqxqxaBHH5blOAyobeLY lEjWoe1BKwyvYLRZbh7fPTuWaFKBPWTd+Qjtic1VkXB7itNSWVnKpu6KAIIngIqLoVI4 apBsU1uKaBm7g8ie6oScjFuAuXRMMQPxneskz43IFTrgt8SGwlPnP1uVxxGPmWxcuklp oa+gOKWO8kjMx7oUUt7K3z5wHjGapyIxUoR18NArVWuBtMfo13eWVyVJKqplmq1EH1MY 32Aw== 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=FuEJJBuRMa3gAdZ38LHvbEeUjZB7sOLTYPZMMmU6OpU=; b=dSHthvp7AL1xV7N0aCNe+hsWCNXINiJptfFcpKiQVs5ZP8R9F5TgBRAdkuIxhS81q4 L1FoV4ezfpfOrFePHgm7lhW7HqxG6ZwAUmMZvieN/oSEZgLAC2aW8xnghzwemUzDSFDY IiU6ZBLxoCkNQAjfKSrYpebyBXOQx9y+da1Cbecg8b7/lMQ7ZG7oOW4cgViJqyBBu1UI cX2irXCNpPPRanwTpN1Bxkqyilf05pxq5JI8LZlAS6YeCOQ3ncdYPUzKbIR/AmjPdZS+ QbpI4oeuVD6g1pXK7RQlkQZPDx/1xTdsCCNUc9tMg42qKJxQ5BlCE1wHedP1c6ZoFwSr R1Tg== 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 nc23-20020a1709071c1700b00779f8e7ec5bsi12438369ejc.42.2022.10.18.05.40.18; Tue, 18 Oct 2022 05:40:19 -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 8974768BDAC; Tue, 18 Oct 2022 15:38:35 +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 4C27E68BD1F for ; Tue, 18 Oct 2022 15:38:16 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CACD92404F7 for ; Tue, 18 Oct 2022 14:38:15 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id z1ZBCt63Y3yk for ; Tue, 18 Oct 2022 14:38:15 +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 A5B4C240591 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B70E43A17F4 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:49 +0200 Message-Id: <20221018123701.25002-8-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/20] fftools/ffmpeg_demux: do not log to the demuxer context 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: CZMI3lSTfoq/ Only the demuxer itself is supposed to do that. --- fftools/ffmpeg_demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index fe1b3bd8b7..e5e7cd1a54 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -81,7 +81,7 @@ static void report_new_stream(InputFile *file, const AVPacket *pkt) if (pkt->stream_index < file->nb_streams_warn) return; - av_log(file->ctx, AV_LOG_WARNING, + av_log(NULL, AV_LOG_WARNING, "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n", av_get_media_type_string(st->codecpar->codec_type), file->index, pkt->stream_index, From patchwork Tue Oct 18 12:36:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38788 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083258pzb; Tue, 18 Oct 2022 05:39:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gIZzzjfXYuXXKtwS4jagpou6L5tDBpRtipk5MushTVWeYu4tKvZ517cStYXxVD9cHbIkv X-Received: by 2002:a05:6402:28b7:b0:459:3115:aa07 with SMTP id eg55-20020a05640228b700b004593115aa07mr2349779edb.280.1666096793952; Tue, 18 Oct 2022 05:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096793; cv=none; d=google.com; s=arc-20160816; b=LjALnbO7rt7gbuWVyhgJfGUuOsufu4BRmWvDEAkxbcGOHK4M/nIuidcGeqCAMKqF68 DeYRPi+zmUaTY+I1QWpXBsTyFYAA6JlIMjxnzwZLxhATzl0wA8sYpSzEwGEzlpqTUrKB jDsFmMrEF/ZBznFaRVtw97vlIlvIgNdgZ+H/mdIAm4geBvhWuOYzrJncxcWS/PS4puzR +FetaiHKx0Th4SN5Jy6YNOtXZQIF14Ip8EEgMXJV+sK+uxfT8TDRulM9FSsITp3cm0pa g9QWynfuSH+hwti2MYywvDcgy2W+1/hAX703ww+dGb5/q+qHLbiMZtiIFr+JkxTZ/HEA GuEg== 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=BlRCNWPNaCqG5DTd3MDW6uKfXNZzVpeCQ4F5u86QGY4=; b=VuwNkRwhBsO1kjfSkR217wXh+YycT97DtTgVw8otop0e5O1pJT0TKrGs+lG97GF9VU k8YTG+l5DVngrsBapPPb54ROlSs9jKYUthq0uxcfxUywsSkkC8FOUO5HWGNY8tbz5ETG Ju+z9fxxVvD3M1AC5nJcfFZ6rgoAdv8jzNWHyQq4MmL7nhNom/D/QzQnY5Qsoumissje obDgqfDHy6qu6KyX0pyey2HrKbdHIygL5E/t7AEYOYt2YBxiWZz9MwXhL0ii2XrXn4yL NzMwR5eDwGiLYscSkb1AipzuQaQUexQT4GrrKPYZJ+jQdtOcPgV++mm7Oe/CB/EjTsTI tHYA== 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 hz5-20020a1709072ce500b007919d2f6517si1538019ejc.737.2022.10.18.05.39.53; Tue, 18 Oct 2022 05:39:53 -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 CD3FF68BD97; Tue, 18 Oct 2022 15:38:32 +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 21EE668BD28 for ; Tue, 18 Oct 2022 15:38:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 76D122406CC for ; Tue, 18 Oct 2022 14:38:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6fCGgy56Ohmh for ; Tue, 18 Oct 2022 14:38:19 +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 CBC0D2406CE for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B7EA53A184A for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:50 +0200 Message-Id: <20221018123701.25002-9-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/20] fftools/ffmpeg: move nb_streams_warn from InputFile to Demuxer 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: hfWXVhS2WpEf It is private to the demuxer and do not need to be visible outside of it. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_demux.c | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 2f635c779d..a124b1b045 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -447,7 +447,6 @@ typedef struct InputFile { int64_t recording_time; int nb_streams; /* number of stream that ffmpeg is aware of; may be different from ctx.nb_streams if new streams appear during av_read_frame() */ - int nb_streams_warn; /* number of streams that the user was warned of */ int rate_emu; float readrate; int accurate_seek; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index e5e7cd1a54..040213b392 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -56,6 +56,9 @@ typedef struct Demuxer { /* time base of the duration */ AVRational time_base; + /* number of streams that the user was warned of */ + int nb_streams_warn; + AVThreadMessageQueue *in_thread_queue; int thread_queue_size; pthread_t thread; @@ -75,18 +78,18 @@ static Demuxer *demuxer_from_ifile(InputFile *f) return (Demuxer*)f; } -static void report_new_stream(InputFile *file, const AVPacket *pkt) +static void report_new_stream(Demuxer *d, const AVPacket *pkt) { - AVStream *st = file->ctx->streams[pkt->stream_index]; + AVStream *st = d->f.ctx->streams[pkt->stream_index]; - if (pkt->stream_index < file->nb_streams_warn) + if (pkt->stream_index < d->nb_streams_warn) return; av_log(NULL, AV_LOG_WARNING, "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n", av_get_media_type_string(st->codecpar->codec_type), - file->index, pkt->stream_index, + d->f.index, pkt->stream_index, pkt->pos, av_ts2timestr(pkt->dts, &st->time_base)); - file->nb_streams_warn = pkt->stream_index + 1; + d->nb_streams_warn = pkt->stream_index + 1; } static void ifile_duration_update(Demuxer *d, InputStream *ist, @@ -264,7 +267,7 @@ static void *input_thread(void *arg) /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ if (pkt->stream_index >= f->nb_streams) { - report_new_stream(f, pkt); + report_new_stream(d, pkt); av_packet_unref(pkt); continue; } From patchwork Tue Oct 18 12:36:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38795 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083690pzb; Tue, 18 Oct 2022 05:41:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62CI3hzb0Mt9sNYDGerb/VYh4OlowzSEhYY9cqkKKIQ/qXmLfbjUVpYuGaAB7LvYOnobfP X-Received: by 2002:a17:907:8a23:b0:78d:b042:eece with SMTP id sc35-20020a1709078a2300b0078db042eecemr2188381ejc.494.1666096864286; Tue, 18 Oct 2022 05:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096864; cv=none; d=google.com; s=arc-20160816; b=KDBKdOeU7u8CAMioeBjUxBhN/wVr4dG6v7ZPpS0ZKzl85zll6gCIiY9tzvIMG/d9sV TpB/H1kEqQMKZdP1K2Vi3Eh3XpLFaZCvCwlS3MT1Nbrr8fKCjm4Gu1Z/rWsRhlj+p09f BzhnaePSqtdYN+vj4Lksh0HK/3OA1oYhdR0J1zl43Rdmb/sRXW+uaXHfzSbPMcHAd9Xy 4oOjbLhFm9dFOiAhbrjqbPHtCoUzG4Ytd1bgk1Xm6NSQrdfng168ipRt+kPlfpix+gJ2 QbFMn3E+mtYcDzOM7YH9EhdBV9dDeCpxb5qY6CRATwtBfAporEQ8TUH/Ae/H4cDQItrF cH9A== 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=3BgPR8rZxkw9nzdeJ4RUtpq1PLK4ObgGO2z64wh6ekU=; b=oAUwrv2oogWXOUDZ1L1LCKLObNs2Vc9N7bA4AsoKK29JIPIdrjb1QiWNtiT6th/UD4 bb6CtAc8z/1OjqYJl7OPzICsxnXoQOVqM5FEkXdcPbVCMUi0AcLQJLmzvtQ9EQPRy+RE jENOOlSNDHDIXX1ZdbDwD+mAEmhcVvqcRwzH+XOTEdyVR4+HqOSDYJJv6RlCUs98VhtS XrNQSAxq2hG/fPogtHvy2DaQeJlBq2Uf9B8TB9kw4vtJrdq6xJnd6mEK11t9wWOqNs8q yWpit46VLs9rMUOOlejPxfq2LJ3tu5XjzzY1OCAV6dJZ26H44fC7kBOtpnnBx4Ngwc5D fBoA== 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 y16-20020a056402359000b0045d15f39bf4si13407940edc.479.2022.10.18.05.41.03; Tue, 18 Oct 2022 05:41: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 ED4F068BDD2; Tue, 18 Oct 2022 15:38:40 +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 01D9A68BD3D for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 87B4C2400F4 for ; Tue, 18 Oct 2022 14:38:17 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id gyO_yPBnTn3T for ; Tue, 18 Oct 2022 14:38:17 +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 AF07E2406C7 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B8C643A18BC for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:51 +0200 Message-Id: <20221018123701.25002-10-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/20] fftools/ffmpeg_demux: log when the demuxer thread terminates 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: pcR0c0Kqg4Oa Similar to what is done for muxing, may be useful for debugging. --- fftools/ffmpeg_demux.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 040213b392..29cff4b471 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -256,6 +256,12 @@ static void *input_thread(void *arg) /* fallthrough to the error path */ } + if (ret == AVERROR_EOF) + av_log(NULL, AV_LOG_VERBOSE, "EOF in input file %d\n", f->index); + else + av_log(NULL, AV_LOG_ERROR, "Error demuxing input file %d: %s\n", + f->index, av_err2str(ret)); + break; } @@ -317,6 +323,8 @@ finish: av_packet_free(&pkt); + av_log(NULL, AV_LOG_VERBOSE, "Terminating demuxer thread %d\n", f->index); + return NULL; } From patchwork Tue Oct 18 12:36:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38785 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083085pzb; Tue, 18 Oct 2022 05:39:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5VlK5kdLgGR9kznZedPQGymOvwtxIraC3YqqQagmPpSM6Z8u1HaIDlPp689fS+AqpBWXIA X-Received: by 2002:a17:906:4a09:b0:78d:b6bb:ff5f with SMTP id w9-20020a1709064a0900b0078db6bbff5fmr2157809eju.538.1666096768020; Tue, 18 Oct 2022 05:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096768; cv=none; d=google.com; s=arc-20160816; b=iMiO2CesCUCmLTKV+CDndP+pjUjtdF6mrSvBD7jYVkJ2G3QNpuTDdPgzGoahseailA MxksqRRH4wJzLcpo4YOs0onG7+3dwuoNyMTZu/92U8sZmaLIvoZ/gH6akBxgohq4XGTx OwOudSVHlB7Xxowzp+VcPeFz3I9BVR08XEZMc4YFgpBLnDedsAmxSmJMsJJPEb2JXUTp b/f9StzPvgD+mzQJmljEzK0A7IHxxDmxandnE4wDEhgWIIo/g0srMqgrVjjV834zjnyy ozKnWeGu6fHaNQg6pUvu6dt9bZ4CHHRoZ2mVi2Rq2fxh0XwlHE3ZUTouWrsIASTnTmeV sh3Q== 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=iF7HcsGeLsZfH+F2vLzctzEqCyAiPabS0wADMi78Ur0=; b=oeAScfbc85DvnolaWld325KhY1iHdh7JXu6PENZCtno7yTpn112JtuLgsjlHNHGcbL 0A2N7LojUZ5VqFc459QW7N7cWIICSDbbDwsDWAMg84TWNiIPT6q6MDK17KFYF4d/cXbu Jh8UiImika7FfIWPpOQak56ravYY4YDTocvOUQXVm+g8IODlX6RT2SDVLpIIlB2tmtxx oflCQTTM0EmaQUu66OKBKnLVle5sDAqGZH15xTWnTzxHvvcOuOLAl8t+f4E/2OifEJWC YIQqOncY9cV4FHsGIDtJWM+OlZBNLzFHCELYZeSnocKvp9Q33P+lrQyUKPTQSwDiJaUt f0FA== 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 o8-20020a170906974800b0078c39937f73si11417061ejy.798.2022.10.18.05.39.27; Tue, 18 Oct 2022 05:39:28 -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 B1C2968BD6B; Tue, 18 Oct 2022 15:38:29 +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 D350B68BD15 for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8C97F2406CA for ; Tue, 18 Oct 2022 14:38:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QqBFlRdP0FyW for ; Tue, 18 Oct 2022 14:38:17 +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 AE3B12405F9 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B99623A18F7 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:52 +0200 Message-Id: <20221018123701.25002-11-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/20] fftools/ffmpeg: factor out copying metadata/chapters from of_open() 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: I/SKdVbPGwM9 This code shares variables like OptionsContext.metadata_*_manual, so it makes sense to group it together. --- fftools/ffmpeg_mux_init.c | 123 ++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index aa958052d1..cd46f441cf 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1533,6 +1533,70 @@ static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFor return 0; } +static void copy_meta(Muxer *mux, OptionsContext *o) +{ + OutputFile *of = &mux->of; + AVFormatContext *oc = mux->fc; + + /* copy metadata */ + for (int i = 0; i < o->nb_metadata_map; i++) { + char *p; + int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0); + + if (in_file_index >= nb_input_files) { + av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); + exit_program(1); + } + copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, + in_file_index >= 0 ? + input_files[in_file_index]->ctx : NULL, o); + } + + /* copy chapters */ + if (o->chapters_input_file >= nb_input_files) { + if (o->chapters_input_file == INT_MAX) { + /* copy chapters from the first input file that has them*/ + o->chapters_input_file = -1; + for (int i = 0; i < nb_input_files; i++) + if (input_files[i]->ctx->nb_chapters) { + o->chapters_input_file = i; + break; + } + } else { + av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n", + o->chapters_input_file); + exit_program(1); + } + } + if (o->chapters_input_file >= 0) + copy_chapters(input_files[o->chapters_input_file], of, oc, + !o->metadata_chapters_manual); + + /* copy global metadata by default */ + if (!o->metadata_global_manual && nb_input_files){ + av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata, + AV_DICT_DONT_OVERWRITE); + if(o->recording_time != INT64_MAX) + av_dict_set(&oc->metadata, "duration", NULL, 0); + av_dict_set(&oc->metadata, "creation_time", NULL, 0); + av_dict_set(&oc->metadata, "company_name", NULL, 0); + av_dict_set(&oc->metadata, "product_name", NULL, 0); + av_dict_set(&oc->metadata, "product_version", NULL, 0); + } + if (!o->metadata_streams_manual) + for (int i = 0; i < of->nb_streams; i++) { + OutputStream *ost = of->streams[i]; + InputStream *ist; + if (ost->source_index < 0) /* this is true e.g. for attached files */ + continue; + ist = input_streams[ost->source_index]; + av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); + if (ost->enc_ctx) { + av_dict_set(&ost->st->metadata, "encoder", NULL, 0); + } + } +} + static int set_dispositions(OutputFile *of, AVFormatContext *ctx) { int nb_streams[AVMEDIA_TYPE_NB] = { 0 }; @@ -1839,63 +1903,8 @@ int of_open(OptionsContext *o, const char *filename) } oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE); - /* copy metadata */ - for (i = 0; i < o->nb_metadata_map; i++) { - char *p; - int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0); - - if (in_file_index >= nb_input_files) { - av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); - exit_program(1); - } - copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, - in_file_index >= 0 ? - input_files[in_file_index]->ctx : NULL, o); - } - - /* copy chapters */ - if (o->chapters_input_file >= nb_input_files) { - if (o->chapters_input_file == INT_MAX) { - /* copy chapters from the first input file that has them*/ - o->chapters_input_file = -1; - for (i = 0; i < nb_input_files; i++) - if (input_files[i]->ctx->nb_chapters) { - o->chapters_input_file = i; - break; - } - } else { - av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n", - o->chapters_input_file); - exit_program(1); - } - } - if (o->chapters_input_file >= 0) - copy_chapters(input_files[o->chapters_input_file], of, oc, - !o->metadata_chapters_manual); - - /* copy global metadata by default */ - if (!o->metadata_global_manual && nb_input_files){ - av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata, - AV_DICT_DONT_OVERWRITE); - if(o->recording_time != INT64_MAX) - av_dict_set(&oc->metadata, "duration", NULL, 0); - av_dict_set(&oc->metadata, "creation_time", NULL, 0); - av_dict_set(&oc->metadata, "company_name", NULL, 0); - av_dict_set(&oc->metadata, "product_name", NULL, 0); - av_dict_set(&oc->metadata, "product_version", NULL, 0); - } - if (!o->metadata_streams_manual) - for (int i = 0; i < of->nb_streams; i++) { - OutputStream *ost = of->streams[i]; - InputStream *ist; - if (ost->source_index < 0) /* this is true e.g. for attached files */ - continue; - ist = input_streams[ost->source_index]; - av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); - if (ost->enc_ctx) { - av_dict_set(&ost->st->metadata, "encoder", NULL, 0); - } - } + /* copy metadata and chapters from input files */ + copy_meta(mux, o); of_add_programs(oc, o); of_add_metadata(of, oc, o); From patchwork Tue Oct 18 12:36:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38787 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083200pzb; Tue, 18 Oct 2022 05:39:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ExPg7K6CWoscg7EetR1NQTtsIIHDdLGrugiaDStleGptB+dDKKmlQmI+oI46vg7TVZZbg X-Received: by 2002:a17:906:5daa:b0:78d:fa76:f837 with SMTP id n10-20020a1709065daa00b0078dfa76f837mr2146829ejv.239.1666096785493; Tue, 18 Oct 2022 05:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096785; cv=none; d=google.com; s=arc-20160816; b=CXUrOlkH8jcEx+PHRdtAcPfehEzAW8YRWqdd+DpgbrqBMhalj9kTtMA8XbLy+e4dnW Z8kwgFaO2nyO02+kCkVXvrV2ZIfZ7J5TLXgCQXR0VaZ8FHw5UX9InttwCGX8eCutwxcM ffrg6lNBvPG+u3P5P9DhagrMcGLe+ULp1ZaUTduN1rf3yIv9kiGcQE1nrVn+NkHjn/OA IB0XU4mkswCQ42tfdKf7A6l4yzbS73X79+HMjUWgtnyTvjVnnbnZnF66eAxo2M+/vNDh 82ElDuAj8m6q44Zb2TXWmMRau8lagsclwQSugBixW/pEaRQY/mJCUfywXnh4EnjaXUAg i1Tg== 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=suv93u20Pbb3cKBgV8aBFBDVOb18ujmQCvV0vXYi2AM=; b=tMHDtFTQeQjGN/bCXoUfN3rTPvBNlLvDij5mLTQmJpOTvxSc3vJpFK/A4+OFLarB7m 2jYdPE37su8nL9EFhFvUjxFx18QiVpcsHIyfTIuuA2HKHHSPMYW/qSx+xtuSweZjZCTS s2Orhg2ffH3gLpyw/fEUbo9+xDC8yUJDaYwpF6HcYEi5be/rQGz79KWjbdwxYI0xnWRz XKjaA0PP6Nq75YwFGI1TK3wIXM4dGEIpz9UGBhq9hBW5vwpBrvaJLIiawvHHf18vZwqq WCVqPCAEZLO+bPlE0cLNKODKIyXjq5kjr6AUekq8xIQrtF/Z1fmTWp5L5CwV1Ksvw/Dv 3MCg== 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 qf38-20020a1709077f2600b00787f13c332esi11907872ejc.799.2022.10.18.05.39.44; Tue, 18 Oct 2022 05:39:45 -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 DDF3268BD21; Tue, 18 Oct 2022 15:38:31 +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 2155168BD1F for ; Tue, 18 Oct 2022 15:38:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 99F712406CE for ; Tue, 18 Oct 2022 14:38:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tKjFI4xrmiPP for ; Tue, 18 Oct 2022 14:38:19 +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 D3F732406CF for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C53E23A1909 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:53 +0200 Message-Id: <20221018123701.25002-12-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/20] fftools/ffmpeg_mux_init: avoid modifying OptionsContext.chapters_input_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: 8hNVoA4w+5od Use a local variable instead. This will allow making OptionsContext const in future commits. --- fftools/ffmpeg_mux_init.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index cd46f441cf..f608376cf0 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1537,6 +1537,7 @@ static void copy_meta(Muxer *mux, OptionsContext *o) { OutputFile *of = &mux->of; AVFormatContext *oc = mux->fc; + int chapters_input_file = o->chapters_input_file; /* copy metadata */ for (int i = 0; i < o->nb_metadata_map; i++) { @@ -1553,23 +1554,23 @@ static void copy_meta(Muxer *mux, OptionsContext *o) } /* copy chapters */ - if (o->chapters_input_file >= nb_input_files) { - if (o->chapters_input_file == INT_MAX) { + if (chapters_input_file >= nb_input_files) { + if (chapters_input_file == INT_MAX) { /* copy chapters from the first input file that has them*/ - o->chapters_input_file = -1; + chapters_input_file = -1; for (int i = 0; i < nb_input_files; i++) if (input_files[i]->ctx->nb_chapters) { - o->chapters_input_file = i; + chapters_input_file = i; break; } } else { av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n", - o->chapters_input_file); + chapters_input_file); exit_program(1); } } - if (o->chapters_input_file >= 0) - copy_chapters(input_files[o->chapters_input_file], of, oc, + if (chapters_input_file >= 0) + copy_chapters(input_files[chapters_input_file], of, oc, !o->metadata_chapters_manual); /* copy global metadata by default */ From patchwork Tue Oct 18 12:36:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38793 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083515pzb; Tue, 18 Oct 2022 05:40:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ivDwK3hlb7AbGnXwPpk5hZLh2J5nylVQUS3lAVPNfvUoFq+3HAWnpM5cdALcVzcsL0kWl X-Received: by 2002:a17:906:846e:b0:78d:ed3c:edfa with SMTP id hx14-20020a170906846e00b0078ded3cedfamr2225869ejc.515.1666096837279; Tue, 18 Oct 2022 05:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096837; cv=none; d=google.com; s=arc-20160816; b=RGU3WxruEIA7iXEALVWHBcblZgjEc9wCZWdTDa53qJOZxflT6bhNi7cGzPoZ1E+smI XsKuS1al4Y/oMEDiNr8ZDQ8WshovPrOr2ExBP6og+mnpsPPepxE5eltffcg6wnQPu0Co WgmyYfzo3qzDU/xkxolz8lFLZXNdccFwowItkPfz8tMq/yokY+Q/THc7xEUe0sdry6Gu UfeGt1ZzBd2agVbHkMrWbllHTlXtRgBxEGO9FAQ2UmLcQtaeNvwIX5BLXyTCYJ4It0Zv Z1XjERDF5udpQuWlCZ9MY34Qp7wh+hr7h4O3+2n+3xbSwxntMBU59DS0mon0PAcHD+hP ToEA== 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=V55C05PAlObuAwywcFKQoJ28aG8hRQbPdiYq+nVC+qI=; b=I/sx1abeoXMswa8AoklHg0V7t8Vu+2ZYiURiqHQ4B+ufk84ADPDT+L3O5evAfthG8T s9GBbtifEpEaKwq1Q6+L5cTtIt1lQ59qzvNhk4ZH4dAgu3o8j43kw9YOGqP4RntPGNZS 7riayd0ZHfgHhi4c5v5R7or4xRRYjTiN6M3oWFWPeo5en7wU0Oxwlq3fqBGDFQwHPoBC y44din7/gn9IIEQqu0NAaJyubb0YROmpGDGT/D0kurIu/SnaCaAsfeD3V19Zp94kjclK e8lSw3QQldO1pRC5jWA5GhGtLrEa4n+h8HPaA7K9tfSYQzsFuvHOijwjbxHd0z8iV6O9 sXKg== 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 sg19-20020a170907a41300b00782161b3422si12514743ejc.914.2022.10.18.05.40.36; Tue, 18 Oct 2022 05:40:37 -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 6944268BDBD; Tue, 18 Oct 2022 15:38:37 +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 D6CB468BD35 for ; Tue, 18 Oct 2022 15:38:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6581A2404E4 for ; Tue, 18 Oct 2022 14:38:21 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ksSC-yFEx3HV for ; Tue, 18 Oct 2022 14:38:20 +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 DAC922406D1 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C65913A1A26 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:54 +0200 Message-Id: <20221018123701.25002-13-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/20] fftools/ffmpeg_mux_init: constify metadata specifier arguments 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: 53VXmVLO2Ng5 --- fftools/ffmpeg_mux_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index f608376cf0..a471bbf469 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1272,7 +1272,7 @@ static void of_add_programs(AVFormatContext *oc, const OptionsContext *o) * @param index for type c/p, chapter/program index is written here * @param stream_spec for type s, the stream specifier is written here */ -static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec) +static void parse_meta_type(const char *arg, char *type, int *index, const char **stream_spec) { if (*arg) { *type = *arg; @@ -1443,7 +1443,7 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *o return 0; } -static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o) +static int copy_metadata(const char *outspec, const char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o) { AVDictionary **meta_in = NULL; AVDictionary **meta_out = NULL; From patchwork Tue Oct 18 12:36:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38782 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2082878pzb; Tue, 18 Oct 2022 05:39:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4z3bcvPF9DqstYDqh2/UwqqdODOFIgOHnA1ocd2kZw2wGffO5Bb3IUNW+yD5MEcU4GMHCc X-Received: by 2002:a17:906:6a16:b0:78d:e4b3:5365 with SMTP id qw22-20020a1709066a1600b0078de4b35365mr2306904ejc.107.1666096741042; Tue, 18 Oct 2022 05:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096741; cv=none; d=google.com; s=arc-20160816; b=Y+qfRxUuC1xrb8mnPEZqcHKAJU3wDV8ge/1JpEzbFqoEeRemjxDCfWNbQBFJOneZAD 7mDV0X9w4s7c6AjAGQTPEy9YBXwfWyxFnZR6frq9i3XJOhQw+OPW6NvfZSuzttnhzJKW c38DIPLcf28AzZyqxs5DRcfdlGNkdg3QiQ3otmcFFy2ky82vlKybzx8q72q9IzPuQGgN Dga4h3YVHI5vgdYwST6tFnjazCSKxpvNEVdG3SoYJafkI4t7BqEzgWkJADvviNdqWnNC +LujEyclI4qmGlrBWB9IRnsMDmS030OzrwRTuqutNsRdbqRRXjFM8VHbekV7Oe3Bk3+p k+Yg== 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=nr9cTiTdocwcRVm5U5rhnc3Um1s95bNhtgm/cgwzgvc=; b=bNlQwJPEoq09BGYlCpHTtW3CAl5CB8/ZCdvYvcQahjNyZd4gulZoXh1wr5peJ3RLrI 58t3h4v56B+Q2EFMbP6ZsO0Z1VyJ2HmlQTS/i2R3iDqqUkrtbbPQUJcOt76ieEdFc3K4 K/rt5n8r9g6l9leg0iauKwNZ18IXZgg53ziraZjY4Inq7KPdg88urGVbeAG9sgy79pHv i9H2oG4vM0+g4sg/yo+5icVQkYkn6mgWW23vIHNCSRTrB2FcCRsjdocKKIu7sFAN/B+4 xrS/poJF/qhfdN4rFrG6B3cBv5Vs9E4wbBxjbErAq0W9aZo5jVUpH0vICHRbn9w/Qn0R 3ahQ== 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 f30-20020a50d55e000000b00457e08f77c2si10596567edj.272.2022.10.18.05.39.00; Tue, 18 Oct 2022 05:39: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 95FC868BD3B; Tue, 18 Oct 2022 15:38:26 +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 CC78668BCF7 for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6664B2406CB for ; Tue, 18 Oct 2022 14:38:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id W-2Qm1scxTWr for ; Tue, 18 Oct 2022 14:38:18 +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 B5E272406CA for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D1F9A3A1A2A for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:55 +0200 Message-Id: <20221018123701.25002-14-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/20] fftools/ffmpeg_mux_init: drop a duplicated block in copy_metadata() 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: fOdS5+DEv9/c It does the same thing as the block right below it. --- fftools/ffmpeg_mux_init.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index a471bbf469..9e0164ba19 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1455,16 +1455,6 @@ static int copy_metadata(const char *outspec, const char *inspec, AVFormatContex parse_meta_type(inspec, &type_in, &idx_in, &istream_spec); parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec); - if (!ic) { - if (type_out == 'g' || !*outspec) - o->metadata_global_manual = 1; - if (type_out == 's' || !*outspec) - o->metadata_streams_manual = 1; - if (type_out == 'c' || !*outspec) - o->metadata_chapters_manual = 1; - return 0; - } - if (type_in == 'g' || type_out == 'g') o->metadata_global_manual = 1; if (type_in == 's' || type_out == 's') From patchwork Tue Oct 18 12:36:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38784 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083028pzb; Tue, 18 Oct 2022 05:39:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5f/Soa8xyn0ED25JQjnz+1t1lnWDDYsIOhyLNChtVGYEC/835ZjSkppC4r8YmO9I77DDFB X-Received: by 2002:a05:6402:f24:b0:45c:d71c:7f62 with SMTP id i36-20020a0564020f2400b0045cd71c7f62mr2473044eda.416.1666096758852; Tue, 18 Oct 2022 05:39:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096758; cv=none; d=google.com; s=arc-20160816; b=wPXWaVYEY9kzIT6CmEaRiUoydGpvGfmEKjj/a1uwOJZQzPmaWblzOQG/jGj/6mQKda d7DhrxGxFIhT0amvTxlbVdCLNZk5k4tvt0bAjWxNAhrOZksOz4Eg1J2Hk61lCAn7FvOm +WrAbtJXdkfSCzPWaIuNtbJBkJwVsCmZ71odrh8SKigWzqvEa4C/qj5L1EGHBefcLrFA PcWpsYlDC92BfiBadNhcsHAgkMXO+rKKzNz7jbuzRpi6NOkAtaAy7uO4B0gIi27Ya7XM E0ul1yT6YkVla+DZX4W3CNsNHFGdPpLIeWdynB5Emtgm7KBs9MQPhvIpskFV7m+TqTfJ Jb0A== 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=qcTCL0ue8vyzXivHGG2qY+vMVIhFOCByi7BA6QzMqrY=; b=zA4B6RHcIvKmN4jdOjPINnb20pLpD3i9s+py/bR4Mxy1iy3k6SOVziZ9qR/zTAlQuG lKDZ7O8cIYql35g8zSVrkc0bwSFh/KjG+ex3Olxe8E0a7taxRj3YT6+ZOw7s796y2HWJ T18Kgtj1XKUYF1Ld48tr6NZwJtdZmZD+evsArbodTeWW5opnyrzaCkaKsR2c1eJHvzYO xsgHj18cYYynJNPM8tkCuvob1UedfSDCfga6WWNGiZiZo6wuRNdKZCw/mFB/kSEqBzh+ pLO8Fo0sC4mZsrE6VQQIAJgwaz/JphUfv0kKDSO99JKicK251gBUMFvvxRLQQAvGldfB 4kjQ== 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 o10-20020a50fd8a000000b00458896ae248si9374565edt.474.2022.10.18.05.39.18; Tue, 18 Oct 2022 05:39: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 A92DA68BD3F; Tue, 18 Oct 2022 15:38:28 +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 D488E68BD18 for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 340822406CD for ; Tue, 18 Oct 2022 14:38:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id aq41cAAMRAG5 for ; Tue, 18 Oct 2022 14:38:18 +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 B64C72406CC for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D31213A1A7C for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:56 +0200 Message-Id: <20221018123701.25002-15-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/20] fftools/ffmpeg_mux_init: stop using OptionsContext as storage in copy_metadata() 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: fcPHZJVLsk1l It should be input-only to this code. Will allow making it const in future commits. --- fftools/ffmpeg.h | 3 --- fftools/ffmpeg_mux_init.c | 24 ++++++++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index a124b1b045..8a50cd8d4b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -148,9 +148,6 @@ typedef struct OptionsContext { AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */ int nb_audio_channel_maps; /* number of (valid) -map_channel settings */ #endif - int metadata_global_manual; - int metadata_streams_manual; - int metadata_chapters_manual; const char **attachments; int nb_attachments; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 9e0164ba19..96584e960b 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1443,7 +1443,10 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *o return 0; } -static int copy_metadata(const char *outspec, const char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o) +static int copy_metadata(const char *outspec, const char *inspec, + AVFormatContext *oc, AVFormatContext *ic, + int *metadata_global_manual, int *metadata_streams_manual, + int *metadata_chapters_manual, OptionsContext *o) { AVDictionary **meta_in = NULL; AVDictionary **meta_out = NULL; @@ -1456,11 +1459,11 @@ static int copy_metadata(const char *outspec, const char *inspec, AVFormatContex parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec); if (type_in == 'g' || type_out == 'g') - o->metadata_global_manual = 1; + *metadata_global_manual = 1; if (type_in == 's' || type_out == 's') - o->metadata_streams_manual = 1; + *metadata_streams_manual = 1; if (type_in == 'c' || type_out == 'c') - o->metadata_chapters_manual = 1; + *metadata_chapters_manual = 1; /* ic is NULL when just disabling automatic mappings */ if (!ic) @@ -1528,6 +1531,9 @@ static void copy_meta(Muxer *mux, OptionsContext *o) OutputFile *of = &mux->of; AVFormatContext *oc = mux->fc; int chapters_input_file = o->chapters_input_file; + int metadata_global_manual = 0; + int metadata_streams_manual = 0; + int metadata_chapters_manual = 0; /* copy metadata */ for (int i = 0; i < o->nb_metadata_map; i++) { @@ -1540,7 +1546,9 @@ static void copy_meta(Muxer *mux, OptionsContext *o) } copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, in_file_index >= 0 ? - input_files[in_file_index]->ctx : NULL, o); + input_files[in_file_index]->ctx : NULL, + &metadata_global_manual, &metadata_streams_manual, + &metadata_chapters_manual, o); } /* copy chapters */ @@ -1561,10 +1569,10 @@ static void copy_meta(Muxer *mux, OptionsContext *o) } if (chapters_input_file >= 0) copy_chapters(input_files[chapters_input_file], of, oc, - !o->metadata_chapters_manual); + !metadata_chapters_manual); /* copy global metadata by default */ - if (!o->metadata_global_manual && nb_input_files){ + if (!metadata_global_manual && nb_input_files){ av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata, AV_DICT_DONT_OVERWRITE); if(o->recording_time != INT64_MAX) @@ -1574,7 +1582,7 @@ static void copy_meta(Muxer *mux, OptionsContext *o) av_dict_set(&oc->metadata, "product_name", NULL, 0); av_dict_set(&oc->metadata, "product_version", NULL, 0); } - if (!o->metadata_streams_manual) + if (!metadata_streams_manual) for (int i = 0; i < of->nb_streams; i++) { OutputStream *ost = of->streams[i]; InputStream *ist; From patchwork Tue Oct 18 12:36:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38780 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2082747pzb; Tue, 18 Oct 2022 05:38:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6fSKX0JCMkYGyQISENZ4L/rbCms5lcwLbCawuOOt8Tqo3ngYz52MSIgc8woPt7jd+6GGL+ X-Received: by 2002:a17:906:99c3:b0:78d:9cc9:deda with SMTP id s3-20020a17090699c300b0078d9cc9dedamr2235278ejn.712.1666096724815; Tue, 18 Oct 2022 05:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096724; cv=none; d=google.com; s=arc-20160816; b=rWmA26FLYp7Ve4fBPqV++02Ga/1EIDg+fhAVDFpkfH+YZwb1s/Epzp8qBQW+az61z+ UzjTXVzN+CjhnqVqGifHHDyytJj8XX7XjTLbx71BzOgfIM1N8swdIbYuWmeHQPimHVlJ 7qoZJHFY2v6U7ETEs8qLYMErKLgMK2Fw4oFuhNoDXlp9LUd03ATVyh3RsuOyUiZx46fj GBFD6O5SaA8+UFt4rCKSm+R/uN9qoRKOJr4WK/6nh7Ji/jftplx3nfyifhwO/G5EnEk/ 5FlCyvk2W4UARn8KK95w2If885fF6Mcb674fwF2mG000FwopRb/EWp/C3ptfVue4di9j YnMQ== 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=xEKCbx6irBej/hIyI/ty8Yk1AxzSpniEMgYyizNRaD0=; b=zZhQzOXS/XTCaI2E0hTeZVY6/kNg1rCnVteIBgcUDuZMR5EvCMfzInPvyo25R7T6tk 10VlqvcqxNEx/rcurH1U/utvcnA1oxwSegueCvYB4emzbbrw3OPJ53Tl4mUhzXFBBJt4 GGsQm/LQekLyPYQEuC9RBWHWTw5i6Qqm4Jpz5AiVjAmNbd+XK4NazENKLytqnrHkjJv2 bfm3vq4WXa2HzOsRJc3AhyHlv3I5LiAolL8cJPOhBFjj602As1VexmNhJI2OwIDSroHs jyVFvW9SjE3yypZcrduuVSh0aRX5+wZh/zljz1sQkGi4qNB7UeSPmRKf66kIbUSxK51I Uv6Q== 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 p26-20020a170906a01a00b0078db89b2566si10313393ejy.699.2022.10.18.05.38.44; Tue, 18 Oct 2022 05:38: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 9843868BD4D; Tue, 18 Oct 2022 15:38: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 9333368BC19 for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 091612405EC for ; Tue, 18 Oct 2022 14:38:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id WM2yYDtcov3B for ; Tue, 18 Oct 2022 14:38:17 +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 B5FAB2406CB for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D44853A0212 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:57 +0200 Message-Id: <20221018123701.25002-16-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/20] fftools/ffmpeg_mux_init: stop modifying some OptionsContext fields 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: /D/WOIWWCApn Specifically recording_time and stop_time - use local variables instead. OptionsContext should be input-only to this code. Will allow making it const in future commits. --- fftools/ffmpeg_mux_init.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 96584e960b..d25dace105 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1575,7 +1575,7 @@ static void copy_meta(Muxer *mux, OptionsContext *o) if (!metadata_global_manual && nb_input_files){ av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata, AV_DICT_DONT_OVERWRITE); - if(o->recording_time != INT64_MAX) + if (of->recording_time != INT64_MAX) av_dict_set(&oc->metadata, "duration", NULL, 0); av_dict_set(&oc->metadata, "creation_time", NULL, 0); av_dict_set(&oc->metadata, "company_name", NULL, 0); @@ -1671,18 +1671,21 @@ int of_open(OptionsContext *o, const char *filename) AVDictionary *unused_opts = NULL; const AVDictionaryEntry *e = NULL; - if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { - o->stop_time = INT64_MAX; + int64_t recording_time = o->recording_time; + int64_t stop_time = o->stop_time; + + if (stop_time != INT64_MAX && recording_time != INT64_MAX) { + stop_time = INT64_MAX; av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n"); } - if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) { + if (stop_time != INT64_MAX && recording_time == INT64_MAX) { int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time; - if (o->stop_time <= start_time) { + if (stop_time <= start_time) { av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n"); exit_program(1); } else { - o->recording_time = o->stop_time - start_time; + recording_time = stop_time - start_time; } } @@ -1690,7 +1693,7 @@ int of_open(OptionsContext *o, const char *filename) of = &mux->of; of->index = nb_output_files - 1; - of->recording_time = o->recording_time; + of->recording_time = recording_time; of->start_time = o->start_time; of->shortest = o->shortest; @@ -1712,8 +1715,8 @@ int of_open(OptionsContext *o, const char *filename) want_sdp = 0; of->format = oc->oformat; - if (o->recording_time != INT64_MAX) - oc->duration = o->recording_time; + if (recording_time != INT64_MAX) + oc->duration = recording_time; oc->interrupt_callback = int_cb; From patchwork Tue Oct 18 12:36:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38789 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083302pzb; Tue, 18 Oct 2022 05:40:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5BhiiHFNVqHKoAdZMH7bcwZT87xhsQidiVo/s2DzjuqPzUxTjt3u2E7Ru0SUsALNSRyE6+ X-Received: by 2002:a17:906:fe0b:b0:787:f1d3:2105 with SMTP id wy11-20020a170906fe0b00b00787f1d32105mr2248309ejb.83.1666096801931; Tue, 18 Oct 2022 05:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096801; cv=none; d=google.com; s=arc-20160816; b=i11Q0kyTf+xDLV21RKoAblFzPhRH9eV2QxnVLqcBd1XraX7j4DShZlQC5+gL3R+PwT Fx6PHSiq4vqORX5QFczTaZ9MFLcJWHDjjL6+dlRnAAze/oYCDTgupgIZBfR9LLPGryjd uXDQur3ok1a4D/2dNFNOF2w53DsIyWO84/XxxIDjXYqcUhd/kvwNpwgF8KL1CdPgJ4LZ p7jURKWLcdQaw1sJROAcgv24et5+eXHHST2AYIIo/eJklaacBvNC2Q3smSer74EMz5A2 GNHPyLMltma1UuOHYvbRBiKZVOwLEntGcY40fnbZX3ak8f482TWXeDrXyN5BUNVQz1qH VYrA== 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=PTFQVdV+IT6XLVPrudO/9wRdqBlp4J3VDJu+K8I5VjA=; b=YBXmDjYwDmsIy1FvernOd0KcUYX0uqsQ6oKB+pPF1x0Jo/0S9pSmRnzddWzhHT1KbB Nbwo95HZ7813MwJ59wTpCfgS8jhhmKUGw7zCevtoZk9jQ7BJBz8pabNVdJzCxjSkYDpI Lrjvvgx6XRsEdTXIw2gVJ1fx+x4VlJQDfBl+pB/ELyIrMvJCJH6nJJcYak25R9BkXM9E bOVL0eQdTARmQhP0BK1noXaJZ+dGuSe9tkhdNJlL6ksCHrORBPbJ+UQ3K5MprZOpXMDv iWKEOuKTdHLSUrpoDwuHeeTTWvbsUsL/STcGegs5cw3fgzNfYrJ4mpqd0fOOpKaAzty6 8cRQ== 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 y18-20020aa7ce92000000b00442296a8407si10097878edv.629.2022.10.18.05.40.01; Tue, 18 Oct 2022 05:40: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 BAFE268BD9C; Tue, 18 Oct 2022 15:38:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2121368BD15 for ; Tue, 18 Oct 2022 15:38:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 368C02404F5 for ; Tue, 18 Oct 2022 14:38:20 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id EbGcRI6sd7hS for ; Tue, 18 Oct 2022 14:38:19 +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 DD12F2406E1 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D6D903A1E5A for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:58 +0200 Message-Id: <20221018123701.25002-17-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/20] fftools/ffmpeg_mux_init: move code creating streams into a new function 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: q1+3vGd4NbTk Makes it easy to see where all the streams are created. Will also be useful in the following commit. --- fftools/ffmpeg_mux_init.c | 72 +++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index d25dace105..6687ba872a 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1062,6 +1062,42 @@ loop_end: } } +static void create_streams(Muxer *mux, OptionsContext *o) +{ + /* create streams for all unlabeled output pads */ + for (int i = 0; i < nb_filtergraphs; i++) { + FilterGraph *fg = filtergraphs[i]; + for (int j = 0; j < fg->nb_outputs; j++) { + OutputFilter *ofilter = fg->outputs[j]; + + if (!ofilter->out_tmp || ofilter->out_tmp->name) + continue; + + switch (ofilter->type) { + case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break; + case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break; + case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break; + } + init_output_filter(ofilter, o, mux); + } + } + + if (!o->nb_stream_maps) { + /* pick the "best" stream of each type */ + if (!o->video_disable) + map_auto_video(mux, o); + if (!o->audio_disable) + map_auto_audio(mux, o); + if (!o->subtitle_disable) + map_auto_subtitle(mux, o); + if (!o->data_disable) + map_auto_data(mux, o); + } else { + for (int i = 0; i < o->nb_stream_maps; i++) + map_manual(mux, o, &o->stream_maps[i]); + } +} + static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us) { OutputFile *of = &mux->of; @@ -1666,7 +1702,7 @@ int of_open(OptionsContext *o, const char *filename) { Muxer *mux; AVFormatContext *oc; - int i, j, err; + int err; OutputFile *of; AVDictionary *unused_opts = NULL; const AVDictionaryEntry *e = NULL; @@ -1728,38 +1764,8 @@ int of_open(OptionsContext *o, const char *filename) AVFMT_FLAG_BITEXACT); } - /* create streams for all unlabeled output pads */ - for (i = 0; i < nb_filtergraphs; i++) { - FilterGraph *fg = filtergraphs[i]; - for (j = 0; j < fg->nb_outputs; j++) { - OutputFilter *ofilter = fg->outputs[j]; - - if (!ofilter->out_tmp || ofilter->out_tmp->name) - continue; - - switch (ofilter->type) { - case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break; - case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break; - case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break; - } - init_output_filter(ofilter, o, mux); - } - } - - if (!o->nb_stream_maps) { - /* pick the "best" stream of each type */ - if (!o->video_disable) - map_auto_video(mux, o); - if (!o->audio_disable) - map_auto_audio(mux, o); - if (!o->subtitle_disable) - map_auto_subtitle(mux, o); - if (!o->data_disable) - map_auto_data(mux, o); - } else { - for (int i = 0; i < o->nb_stream_maps; i++) - map_manual(mux, o, &o->stream_maps[i]); - } + /* create all output streams for this file */ + create_streams(mux, o); of_add_attachments(mux, o); From patchwork Tue Oct 18 12:36:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38783 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2082947pzb; Tue, 18 Oct 2022 05:39:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XzsKYKFoIUT2bW9jkjK79MjYsRgESDuF9MIBuckN0job5i8tMZIRFunMqty+7skBj5/n7 X-Received: by 2002:a05:6402:510d:b0:45d:a888:d831 with SMTP id m13-20020a056402510d00b0045da888d831mr2375464edd.315.1666096749970; Tue, 18 Oct 2022 05:39:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096749; cv=none; d=google.com; s=arc-20160816; b=H70oFSItQdN9Q3zY9ReXiRq057zUtgnN02Dv9WtIlWbOIubErBc/ldmEeVEoHkCQTH ZU/A5j1AuuFfEIWbWVIeI/zzeSWAPzoCe16aCMwsmHz9tWtQwGO4woyHm5fvabydF9Ee OGueNR3FJfiO99ghLlYqxBnNEZNn10wLPoquD6/52dmq+FN/lUSIX1QqcYOxn/rVijLQ NVa3ciGk5ZfR1jAYDXhObMpkSPN6DOkUVSnqMOEolDuRbV/yz9xVekYc7VaDMad4c9J2 AwRZ5F9fiHz+/eAJ/uRiJiiyc+zu8nquwcIFer1bXQJhtuCxzm/0X+2cMK8JYRRJC9d8 tRKQ== 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=M8iZIDlPErBsQB6Eqpjq/yIQd89cZXfzyN+hXbXPMhw=; b=Bi8tcvGcPoVRvgB8bM1DZgtS8Bq/nUCb4HLX1R2pX0pMwj5SNb50iJ67IsreZNoHyJ oIkPSOx9z/LmcZ7MeDFh/rbEYh2a1xVEt/m58xDWlR77tNT0uJQWJBwae4qo4gM9EVL8 eYUkN28anscBf1M+nW5Fj3AuwoMzgpkaDMPIHqYzeLQ7f0hFPGvv0EiIrkBeIXeXzvs4 ryQodw7lxrQWC1DLMRspNHh5asZ1vXuthSqvxy74SgTMmVoJHbmX4Pn5O6Dw9goD/JSC Zv+5h/pL1tzy58ftFRWztMfCL6OK9vDnftxJ+HactkWMzoQcNn/fGxgNtoHE8vpO9t+U cdcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b11-20020a0564021f0b00b0045bf23171d5si11341819edb.165.2022.10.18.05.39.09; Tue, 18 Oct 2022 05:39:09 -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 9E71768BD13; Tue, 18 Oct 2022 15:38:27 +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 D012068BD13 for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EFC682405F9 for ; Tue, 18 Oct 2022 14:38:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id w3CgPU7fHOaj for ; Tue, 18 Oct 2022 14:38:18 +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 C03B62406CD for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D80E33A1E7C for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:59 +0200 Message-Id: <20221018123701.25002-18-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/20] fftools/ffmpeg_mux_init: stop modifying OptionsContext.*_disable 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: 5nrEBOMFwNlK The current code will override the *_disable fields (set by -vn/-an options) when creating output streams for unlabeled complex filtergraph outputs, in order to disable automatic mapping for the corresponding media type. However, this will apply not only to automatic mappings, but to manual ones as well, which should not happen. Avoid this by adding local variables that are used only for automatic mappings. --- fftools/ffmpeg_mux_init.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6687ba872a..7c19cb7442 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1064,6 +1064,11 @@ loop_end: static void create_streams(Muxer *mux, OptionsContext *o) { + int auto_disable_v = o->video_disable; + int auto_disable_a = o->audio_disable; + int auto_disable_s = o->subtitle_disable; + int auto_disable_d = o->data_disable; + /* create streams for all unlabeled output pads */ for (int i = 0; i < nb_filtergraphs; i++) { FilterGraph *fg = filtergraphs[i]; @@ -1074,9 +1079,9 @@ static void create_streams(Muxer *mux, OptionsContext *o) continue; switch (ofilter->type) { - case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break; - case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break; - case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break; + case AVMEDIA_TYPE_VIDEO: auto_disable_v = 1; break; + case AVMEDIA_TYPE_AUDIO: auto_disable_a = 1; break; + case AVMEDIA_TYPE_SUBTITLE: auto_disable_s = 1; break; } init_output_filter(ofilter, o, mux); } @@ -1084,13 +1089,13 @@ static void create_streams(Muxer *mux, OptionsContext *o) if (!o->nb_stream_maps) { /* pick the "best" stream of each type */ - if (!o->video_disable) + if (!auto_disable_v) map_auto_video(mux, o); - if (!o->audio_disable) + if (!auto_disable_a) map_auto_audio(mux, o); - if (!o->subtitle_disable) + if (!auto_disable_s) map_auto_subtitle(mux, o); - if (!o->data_disable) + if (!auto_disable_d) map_auto_data(mux, o); } else { for (int i = 0; i < o->nb_stream_maps; i++) From patchwork Tue Oct 18 12:37:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38790 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083352pzb; Tue, 18 Oct 2022 05:40:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XkFq2Bf3/dGNka/y2aOcdvLyk7p1DGfjWJAM23WznzUvaZu+GFK+aVb5qC6NBHoJy/Hk0 X-Received: by 2002:a17:907:74a:b0:77e:9455:b4e1 with SMTP id xc10-20020a170907074a00b0077e9455b4e1mr2300916ejb.462.1666096810719; Tue, 18 Oct 2022 05:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096810; cv=none; d=google.com; s=arc-20160816; b=PQUEA+TDUX4WvYWkwH/YRat67MugzXDuR4xeC2Em9sXGDBQKPVuPntnqG+YUO4FVn3 qIwuhgaSSSB9jYk5eVxYQMhE3W0jHJoWcvrfzU+EM3ya4MWGDp5hNBBrJhlAe5TkzYjg EPSEMxfeZ2nyuxJmoyDWSxg/bNa1qhnKIFmWVa3dUuT1yBnopIVZIrlkG/VfyWv8Bq3C DhbNFeg2M9kytuEGGS1t+Q4AKFWU6SG2ZKkrOOS3/sU5fy8QdOrizUCUE+bN4l58Ea9M ZwXVEqz0oNBKqt1l3/k4B0aPXYpm4FBJAsDo+RBZEM6a1Nls8UjAmVUWfbv4kDdLs8CV Jngg== 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=20GfJ3bcczjOFFk7nlLPOaNolf5SrKd/FH8pboFpye0=; b=Ey1LIFfqgVimYgkA1q48lJEoaninNfr7p+kmLUfA0UjMn1939IsnI5SLL1waisNQx8 VVPldeFgi2ywugDu/PTb8O2HmePbc0E4VqARrCF5D7nZTkixHrt4IUkYpgsJ6rpQ8QUP NbyFC5yiCOujNcdvyTJ/9OX/icbVPr7JoWtt8uQBu72hmD26ZZMzY/+J485j4IhKIDDE pRe8nCAlaLiTVUrTs+OTFLqVoRn5MEfrRAs/2fXnPppWNl36XvlXtF734gBzXtuqQC1a Qxftsnh1jCHebEa/c/77ShWFr7qFXS2rqKYoOKzrVX1BUaoCAu19sB/8L10drtcW0OFT w0Vg== 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 cr2-20020a170906d54200b0078cc4a8a956si12880266ejc.881.2022.10.18.05.40.10; Tue, 18 Oct 2022 05:40:10 -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 AB7DD68BD3D; Tue, 18 Oct 2022 15:38:34 +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 21AF568BD23 for ; Tue, 18 Oct 2022 15:38:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0FBB32406CF for ; Tue, 18 Oct 2022 14:38:20 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cWmmY577YSan for ; Tue, 18 Oct 2022 14:38:19 +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 DE119240706 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E6DE43A0922 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:37:00 +0200 Message-Id: <20221018123701.25002-19-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/20] fftools/ffmpeg_demux: stop modifying OptionsContext 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: /a5BtZF062YL It should be input-only to this code. --- fftools/ffmpeg_demux.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 29cff4b471..4ce92862cb 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -772,18 +772,23 @@ int ifile_open(OptionsContext *o, const char *filename) char * data_codec_name = NULL; int scan_all_pmts_set = 0; - if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { - o->stop_time = INT64_MAX; + int64_t start_time = o->start_time; + int64_t start_time_eof = o->start_time_eof; + int64_t stop_time = o->stop_time; + int64_t recording_time = o->recording_time; + + if (stop_time != INT64_MAX && recording_time != INT64_MAX) { + stop_time = INT64_MAX; av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n"); } - if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) { - int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time; - if (o->stop_time <= start_time) { + if (stop_time != INT64_MAX && recording_time == INT64_MAX) { + int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time; + if (stop_time <= start) { av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n"); exit_program(1); } else { - o->recording_time = o->stop_time - start_time; + recording_time = stop_time - start; } } @@ -908,32 +913,32 @@ int ifile_open(OptionsContext *o, const char *filename) } } - if (o->start_time != AV_NOPTS_VALUE && o->start_time_eof != AV_NOPTS_VALUE) { + if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) { av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename); - o->start_time_eof = AV_NOPTS_VALUE; + start_time_eof = AV_NOPTS_VALUE; } - if (o->start_time_eof != AV_NOPTS_VALUE) { - if (o->start_time_eof >= 0) { + if (start_time_eof != AV_NOPTS_VALUE) { + if (start_time_eof >= 0) { av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n"); exit_program(1); } if (ic->duration > 0) { - o->start_time = o->start_time_eof + ic->duration; - if (o->start_time < 0) { + start_time = start_time_eof + ic->duration; + if (start_time < 0) { av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename); - o->start_time = AV_NOPTS_VALUE; + start_time = AV_NOPTS_VALUE; } } else av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename); } - timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time; + timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time; /* add the stream start time */ if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE) timestamp += ic->start_time; /* if seeking requested, we execute it */ - if (o->start_time != AV_NOPTS_VALUE) { + if (start_time != AV_NOPTS_VALUE) { int64_t seek_timestamp = timestamp; if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) { @@ -968,8 +973,8 @@ int ifile_open(OptionsContext *o, const char *filename) f->ctx = ic; f->index = nb_input_files - 1; f->ist_index = nb_input_streams - ic->nb_streams; - f->start_time = o->start_time; - f->recording_time = o->recording_time; + f->start_time = start_time; + f->recording_time = recording_time; f->input_sync_ref = o->input_sync_ref; f->input_ts_offset = o->input_ts_offset; f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp); From patchwork Tue Oct 18 12:37:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38792 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083469pzb; Tue, 18 Oct 2022 05:40:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6degB9ceeE/nyvUtNjjHgVbHpidQTeQ+QYpVUpVNt14RhK+30wuGmKF35Peb8MzJXb9yTx X-Received: by 2002:a17:906:8a48:b0:78d:acdc:b7d9 with SMTP id gx8-20020a1709068a4800b0078dacdcb7d9mr2311192ejc.500.1666096828172; Tue, 18 Oct 2022 05:40:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096828; cv=none; d=google.com; s=arc-20160816; b=MwB9/H/RbazNuPnRgGMBiIZOpegiuANHJ4AZNsMwAGBanQ+Szol92ZDZEbeM00nlPA yCDuP3yeBPWhCqcUASXqvGNWaPYZkn6pn0yziI052sbhv88H8rf470cS6ePQ6I4Vsaeb fR4JSQGXsCIwP0gTc7/mX5+m6EV332+d3fMEKOjOB2N//pBjcvxz+bmbXEVXTw4ZNSBv calScA4LTZdTX6pyfPOmxZ16kuLz5pAC9uEjY6fhkXArTZe6e7wyLzjJcf6IR+FpP3oc TiXkezQbWE9l48rCKABfi3qXceaGJCtqn+ltVggX6dL3FE8iZ0J2ZPn7Ur3mOLs7I6hu X05Q== 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=t+Rxqi5UvSZV11dzdwkuquCQM6PJYAbFLZMb7qYn1EI=; b=cuO19mNCE5LHHC8cSCPmvG1EEdDbMkSz7ANY1dqDYYHd/qVenPykvNOiJX7m8qrUuU tzxQX/h6Dj3JrqRjbF97d+HMZPNMm5zQlV6Pg5KCa0La3XstXazcrjTrhosmrQvs+ZSk k1BU+jD2b/bn0392updo6dJvNG73qDhpmr73j0o3AIaJscEw/9YB9QLevkWNBJradXrh T5C6nQMqU9/ibiKWbDm+wjcgaYks/skIipQD4EUHCociGuD9tGqILu93sNqY0OR9lHfl eSX/4qW/0r8c8SoGo19TU2dhREsWLLzQSUz2+5JkuyU/Ee5YFMd0GkbUf1VFcjq5ZjFb 6w5g== 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 x11-20020a05640226cb00b0045d46f28533si10453160edd.377.2022.10.18.05.40.27; Tue, 18 Oct 2022 05:40:28 -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 7705D68BDB2; Tue, 18 Oct 2022 15:38:36 +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 5CA7068BD15 for ; Tue, 18 Oct 2022 15:38:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DD0AD2404E4 for ; Tue, 18 Oct 2022 14:38:20 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id N4qCAD3iJ0PX for ; Tue, 18 Oct 2022 14:38:20 +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 E2BD0240D03 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E85373A13D9 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:37:01 +0200 Message-Id: <20221018123701.25002-20-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/20] fftools/ffmpeg_[de]mux: constify all uses of OptionsContext 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: HDCzwyGsbADS --- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_demux.c | 6 +++--- fftools/ffmpeg_mux_init.c | 42 +++++++++++++++++++-------------------- fftools/ffmpeg_opt.c | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8a50cd8d4b..0724914f27 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -715,7 +715,7 @@ int hwaccel_decode_init(AVCodecContext *avctx); */ int of_stream_init(OutputFile *of, OutputStream *ost); int of_write_trailer(OutputFile *of); -int of_open(OptionsContext *o, const char *filename); +int of_open(const OptionsContext *o, const char *filename); void of_close(OutputFile **pof); /* @@ -734,7 +734,7 @@ int64_t of_filesize(OutputFile *of); AVChapter * const * of_get_chapters(OutputFile *of, unsigned int *nb_chapters); -int ifile_open(OptionsContext *o, const char *filename); +int ifile_open(const OptionsContext *o, const char *filename); void ifile_close(InputFile **f); /** diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 4ce92862cb..eb9fa9132b 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -452,7 +452,7 @@ void ifile_close(InputFile **pf) av_freep(pf); } -static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st, +static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) { @@ -514,7 +514,7 @@ static int guess_input_channel_layout(InputStream *ist) /* Add all the streams from the given input file to the global * list of input streams. */ -static void add_input_streams(OptionsContext *o, AVFormatContext *ic) +static void add_input_streams(const OptionsContext *o, AVFormatContext *ic) { int i, ret; @@ -756,7 +756,7 @@ static void dump_attachment(AVStream *st, const char *filename) avio_close(out); } -int ifile_open(OptionsContext *o, const char *filename) +int ifile_open(const OptionsContext *o, const char *filename) { Demuxer *d; InputFile *f; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 7c19cb7442..0ddb7b94dc 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -97,7 +97,7 @@ static int check_opt_bitexact(void *ctx, const AVDictionary *opts, return 0; } -static int choose_encoder(OptionsContext *o, AVFormatContext *s, +static int choose_encoder(const OptionsContext *o, AVFormatContext *s, OutputStream *ost, const AVCodec **enc) { enum AVMediaType type = ost->st->codecpar->codec_type; @@ -170,7 +170,7 @@ static int get_preset_file_2(const char *preset_name, const char *codec_name, AV return ret; } -static OutputStream *new_output_stream(Muxer *mux, OptionsContext *o, +static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, enum AVMediaType type, int source_index) { AVFormatContext *oc = mux->fc; @@ -368,7 +368,7 @@ static OutputStream *new_output_stream(Muxer *mux, OptionsContext *o, return ost; } -static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc, +static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost) { AVStream *st = ost->st; @@ -388,7 +388,7 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc, "null" : "anull"); } -static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, +static void check_streamcopy_filters(const OptionsContext *o, AVFormatContext *oc, const OutputStream *ost, enum AVMediaType type) { if (ost->filters_script || ost->filters) { @@ -419,7 +419,7 @@ static void parse_matrix_coeffs(uint16_t *dest, const char *str) } } -static OutputStream *new_video_stream(Muxer *mux, OptionsContext *o, int source_index) +static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, int source_index) { AVFormatContext *oc = mux->fc; AVStream *st; @@ -658,7 +658,7 @@ static OutputStream *new_video_stream(Muxer *mux, OptionsContext *o, int source_ return ost; } -static OutputStream *new_audio_stream(Muxer *mux, OptionsContext *o, int source_index) +static OutputStream *new_audio_stream(Muxer *mux, const OptionsContext *o, int source_index) { AVFormatContext *oc = mux->fc; AVStream *st; @@ -756,7 +756,7 @@ static OutputStream *new_audio_stream(Muxer *mux, OptionsContext *o, int source_ return ost; } -static OutputStream *new_data_stream(Muxer *mux, OptionsContext *o, int source_index) +static OutputStream *new_data_stream(Muxer *mux, const OptionsContext *o, int source_index) { OutputStream *ost; @@ -769,7 +769,7 @@ static OutputStream *new_data_stream(Muxer *mux, OptionsContext *o, int source_i return ost; } -static OutputStream *new_unknown_stream(Muxer *mux, OptionsContext *o, int source_index) +static OutputStream *new_unknown_stream(Muxer *mux, const OptionsContext *o, int source_index) { OutputStream *ost; @@ -782,14 +782,14 @@ static OutputStream *new_unknown_stream(Muxer *mux, OptionsContext *o, int sourc return ost; } -static OutputStream *new_attachment_stream(Muxer *mux, OptionsContext *o, int source_index) +static OutputStream *new_attachment_stream(Muxer *mux, const OptionsContext *o, int source_index) { OutputStream *ost = new_output_stream(mux, o, AVMEDIA_TYPE_ATTACHMENT, source_index); ost->finished = 1; return ost; } -static OutputStream *new_subtitle_stream(Muxer *mux, OptionsContext *o, int source_index) +static OutputStream *new_subtitle_stream(Muxer *mux, const OptionsContext *o, int source_index) { AVStream *st; OutputStream *ost; @@ -811,7 +811,7 @@ static OutputStream *new_subtitle_stream(Muxer *mux, OptionsContext *o, int sour return ost; } -static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, +static void init_output_filter(OutputFilter *ofilter, const OptionsContext *o, Muxer *mux) { OutputStream *ost; @@ -852,7 +852,7 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, avfilter_inout_free(&ofilter->out_tmp); } -static void map_auto_video(Muxer *mux, OptionsContext *o) +static void map_auto_video(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; InputStream *ist; @@ -898,7 +898,7 @@ static void map_auto_video(Muxer *mux, OptionsContext *o) new_video_stream(mux, o, idx); } -static void map_auto_audio(Muxer *mux, OptionsContext *o) +static void map_auto_audio(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; InputStream *ist; @@ -937,7 +937,7 @@ static void map_auto_audio(Muxer *mux, OptionsContext *o) new_audio_stream(mux, o, idx); } -static void map_auto_subtitle(Muxer *mux, OptionsContext *o) +static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; char *subtitle_codec_name = NULL; @@ -975,7 +975,7 @@ static void map_auto_subtitle(Muxer *mux, OptionsContext *o) } } -static void map_auto_data(Muxer *mux, OptionsContext *o) +static void map_auto_data(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; /* Data only if codec id match */ @@ -989,7 +989,7 @@ static void map_auto_data(Muxer *mux, OptionsContext *o) } } -static void map_manual(Muxer *mux, OptionsContext *o, const StreamMap *map) +static void map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map) { InputStream *ist; @@ -1062,7 +1062,7 @@ loop_end: } } -static void create_streams(Muxer *mux, OptionsContext *o) +static void create_streams(Muxer *mux, const OptionsContext *o) { int auto_disable_v = o->video_disable; int auto_disable_a = o->audio_disable; @@ -1194,7 +1194,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u return 0; } -static void of_add_attachments(Muxer *mux, OptionsContext *o) +static void of_add_attachments(Muxer *mux, const OptionsContext *o) { OutputStream *ost; int err; @@ -1487,7 +1487,7 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *o static int copy_metadata(const char *outspec, const char *inspec, AVFormatContext *oc, AVFormatContext *ic, int *metadata_global_manual, int *metadata_streams_manual, - int *metadata_chapters_manual, OptionsContext *o) + int *metadata_chapters_manual, const OptionsContext *o) { AVDictionary **meta_in = NULL; AVDictionary **meta_out = NULL; @@ -1567,7 +1567,7 @@ static int copy_metadata(const char *outspec, const char *inspec, return 0; } -static void copy_meta(Muxer *mux, OptionsContext *o) +static void copy_meta(Muxer *mux, const OptionsContext *o) { OutputFile *of = &mux->of; AVFormatContext *oc = mux->fc; @@ -1703,7 +1703,7 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) return 0; } -int of_open(OptionsContext *o, const char *filename) +int of_open(const OptionsContext *o, const char *filename) { Muxer *mux; AVFormatContext *oc; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 38916304bc..d8de283fc2 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1186,7 +1186,7 @@ static const OptionGroupDef groups[] = { }; static int open_files(OptionGroupList *l, const char *inout, - int (*open_file)(OptionsContext*, const char*)) + int (*open_file)(const OptionsContext*, const char*)) { int i, ret;