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 6528E4CB42 for ; Thu, 10 Jul 2025 16:29:29 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id E76E168FAE0; Thu, 10 Jul 2025 19:29:25 +0300 (EEST) References: In-Reply-To: Date: Thu, 10 Jul 2025 18:29:06 +0200 To: FFmpeg development discussions and patches MIME-Version: 1.0 Message-ID: List-Id: FFmpeg development discussions and patches List-Post: From: Maryla Ustarroz via ffmpeg-devel Precedence: list Cc: Maryla Ustarroz X-Mailman-Version: 2.1.29 X-BeenThere: ffmpeg-devel@ffmpeg.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: FFmpeg development discussions and patches List-Help: Subject: Re: [FFmpeg-devel] [PATCH v2] ffprobe: add -codec: option Content-Type: multipart/mixed; boundary="===============8179165201076223454==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============8179165201076223454== Content-Type: message/rfc822 Content-Disposition: inline Return-Path: X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 7581E68FA42 for ; Thu, 10 Jul 2025 19:29:20 +0300 (EEST) Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-6fafdd322d3so11735866d6.3 for ; Thu, 10 Jul 2025 09:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752164958; x=1752769758; darn=ffmpeg.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kn28ukto9uZnVeiWUT36t8DbtgJFVKxn0CLNNwBYoqk=; b=oLtKetkrEcQJ/QM3kdQL0Gb0PAaOVSsXSPP5CQtg8P/3rH9rJIXji+r7nUnky9C09k 6jXPMGNjb0S5IdBPiTTAhE7FJFAop/T4GduM+a2ltSrBIQMfh/jelROEK5PYrDmg01IN goXNjUDOtXAHNsoUlqQ4i23ENgIw28VC9GSXTWd/HG3ZU+r5jIJYTgsbfO8gPuRoUsqH WmfuNHWCapsSqNHuvYq6MaWrzebm2MPteHK7kmqaQXNUhBEN8AtVlTeF3Smh7Mql/u4+ nf0l6QSsA62ZrFM5fefty9XvnvvodzaYvcWo0wT3Pk1Z/aFDxBkqm9NkC9eWVBI9QIwa T8xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752164958; x=1752769758; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kn28ukto9uZnVeiWUT36t8DbtgJFVKxn0CLNNwBYoqk=; b=pHL9HJTYDV0zJyP3KUGNbdLSmCeWPuAcqhmsJiiLg1jqI4UV3zQB09DKOkSz72zhO3 bS5Kllcae8HAcogNgiHWGl+iiuqryV3ZYYc+zEb5fAQ6eyGa2xpm0j5pUAjTLgA0LG3z lUDGXKWlaskWAy1aJUlDD7qY1gFEsIllfwIOts7g7GVJNMaaa4aQ7lhx2wtmSWquIF6j NOfuRAzNcOxeujdEGqpOft/Jmp3Z1mfMtIwViH1SbK3UTsfJ9NiW7BgmHJ/v/RIQcbTb 4mbV3OKD4c6Cadk3G+NRvXRQL6ewd5xNmcNW5VE4Urzm2nC4GIdwlFwMAZw/L0Yl7iLe l+xQ== X-Gm-Message-State: AOJu0Yy7DqPrSwiw3hlR4hFlgqI2SN/2Lxx4WNT7kzhtGryaAKXMdB8k EWr2mc77V05HhO//Xc/wXv08CpjnS797YV73LZCJTrgC94uzNfWh86EICly8Muqoel1oIO62uh2 P5UfznlJTVymzmFXbMNtsttfaPQXtVyojW7GdxHAY+GZzKGTFbU8LQOlW6sY= X-Gm-Gg: ASbGncuF2+cC0mWx8gY2nWN7Yz79Q+pj036S0NzsKL7SceRZD4pD4oCcaBp4T45TaQ+ DhpuoNPOa6Z3nhBLyiONjvqrpwRQJ9EBBcZur2gaoSTVNwT4/JmOBTCvvtMsyV/C69X7yyvPgpT c+gl6HLY/RZ5OkXeDB+7W0r46rbUQ4fsKkzFHFP4tuO7M= X-Google-Smtp-Source: AGHT+IFEwpWAq4fVHGaUdCupbTsmKD7RlWVBGPUXYawAMvwuje1+LM1M4zD/R9SDSSqgBG6yfhyQBkGzyo0FK2UOWCI= X-Received: by 2002:a0c:f40a:0:b0:700:9ee6:56f2 with SMTP id 6a1803df08f44-704a3314b55mr544216d6.5.1752164957945; Thu, 10 Jul 2025 09:29:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Maryla Ustarroz Date: Thu, 10 Jul 2025 18:29:06 +0200 X-Gm-Features: Ac12FXyRSFMH3KBfIlIOPSqQy3I9f440lRbIQGHQhtZkUgjHm9JquCVReEpyLIc Message-ID: Subject: Re: [FFmpeg-devel] [PATCH v2] ffprobe: add -codec: option To: FFmpeg development discussions and patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 27, 2025 at 10:24=E2=80=AFAM Maryla Ustarroz-Calonge via ffmpeg-devel wrote: > > > > > ---------- Forwarded message ---------- > From: Maryla Ustarroz-Calonge > To: ffmpeg-devel@ffmpeg.org > Cc: > Bcc: > Date: Fri, 27 Jun 2025 10:23:56 +0200 > Subject: [PATCH v2] ffprobe: add -codec: option > And -c: variant. > Update ffprobe.texi. > opt_codec() is mostly copied over from ffplay.c > > Signed-off-by: Maryla Ustarroz-Calonge > --- > Changelog | 2 +- > doc/ffprobe.texi | 8 ++++ > fftools/ffprobe.c | 117 +++++++++++++++++++++++++++++++++++++++++----- > 3 files changed, 114 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/doc/ffprobe.texi b/doc/ffprobe.texi > index 8834df8d35..4ce0c8b583 100644 > --- a/doc/ffprobe.texi > +++ b/doc/ffprobe.texi > @@ -368,6 +368,14 @@ Read @var{input_url}. > Write output to @var{output_url}. If not specified, the output is sent > to stdout. > > +@item -c:@var{media_specifier} @var{codec_name} > +Force a specific decoder implementation for the stream identified by > +@var{media_specifier}, which can assume the values @code{a} (audio), > +@code{v} (video), @code{s} (subtitle), and @code{d} (data). > + > +@item -codec:@var{media_specifier} @var{codec_name} > +Alias for -c:@var{media_specifier}. > + > @end table > @c man end > > diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c > index 1346ed33c5..14ba4d3fb0 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 =3D 0; > static int use_value_sexagesimal_format =3D 0; > static int show_private_data =3D 1; > > +static const char *audio_codec_name =3D NULL; > +static const char *data_codec_name =3D NULL; > +static const char *subtitle_codec_name =3D NULL; > +static const char *video_codec_name =3D 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, i= nt err) > avtext_print_section_footer(tfc); > } > > +static int get_decoder_by_name(const char *codec_name, const AVCodec **c= odec) > +{ > + if (codec_name =3D=3D NULL) > + return 0; > + > + *codec =3D avcodec_find_decoder_by_name(codec_name); > + if (*codec =3D=3D NULL) { > + av_log(NULL, AV_LOG_ERROR, > + "No codec could be found with name '%s'\n", codec_name); > + return AVERROR(EINVAL); > + } > + return 0; > +} > + > +static int set_decoders(AVFormatContext *fmt_ctx) > +{ > + int ret; > + ret =3D get_decoder_by_name(audio_codec_name, &fmt_ctx->audio_codec)= ; > + if (ret < 0) return ret; > + ret =3D get_decoder_by_name(data_codec_name, &fmt_ctx->data_codec); > + if (ret < 0) return ret; > + ret =3D get_decoder_by_name(subtitle_codec_name, &fmt_ctx->subtitle_= codec); > + if (ret < 0) return ret; > + ret =3D 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, A= VStream *stream) > +{ > + const AVCodec *codec =3D NULL; > + switch (stream->codecpar->codec_type) { > + case AVMEDIA_TYPE_VIDEO: codec =3D fmt_ctx->video_codec; brea= k; > + case AVMEDIA_TYPE_AUDIO: codec =3D fmt_ctx->audio_codec; brea= k; > + case AVMEDIA_TYPE_SUBTITLE: codec =3D fmt_ctx->subtitle_codec; b= reak; > + case AVMEDIA_TYPE_DATA: codec =3D fmt_ctx->data_codec; break= ; > + } > + > + if (codec !=3D NULL) > + return codec; > + > + if (stream->codecpar->codec_id =3D=3D AV_CODEC_ID_PROBE) { > + av_log(NULL, AV_LOG_WARNING, > + "Failed to probe codec for input stream %d\n", stream->in= dex); > + return NULL; > + } > + > + codec =3D avcodec_find_decoder(stream->codecpar->codec_id); > + if (codec =3D=3D 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 =3D set_decoders(fmt_ctx); > + if (err < 0) > + return err; > if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_C= ASE)) { > av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVE= RWRITE); > scan_all_pmts_set =3D 1; > @@ -2350,20 +2417,10 @@ static int open_input_file(InputFile *ifile, cons= t char *filename, > > ist->st =3D stream; > > - if (stream->codecpar->codec_id =3D=3D AV_CODEC_ID_PROBE) { > - av_log(NULL, AV_LOG_WARNING, > - "Failed to probe codec for input stream %d\n", > - stream->index); > + codec =3D get_decoder_for_stream(fmt_ctx, stream); > + if (!codec) > continue; > - } > > - codec =3D 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,36 @@ 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 =3D 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: " > + "where can be one of: 'a' (audio), 'v' (video= ), 's' (subtitle), 'd' (data)\n", > + arg, opt, opt); > + return AVERROR(EINVAL); > + } > + spec++; > + > + switch (spec[0]) { > + case 'a' : name =3D &audio_codec_name; break; > + case 'd' : name =3D &data_codec_name; break; > + case 's' : name =3D &subtitle_codec_name; break; > + case 'v' : name =3D &video_codec_name; break; > + default: > + av_log(NULL, AV_LOG_ERROR, > + "Invalid media specifier '%s' in option '%s'. " > + "Must be one of: 'a' (audio), 'v' (video), 's' (subtitle),= 'd' (data)\n", spec, opt); > + return AVERROR(EINVAL); > + } > + > + av_freep(name); > + *name =3D av_strdup(arg); > + return *name ? 0 : AVERROR(ENOMEM); > +} > + > 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 +3130,8 @@ static const OptionDef real_options[] =3D { > { "print_filename", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = =3D 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 he= uristics" }, > + { "c", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = =3D opt_codec}, "force decoder", "decoder_name" }, > + { "codec", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = =3D opt_codec}, "alias for -c (force decoder)", "decoder_name" }, > { NULL, }, > }; > > -- > 2.50.0.727.gbf7dc18ff4-goog > Friendly ping. This is a v2 of the patch that includes the shorter -c flag in addition to -codec as suggested in the v1 review. It also updates ffprobe.texi which was missing from v1. This ffprobe feature was requested during the review of "[PATCH 2/2] avcodec/libaom: Add tests for HDR10+ metadata support" https://ffmpeg.org/pipermail/ffmpeg-devel/2025-June/344683.html > > ---------- Forwarded message ---------- > From: Maryla Ustarroz-Calonge via ffmpeg-devel > To: ffmpeg-devel@ffmpeg.org > Cc: Maryla Ustarroz-Calonge > Bcc: > Date: Fri, 27 Jun 2025 10:23:56 +0200 > Subject: [FFmpeg-devel] [PATCH v2] ffprobe: add -codec: optio= n > _______________________________________________ > 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". --===============8179165201076223454== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============8179165201076223454==--