[FFmpeg-devel] [PATCH 21/31] fftools/ffmpeg_filter: pass trim parameters through OutputFilterOptions
Anton Khirnov
anton at khirnov.net
Fri Apr 5 19:12:02 EEST 2024
Do not read them from OutputStream directly.
Will allow decoupling filtering from encoding in future commits.
---
fftools/ffmpeg.h | 2 ++
fftools/ffmpeg_filter.c | 11 +++++++----
fftools/ffmpeg_mux_init.c | 2 ++
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 4059b1dcc3..8e773165da 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -279,6 +279,8 @@ typedef struct OutputFilterOptions {
// Overrides encoder pixel formats when set.
const enum AVPixelFormat *pix_fmts;
+ int64_t trim_start_us;
+ int64_t trim_duration_us;
int64_t ts_offset;
/* Desired output timebase.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index dc9556bbc1..225fa4bda2 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -220,6 +220,8 @@ typedef struct OutputFilterPriv {
const int *sample_rates;
AVRational enc_timebase;
+ int64_t trim_start_us;
+ int64_t trim_duration_us;
// offset for output timestamps, in AV_TIME_BASE_Q
int64_t ts_offset;
int64_t next_pts;
@@ -812,6 +814,9 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
ofp->ts_offset = opts->ts_offset;
ofp->enc_timebase = opts->output_tb;
+ ofp->trim_start_us = opts->trim_start_us;
+ ofp->trim_duration_us = opts->trim_duration_us;
+
ofp->name = av_strdup(opts->name);
if (!ofp->name)
return AVERROR(EINVAL);
@@ -1349,8 +1354,6 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph,
OutputFilter *ofilter, AVFilterInOut *out)
{
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
- OutputStream *ost = ofilter->ost;
- OutputFile *of = ost->file;
AVFilterContext *last_filter = out->filter_ctx;
AVBPrint bprint;
int pad_idx = out->pad_idx;
@@ -1411,7 +1414,7 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph,
}
snprintf(name, sizeof(name), "trim_out_%s", ofp->name);
- ret = insert_trim(of->start_time, of->recording_time,
+ ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
&last_filter, &pad_idx, name);
if (ret < 0)
return ret;
@@ -1503,7 +1506,7 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
}
snprintf(name, sizeof(name), "trim for output %s", ofp->name);
- ret = insert_trim(of->start_time, of->recording_time,
+ ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
&last_filter, &pad_idx, name);
if (ret < 0)
goto fail;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 51c31eeb72..6e19b98abd 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1389,6 +1389,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
.sws_opts = o->g->sws_dict,
.swr_opts = o->g->swr_opts,
.output_tb = enc_tb,
+ .trim_start_us = mux->of.start_time,
+ .trim_duration_us = mux->of.recording_time,
.ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
0 : mux->of.start_time,
.flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt |
--
2.43.0
More information about the ffmpeg-devel
mailing list