From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 5CEAE4C049 for ; Mon, 28 Jul 2025 20:07:48 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 68518687D15; Mon, 28 Jul 2025 23:07:43 +0300 (EEST) Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 4F63368D08B for ; Mon, 28 Jul 2025 23:07:36 +0300 (EEST) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-615622ed677so640213a12.1 for ; Mon, 28 Jul 2025 13:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753733255; x=1754338055; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=1XvcfcDEFRKNYfgT4zNHRqyyllLFLxA5QAkLvE85Ok8=; b=iqEWYiTS/Y/I7yk6UyUCSebpaFHV64iu5KCekGYe1ZNjplVjnuRN46eNAAulwopJou WF4NTOsAhZOoq+hL/LiVfHSuRA0f7SNOKj9/sm91RO0wJzu7cKErGT3Ub1xfF82eMDPe pqaIShsbGHCuTHV47WvGIK7ti+WU5u3Kto26Za3qjq5jy378bNNwpSLBMNlQ3uvkk5Cw ONxYQ+hdQPrZYWHDF7gEqxvL+0IqJA/a9/H8mtBdoVYnH1JjVM6iySskybeo5NohST39 b3tlA20H2PtZJK9akeFV9Ih9akZaZXD4MTVlirO7vr77ngHWH+dTyFz9bvTWBBqI0Gso hCBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753733255; x=1754338055; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1XvcfcDEFRKNYfgT4zNHRqyyllLFLxA5QAkLvE85Ok8=; b=XvUP+qkdfX74Dv2tEyb1PEIMY5xzXlqLNpBDBqE85f+6/EHBZONfi5cDZ7yvF/HAZ4 KWOEqjGvT5FzNFVlDATphVdKsA0TCSPlhUCrj2pq57xOVVFHo5RJKFFLRKPhAaEwz3Va wn9AH0hijZZwNrHQ3jMPNLkiBtBB75z6hOMEmzPeHoG4MOnDSkFSGneyo0mypDHRgHjk jqh3qJkwAM5M3pmwEzLewvM6Ngx6Uuq/gvy8MTfGsBcJ1KxYY/vDb0n9e3vWJB1W8V7x tAqlNAmaBJvlga9s2zfIjnGtoTZUtimzp0EE88n2gpFj2drJbsyeEzCz4RSQ4TNi/sjX MiFA== X-Gm-Message-State: AOJu0YxPk5Q0WufYIONAf+cTjvzGMxd31h56v9Vo9upHGG8UlQ1OlUyO ldgIV50pzEl8CNh/Cv3597+PY00Is9p8KVnMxQG4yw+AqGn5MEZsBq4Yf4r1E/ds6Po= X-Gm-Gg: ASbGnct9iBMQLAtFpoE8UWmkM55CsWUjsTTMYXIM1D2p7hCSCohYjisr2e2e2PC/A5K 2HW6udrSxcyW7SeYclF8vR4eO9NMzZpbeMdvcI9ZHE/EYHnxseNKDZUXjQ3ierOLOhRQBHzvibs q9yeuVrhCxFudExNv2cSn+9O2khHiVq8RJUJ20WMOWI7oiHb1Zv5YMJHd9/Uy6g72HiL5Ip0vTh 4yx49e+t2yskDFbM8E/uLDk+uoINVLiqtuE135GV7qNVus6misIhrXUE8ipmPmHx+35Q2pHYoEB CnPdk/2cS11ruoRY2SsH6Jg9ScbwhGUfI5WjmwfZ/D//ykQurFdTak83YgLbH/wPT5STIXR8yF+ RcSrTPCfLF4/9db1DlEatZ4LVUxsqo8zOCTLqUDifmIp60uXk1m8dwMmDT7oojQ== X-Google-Smtp-Source: AGHT+IHYQcyxDEvX0L7Wqdx2m/T4G7Hj509cDYF9bqkdxQO5E5DMX8kpq3l/PbxKQG5H9AZCkRDygg== X-Received: by 2002:a05:6402:42c8:b0:615:4244:8c46 with SMTP id 4fb4d7f45d1cf-61542449868mr4399093a12.28.1753733254738; Mon, 28 Jul 2025 13:07:34 -0700 (PDT) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6156a168f6esm9478a12.18.2025.07.28.13.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jul 2025 13:07:34 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id ECDC1BFCE8; Mon, 28 Jul 2025 22:07:34 +0200 (CEST) Date: Mon, 28 Jul 2025 22:07:34 +0200 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches , Maryla Ustarroz-Calonge References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH] ffprobe: add -codec: option 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 Cc: Maryla Ustarroz-Calonge Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Hi, sorry for the slow reply. On date Tuesday 2025-06-10 17:02:05 +0200, ffmpeg-devel Mailing List wrote: > From: Maryla Ustarroz-Calonge > Subject: [PATCH] ffprobe: add -codec: option > Date: Tue, 10 Jun 2025 17:02:05 +0200 > To: ffmpeg-devel@ffmpeg.org > X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog > > opt_codec() is mostly copied over from ffplay.c > > Signed-off-by: Maryla Ustarroz-Calonge > --- > Changelog | 2 +- > fftools/ffprobe.c | 114 +++++++++++++++++++++++++++++++++++++++++----- > 2 files changed, 103 insertions(+), 13 deletions(-) > > diff --git a/Changelog b/Changelog > index 4217449438..ae73611222 100644 > --- a/Changelog > +++ b/Changelog > @@ -18,7 +18,7 @@ version : > - APV encoding support through a libopenapv wrapper > - VVC decoder supports all content of SCC (Screen Content Coding): > IBC (Inter Block Copy), Palette Mode and ACT (Adaptive Color Transform > - > +- ffprobe -codec option > > version 7.1: > - Raw Captions with Time (RCWT) closed caption demuxer > diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c > index 1346ed33c5..0124ce114c 100644 > --- a/fftools/ffprobe.c > +++ b/fftools/ffprobe.c > @@ -36,6 +36,7 @@ > #include "libavutil/ambient_viewing_environment.h" > #include "libavutil/avassert.h" > #include "libavutil/avstring.h" > +#include "libavutil/avutil.h" > #include "libavutil/bprint.h" > #include "libavutil/channel_layout.h" > #include "libavutil/display.h" > @@ -130,6 +131,11 @@ static int use_byte_value_binary_prefix = 0; > static int use_value_sexagesimal_format = 0; > static int show_private_data = 1; > > +static const char *audio_codec_name = NULL; > +static const char *data_codec_name = NULL; > +static const char *subtitle_codec_name = NULL; > +static const char *video_codec_name = NULL; > + > #define SHOW_OPTIONAL_FIELDS_AUTO -1 > #define SHOW_OPTIONAL_FIELDS_NEVER 0 > #define SHOW_OPTIONAL_FIELDS_ALWAYS 1 > @@ -2284,6 +2290,64 @@ static void show_error(AVTextFormatContext *tfc, int err) > avtext_print_section_footer(tfc); > } > > +static int get_decoder_by_name(const char *codec_name, const AVCodec **codec) > +{ > + if (codec_name == NULL) > + return 0; > + > + *codec = avcodec_find_decoder_by_name(codec_name); > + if (*codec == NULL) { > + av_log(NULL, AV_LOG_ERROR, > + "No codec could be found with name '%s'\n", codec_name); > + return AVERROR(EINVAL);; nit: drop duplicated ; > + } > + return 0; > +} > + > +static int set_decoders(AVFormatContext *fmt_ctx) > +{ > + int ret; > + ret = get_decoder_by_name(audio_codec_name, &fmt_ctx->audio_codec); > + if (ret < 0) return ret; > + ret = get_decoder_by_name(data_codec_name, &fmt_ctx->data_codec); > + if (ret < 0) return ret; > + ret = get_decoder_by_name(subtitle_codec_name, &fmt_ctx->subtitle_codec); > + if (ret < 0) return ret; > + ret = get_decoder_by_name(video_codec_name, &fmt_ctx->video_codec); > + if (ret < 0) return ret; > + return 0; > +} > + > +static const AVCodec *get_decoder_for_stream(AVFormatContext *fmt_ctx, AVStream *stream) > +{ > + const AVCodec *codec = NULL; > + switch (stream->codecpar->codec_type) { > + case AVMEDIA_TYPE_VIDEO: codec = fmt_ctx->video_codec; break; > + case AVMEDIA_TYPE_AUDIO: codec = fmt_ctx->audio_codec; break; > + case AVMEDIA_TYPE_SUBTITLE: codec = fmt_ctx->subtitle_codec; break; > + case AVMEDIA_TYPE_DATA: codec = fmt_ctx->data_codec; break; > + } > + > + if (codec != NULL) > + return codec; > + > + if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) { > + av_log(NULL, AV_LOG_WARNING, > + "Failed to probe codec for input stream %d\n", stream->index); > + return NULL; > + } > + > + codec = avcodec_find_decoder(stream->codecpar->codec_id); > + if (codec == NULL) { > + av_log(NULL, AV_LOG_WARNING, > + "Unsupported codec with id %d for input stream %d\n", > + stream->codecpar->codec_id, stream->index); > + return NULL; > + } > + > + return codec; > +} > + > static int open_input_file(InputFile *ifile, const char *filename, > const char *print_filename) > { > @@ -2296,6 +2360,9 @@ static int open_input_file(InputFile *ifile, const char *filename, > if (!fmt_ctx) > return AVERROR(ENOMEM); > > + err = set_decoders(fmt_ctx); > + if (err < 0) > + return err; > if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) { > av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE); > scan_all_pmts_set = 1; > @@ -2350,20 +2417,10 @@ static int open_input_file(InputFile *ifile, const char *filename, > > ist->st = stream; > > - if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) { > - av_log(NULL, AV_LOG_WARNING, > - "Failed to probe codec for input stream %d\n", > - stream->index); > + codec = get_decoder_for_stream(fmt_ctx, stream); > + if (!codec) > continue; > - } > > - codec = avcodec_find_decoder(stream->codecpar->codec_id); > - if (!codec) { > - av_log(NULL, AV_LOG_WARNING, > - "Unsupported codec with id %d for input stream %d\n", > - stream->codecpar->codec_id, stream->index); > - continue; > - } > { > AVDictionary *opts; > > @@ -2510,6 +2567,10 @@ end: > av_freep(&selected_streams); > av_freep(&streams_with_closed_captions); > av_freep(&streams_with_film_grain); > + av_freep(&audio_codec_name); > + av_freep(&data_codec_name); > + av_freep(&subtitle_codec_name); > + av_freep(&video_codec_name); > > return ret; > } > @@ -2964,6 +3025,34 @@ static int opt_sections(void *optctx, const char *opt, const char *arg) > return 0; > } > > +static int opt_codec(void *optctx, const char *opt, const char *arg) > +{ > + const char *spec = strchr(opt, ':'); > + const char **name; > + if (!spec) { > + av_log(NULL, AV_LOG_ERROR, > + "No media specifier was specified for '%s' in option '%s'. Use -%s:\n", > + arg, opt, opt); > + return AVERROR(EINVAL); > + } > + spec++; > + > + switch (spec[0]) { > + case 'a' : name = &audio_codec_name; break; > + case 'd' : name = &data_codec_name; break; > + case 's' : name = &subtitle_codec_name; break; > + case 'v' : name = &video_codec_name; break; > + default: > + av_log(NULL, AV_LOG_ERROR, > + "Invalid media specifier '%s' in option '%s'. Must be one of: v, a, s, d\n", spec, opt); > + return AVERROR(EINVAL); > + } > + > + av_freep(name); > + *name = av_strdup(arg); > + return *name ? 0 : AVERROR(ENOMEM); > +} > + Not super happy that this is duplicated but I see no sane way to factorize it. > static int opt_show_versions(void *optctx, const char *opt, const char *arg) > { > mark_section_show_entries(SECTION_ID_PROGRAM_VERSION, 1, NULL); > @@ -3039,6 +3128,7 @@ static const OptionDef real_options[] = { > { "print_filename", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"}, > { "find_stream_info", OPT_TYPE_BOOL, OPT_INPUT | OPT_EXPERT, { &find_stream_info }, > "read and decode the streams to fill missing information with heuristics" }, > + { "codec", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_codec}, "force decoder", "decoder_name" }, > { NULL, }, > }; Please also add an update for the docs and a short explanation of the use case in the commit log. Thanks. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".