From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 02/10] fftools/ffmpeg_filter: compute input trim start/end in demuxer Date: Wed, 14 Feb 2024 19:24:27 +0100 Message-ID: <20240214182435.31380-2-anton@khirnov.net> (raw) In-Reply-To: <20240214182435.31380-1-anton@khirnov.net> The computation is based on demuxer properties, so that is the more appropriate place for it. Filter code just receives the desired start time/duration. --- fftools/ffmpeg.h | 11 +++++++---- fftools/ffmpeg_demux.c | 24 +++++++++++++++++++----- fftools/ffmpeg_filter.c | 23 ++++++----------------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 33750e0bb3..cbc5413238 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -250,6 +250,11 @@ typedef struct OptionsContext { SpecifierOptList mux_stats_fmt; } OptionsContext; +typedef struct InputFilterOptions { + int64_t trim_start_us; + int64_t trim_end_us; +} InputFilterOptions; + typedef struct InputFilter { struct FilterGraph *graph; uint8_t *name; @@ -394,15 +399,12 @@ typedef struct InputFile { int64_t ts_offset; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */ int64_t start_time; - int64_t recording_time; /* streams that ffmpeg is aware of; * there may be extra streams in ctx that are not mapped to an InputStream * if new streams appear dynamically during demuxing */ InputStream **streams; int nb_streams; - - int accurate_seek; } InputFile; enum forced_keyframes_const { @@ -790,7 +792,8 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch); void ifile_close(InputFile **f); int ist_output_add(InputStream *ist, OutputStream *ost); -int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple); +int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, + InputFilterOptions *opts); /** * Find an unused input stream of given type. diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 3bf95e2c3f..abda4ad0d9 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -103,6 +103,9 @@ typedef struct Demuxer { int64_t ts_offset_discont; int64_t last_ts; + int64_t recording_time; + int accurate_seek; + /* number of times input stream should be looped */ int loop; int have_audio_dec; @@ -450,13 +453,13 @@ static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags) if (ret < 0) return ret; - if (f->recording_time != INT64_MAX) { + if (d->recording_time != INT64_MAX) { int64_t start_time = 0; if (copy_ts) { start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0; start_time += start_at_zero ? 0 : f->start_time_effective; } - if (ds->dts >= f->recording_time + start_time) + if (ds->dts >= d->recording_time + start_time) *send_flags |= DEMUX_SEND_STREAMCOPY_EOF; } @@ -966,10 +969,12 @@ int ist_output_add(InputStream *ist, OutputStream *ost) return ost->enc ? ds->sch_idx_dec : ds->sch_idx_stream; } -int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) +int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, + InputFilterOptions *opts) { Demuxer *d = demuxer_from_ifile(ist->file); DemuxStream *ds = ds_from_ist(ist); + int64_t tsoffset = 0; int ret; ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER); @@ -995,6 +1000,15 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) ds->have_sub2video = 1; } + if (copy_ts) { + tsoffset = d->f.start_time == AV_NOPTS_VALUE ? 0 : d->f.start_time; + if (!start_at_zero && d->f.ctx->start_time != AV_NOPTS_VALUE) + tsoffset += d->f.ctx->start_time; + } + opts->trim_start_us = ((d->f.start_time == AV_NOPTS_VALUE) || !d->accurate_seek) ? + AV_NOPTS_VALUE : tsoffset; + opts->trim_end_us = d->recording_time; + return ds->sch_idx_dec; } @@ -1722,11 +1736,11 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch) } f->start_time = start_time; - f->recording_time = recording_time; + d->recording_time = recording_time; f->input_sync_ref = o->input_sync_ref; f->input_ts_offset = o->input_ts_offset; f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp); - f->accurate_seek = o->accurate_seek; + d->accurate_seek = o->accurate_seek; d->loop = o->loop; d->nb_streams_warn = ic->nb_streams; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ed62e1d8ec..c411b882de 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -103,6 +103,8 @@ typedef struct FilterGraphThread { typedef struct InputFilterPriv { InputFilter ifilter; + InputFilterOptions opts; + int index; AVFilterContext *filter; @@ -673,7 +675,8 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) ifp->ist = ist; ifp->type_src = ist->st->codecpar->codec_type; - dec_idx = ist_filter_add(ist, ifilter, filtergraph_is_simple(ifilter->graph)); + dec_idx = ist_filter_add(ist, ifilter, filtergraph_is_simple(ifilter->graph), + &ifp->opts); if (dec_idx < 0) return dec_idx; @@ -1478,7 +1481,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, AVBPrint args; char name[255]; int ret, pad_idx = 0; - int64_t tsoffset = 0; AVBufferSrcParameters *par = av_buffersrc_parameters_alloc(); if (!par) return AVERROR(ENOMEM); @@ -1558,13 +1560,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, snprintf(name, sizeof(name), "trim_in_%d_%d", f->index, ist->index); - if (copy_ts) { - tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; - if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) - tsoffset += f->ctx->start_time; - } - ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ? - AV_NOPTS_VALUE : tsoffset, f->recording_time, + ret = insert_trim(ifp->opts.trim_start_us, ifp->opts.trim_end_us, &last_filter, &pad_idx, name); if (ret < 0) return ret; @@ -1589,7 +1585,6 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph, AVBPrint args; char name[255]; int ret, pad_idx = 0; - int64_t tsoffset = 0; ifp->time_base = (AVRational){ 1, ifp->sample_rate }; @@ -1615,13 +1610,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph, snprintf(name, sizeof(name), "trim for input stream %d:%d", f->index, ist->index); - if (copy_ts) { - tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; - if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) - tsoffset += f->ctx->start_time; - } - ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ? - AV_NOPTS_VALUE : tsoffset, f->recording_time, + ret = insert_trim(ifp->opts.trim_start_us, ifp->opts.trim_end_us, &last_filter, &pad_idx, name); if (ret < 0) return ret; -- 2.42.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-02-14 18:25 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-14 18:24 [FFmpeg-devel] [PATCH 01/10] fftools/ffmpeg_filter: stop taking display matrix from global side data Anton Khirnov 2024-02-14 18:24 ` Anton Khirnov [this message] 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 03/10] fftools/ffmpeg_filter: accept a name from its upstream input Anton Khirnov 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 04/10] fftools/ffmpeg_filter: pass sub2video canvas size through InputFilterOptions Anton Khirnov 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 05/10] fftools/ffmpeg_filter: pass autorotate/reinit flags " Anton Khirnov 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 06/10] fftools/ffmpeg_filter: pass framerate " Anton Khirnov 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 07/10] fftools/ffmpeg_filter: refactor setting input timebase Anton Khirnov 2024-02-15 1:58 ` Michael Niedermayer 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 08/10] fftools/ffmpeg_filter: drop unused InputFilterPriv.ist Anton Khirnov 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 09/10] fftools/ffmpeg: move subtitle helpers to ffmpeg_dec, their only user Anton Khirnov 2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 10/10] fftools/ffmpeg: cosmetics, vertically align structs Anton Khirnov
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=20240214182435.31380-2-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