From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 5/8] fftools/ffmpeg_mux_init: move validating codec avoptions to a separate function
Date: Mon, 14 Nov 2022 16:13:47 +0100
Message-ID: <20221114151350.5134-5-anton@khirnov.net> (raw)
In-Reply-To: <20221114151350.5134-1-anton@khirnov.net>
---
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_mux_init.c | 91 +++++++++++++++++++++------------------
fftools/ffmpeg_opt.c | 2 +-
3 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ad53ad4ce8..b9262b373f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -694,7 +694,7 @@ void assert_avoptions(AVDictionary *m);
void assert_file_overwrite(const char *filename);
char *file_read(const char *filename);
-AVDictionary *strip_specifiers(AVDictionary *dict);
+AVDictionary *strip_specifiers(const AVDictionary *dict);
const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder);
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 150eb77ee2..7ccaf9da78 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1725,14 +1725,60 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx)
return 0;
}
+static void validate_enc_avopt(const Muxer *mux, const AVDictionary *codec_avopt)
+{
+ const OutputFile *of = &mux->of;
+
+ AVDictionary *unused_opts;
+ const AVDictionaryEntry *e;
+
+ unused_opts = strip_specifiers(codec_avopt);
+ for (int i = 0; i < of->nb_streams; i++) {
+ e = NULL;
+ while ((e = av_dict_get(of->streams[i]->encoder_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_ENCODING_PARAM)) {
+ av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
+ "output file #%d (%s) is not an encoding option.\n", e->key,
+ option->help ? option->help : "", nb_output_files - 1,
+ mux->fc->url);
+ exit_program(1);
+ }
+
+ // gop_timecode is injected by generic code but not always used
+ if (!strcmp(e->key, "gop_timecode"))
+ continue;
+
+ av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
+ "output 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 encoder "
+ "which was not actually used for any stream.\n", e->key,
+ option->help ? option->help : "", nb_output_files - 1, mux->fc->url);
+ }
+ av_dict_free(&unused_opts);
+}
+
int of_open(const OptionsContext *o, const char *filename)
{
Muxer *mux;
AVFormatContext *oc;
int err;
OutputFile *of;
- AVDictionary *unused_opts = NULL;
- const AVDictionaryEntry *e = NULL;
int64_t recording_time = o->recording_time;
int64_t stop_time = o->stop_time;
@@ -1795,46 +1841,7 @@ int of_open(const OptionsContext *o, const char *filename)
create_streams(mux, o);
/* check if all codec options have been used */
- unused_opts = strip_specifiers(o->g->codec_opts);
- for (int i = 0; i < of->nb_streams; i++) {
- e = NULL;
- while ((e = av_dict_get(of->streams[i]->encoder_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_ENCODING_PARAM)) {
- av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
- "output file #%d (%s) is not an encoding option.\n", e->key,
- option->help ? option->help : "", nb_output_files - 1,
- filename);
- exit_program(1);
- }
-
- // gop_timecode is injected by generic code but not always used
- if (!strcmp(e->key, "gop_timecode"))
- continue;
-
- av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
- "output 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 encoder "
- "which was not actually used for any stream.\n", e->key,
- option->help ? option->help : "", nb_output_files - 1, filename);
- }
- av_dict_free(&unused_opts);
+ validate_enc_avopt(mux, o->g->codec_opts);
/* set the decoding_needed flags and create simple filtergraphs */
for (int i = 0; i < of->nb_streams; i++) {
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 0fd9d98f0f..5ab296828b 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -165,7 +165,7 @@ static int show_hwaccels(void *optctx, const char *opt, const char *arg)
}
/* return a copy of the input with the stream specifiers removed from the keys */
-AVDictionary *strip_specifiers(AVDictionary *dict)
+AVDictionary *strip_specifiers(const AVDictionary *dict)
{
const AVDictionaryEntry *e = NULL;
AVDictionary *ret = NULL;
--
2.35.1
_______________________________________________
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".
next prev parent reply other threads:[~2022-11-14 15:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 15:13 [FFmpeg-devel] [PATCH 1/8] fftools/ffmpeg: simplify ost_iter() Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 2/8] fftools/ffmpeg_mux_init: move more code from of_open() to create_streams() Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 3/8] fftools/ffmpeg: stop handling max_frames in do_video_out() Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 4/8] fftools/ffmpeg: move OutputStream.max_frames to MuxStream Anton Khirnov
2022-11-14 15:13 ` Anton Khirnov [this message]
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 6/8] fftools/ffmpeg_mux_init: do not call av{codec, format}_get_class() repeatedly Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 7/8] fftools/ffmpeg_mux_init: use av_dict_iterate() where appropriate Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 8/8] fftools/ffmpeg_mux_init: drop an always-false check Anton Khirnov
2022-11-14 17:29 ` [FFmpeg-devel] [PATCH 1/8] fftools/ffmpeg: simplify ost_iter() Soft Works
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221114151350.5134-5-anton@khirnov.net \
--to=anton@khirnov.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git