From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg_mux_init: make encoder_opts local to ost_add()
Date: Thu, 23 May 2024 11:03:39 +0200
Message-ID: <20240523090339.4228-4-anton@khirnov.net> (raw)
In-Reply-To: <20240523090339.4228-1-anton@khirnov.net>
It is no longer needed after this function returns.
---
fftools/ffmpeg.h | 2 --
fftools/ffmpeg_mux.c | 1 -
fftools/ffmpeg_mux_init.c | 71 ++++++++++++++++++++++-----------------
3 files changed, 40 insertions(+), 34 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9cab8148ca..51aee0679a 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -586,8 +586,6 @@ typedef struct OutputStream {
FilterGraph *fg_simple;
OutputFilter *filter;
- AVDictionary *encoder_opts;
-
char *attachment_filename;
/* stats */
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 055e2f3678..de3e052152 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -813,7 +813,6 @@ static void ost_free(OutputStream **post)
av_packet_free(&ms->bsf_pkt);
av_packet_free(&ms->pkt);
- av_dict_free(&ost->encoder_opts);
av_freep(&ost->kf.pts);
av_expr_free(ost->kf.pexpr);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 61a0d8658f..b8dc6017a9 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -905,7 +905,7 @@ static int new_stream_subtitle(Muxer *mux, const OptionsContext *o,
return 0;
}
-static int streamcopy_init(const Muxer *mux, OutputStream *ost)
+static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **encoder_opts)
{
MuxStream *ms = ms_from_ost(ost);
@@ -928,7 +928,7 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost)
ret = avcodec_parameters_to_context(codec_ctx, ist->par);
if (ret >= 0)
- ret = av_opt_set_dict(codec_ctx, &ost->encoder_opts);
+ ret = av_opt_set_dict(codec_ctx, encoder_opts);
if (ret < 0) {
av_log(ost, AV_LOG_FATAL,
"Error setting up codec context options.\n");
@@ -1039,6 +1039,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
OutputStream *ost;
const AVCodec *enc;
AVStream *st;
+ AVDictionary *encoder_opts = NULL;
int ret = 0, keep_pix_fmt = 0, autoscale = 1;
int threads_manual = 0;
AVRational enc_tb = { 0, 0 };
@@ -1160,10 +1161,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
const char *enc_time_base = NULL;
ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
- oc, st, enc->codec, &ost->encoder_opts,
+ oc, st, enc->codec, &encoder_opts,
&mux->enc_opts_used);
if (ret < 0)
- return ret;
+ goto fail;
MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
@@ -1187,7 +1188,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
break;
}
*arg++ = 0;
- av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
+ av_dict_set(&encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
} while (!s->eof_reached);
av_bprint_finalize(&bprint, NULL);
avio_closep(&s);
@@ -1195,7 +1196,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
if (ret) {
av_log(ost, AV_LOG_FATAL,
"Preset %s specified, but could not be opened.\n", preset);
- return ret;
+ goto fail;
}
MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st);
@@ -1207,7 +1208,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ret = enc_stats_init(ost, &ost->enc_stats_pre, 1, enc_stats_pre, format);
if (ret < 0)
- return ret;
+ goto fail;
}
MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st);
@@ -1219,7 +1220,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format);
if (ret < 0)
- return ret;
+ goto fail;
}
MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st);
@@ -1231,7 +1232,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format);
if (ret < 0)
- return ret;
+ goto fail;
}
MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
@@ -1253,7 +1254,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
#endif
) {
av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base);
- return ret < 0 ? ret : AVERROR(EINVAL);
+ ret = ret < 0 ? ret : AVERROR(EINVAL);
+ goto fail;
}
#if FFMPEG_OPT_ENC_TIME_BASE_NUM
if (q.num < 0)
@@ -1265,28 +1267,28 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
enc_tb = q;
}
- threads_manual = !!av_dict_get(ost->encoder_opts, "threads", NULL, 0);
+ threads_manual = !!av_dict_get(encoder_opts, "threads", NULL, 0);
- ret = av_opt_set_dict2(ost->enc_ctx, &ost->encoder_opts, AV_OPT_SEARCH_CHILDREN);
+ ret = av_opt_set_dict2(ost->enc_ctx, &encoder_opts, AV_OPT_SEARCH_CHILDREN);
if (ret < 0) {
av_log(ost, AV_LOG_ERROR, "Error applying encoder options: %s\n",
av_err2str(ret));
- return ret;
+ goto fail;
}
- ret = check_avoptions(ost->encoder_opts);
+ ret = check_avoptions(encoder_opts);
if (ret < 0)
- return ret;
+ goto fail;
// default to automatic thread count
if (!threads_manual)
ost->enc_ctx->thread_count = 0;
} else {
ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st,
- NULL, &ost->encoder_opts,
+ NULL, &encoder_opts,
&mux->enc_opts_used);
if (ret < 0)
- return ret;
+ goto fail;
}
@@ -1302,7 +1304,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
q.num <= 0 || q.den <= 0) {
av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
- return AVERROR(EINVAL);
+ ret = AVERROR(EINVAL);
+ goto fail;
}
st->time_base = q;
}
@@ -1325,7 +1328,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
if (ret < 0) {
av_log(ost, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
- return ret;
+ goto fail;
}
}
@@ -1378,12 +1381,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
case AVMEDIA_TYPE_SUBTITLE: ret = new_stream_subtitle (mux, o, ost); break;
}
if (ret < 0)
- return ret;
+ goto fail;
if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) {
ret = ost_get_filters(o, oc, ost, &filters);
if (ret < 0)
- return ret;
+ goto fail;
}
if (ost->enc &&
@@ -1431,7 +1434,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
if (threads_manual) {
ret = av_opt_get(ost->enc_ctx, "threads", 0, (uint8_t**)&opts.nb_threads);
if (ret < 0)
- return ret;
+ goto fail;
}
if (ofilter) {
@@ -1443,18 +1446,19 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
}
av_freep(&opts.nb_threads);
if (ret < 0)
- return ret;
+ goto fail;
ret = sch_connect(mux->sch, SCH_ENC(ms->sch_idx_enc),
SCH_MSTREAM(mux->sch_idx, ms->sch_idx));
if (ret < 0)
- return ret;
+ goto fail;
} else if (ost->ist) {
int sched_idx = ist_output_add(ost->ist, ost);
if (sched_idx < 0) {
av_log(ost, AV_LOG_ERROR,
"Error binding an input stream\n");
- return sched_idx;
+ ret = sched_idx;
+ goto fail;
}
ms->sch_idx_src = sched_idx;
@@ -1462,24 +1466,24 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ret = sch_connect(mux->sch, SCH_DEC(sched_idx),
SCH_ENC(ms->sch_idx_enc));
if (ret < 0)
- return ret;
+ goto fail;
ret = sch_connect(mux->sch, SCH_ENC(ms->sch_idx_enc),
SCH_MSTREAM(mux->sch_idx, ms->sch_idx));
if (ret < 0)
- return ret;
+ goto fail;
} else {
ret = sch_connect(mux->sch, SCH_DSTREAM(ost->ist->file->index, sched_idx),
SCH_MSTREAM(ost->file->index, ms->sch_idx));
if (ret < 0)
- return ret;
+ goto fail;
}
}
if (ost->ist && !ost->enc) {
- ret = streamcopy_init(mux, ost);
+ ret = streamcopy_init(mux, ost, &encoder_opts);
if (ret < 0)
- return ret;
+ goto fail;
}
// copy estimated duration as a hint to the muxer
@@ -1491,7 +1495,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
if (post)
*post = ost;
- return 0;
+ ret = 0;
+
+fail:
+ av_dict_free(&encoder_opts);
+
+ return ret;
}
static int map_auto_video(Muxer *mux, const OptionsContext *o)
--
2.43.0
_______________________________________________
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:[~2024-05-23 9:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 9:03 [FFmpeg-devel] [PATCH 1/4] lavc/qsvenc: rename the skip_frame private option to qsv_skip_frame Anton Khirnov
2024-05-23 9:03 ` [FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg: rewrite checking whether codec AVOptions have been used Anton Khirnov
2024-05-23 18:03 ` Marton Balint
2024-05-24 19:41 ` Michael Niedermayer
2024-05-23 9:03 ` [FFmpeg-devel] [PATCH 3/4] fftools/ffmpeg_mux_init: apply encoder options manually Anton Khirnov
2024-05-23 9:03 ` Anton Khirnov [this message]
2024-05-24 2:36 ` [FFmpeg-devel] [PATCH 1/4] lavc/qsvenc: rename the skip_frame private option to qsv_skip_frame Xiang, Haihao
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=20240523090339.4228-4-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