From patchwork Wed Feb 14 18:24:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46276 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:b819:b0:19e:cdac:8cce with SMTP id fi25csp114751pzb; Wed, 14 Feb 2024 10:25:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUcNjTl/dYmQuz1Iu2AkSf8ZmtbH2l9h4qwmb52nvUxOcg088HGEOyIGB/C3pLvrsYBFQINIkGr6axl4+cgqdRTASlax4xUUSdLvw== X-Google-Smtp-Source: AGHT+IEGjdFrmQoSTEbE8YKsT0bsa48IG7DwGU18vXLdVbm7/c2b9jHuxot8+qRrkelzjyJL2jjR X-Received: by 2002:ac2:5deb:0:b0:511:84ae:9f38 with SMTP id z11-20020ac25deb000000b0051184ae9f38mr2062619lfq.36.1707935114162; Wed, 14 Feb 2024 10:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707935114; cv=none; d=google.com; s=arc-20160816; b=Oo2aR4DKsGBQE0Z1hueR4zwICRCNKlGOgPa/JfanOdko1MB6qsCvYs+C6wzfGPWus7 /CZyyHt7qh307bHWEPOcas+YvB0nsBhoak/CqqraOeCcO2yw+A+2/v1kSQl5k3rZ6RbI JEt0SupxSs2NFTBgx0laMcZMWQzyjZN/Z7f2JxnVVncVq9XRV+Ygd6MHOi7aB4VIjSgM cD3KcvxIc+rsT56eCi/rlXWWVPSKdH4d8L239wISyMAB3Ou6c8MkZn/2kLvQO5mLSup7 8zND+39zeZfGdSlxCNTMAMpISYiYf5nVvpQdcl2akqrVZz7jQMy9JhkI4MqCDK/vBPw1 Vg5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=Q4/bfhZfPJkhBWv0q8GJEfhZ5Z08LWQCdeH3H3MZqbU=; fh=BU4X0J9elOZCOqC97DSdkntwGsRAKYRV4KwNkOPs8lg=; b=oLi0TIXOwA9WeWZvYdcBREUeeV/zL5Q2+2wSaEKQCUlsfK2utCIOvwvm8sLRREVxVQ 7ACB7sGaWsh/SEiwAwpROFFmivI62VnVpga3vqX/ZJXAfA7Ylmu9GN0+6htpK0nnZz4o Y39dYcXowMOo0+X1vqQWEn+k82sLQY5AUxQaq5UGOofB0qlpTjepVvfERFuVRB+p60IG e4DjXXhdxxHnlrqj40JvdaTklYG37c6pb3cgQXVHQGYj5AqGhj2FG77Xsa8mZmmOKLdJ SJICAqIGsK3Arjy+18NDXT1MFkjxVz/TFPo6lH18qcpQEGDKq4trBD+JuYOHFepMCGMc lS6g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=HueFisvF; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org X-Forwarded-Encrypted: i=1; AJvYcCUcU9zIRBIDH7/JLzlHjEvZam7xQmY2X8Wm66v4xG/7SaKMP4haVXxCfgtf+n/ljUU24od51Twm5aI9zUfZ2bZ2/QNCaYF2tx/thLO4wCvoHsA+xxPJFuUPZ4GdAT7BCEqPPeQnG8PddWdkbsWGmXv7nKtu9APC6ZdOs0TdnqtPGSyg7+rjpd5kCITwgMqpwDI1+pzAGXMHj6pNKz/yt+UhhvD/c19zthiCEEN5wN1HdwZmdFHwPcRvAcwRYKJ54CG73O71yPPRtbZbS5nqjz6Z0oh5d7IijzxdJtFs0+nOJD1yHzFEjbSFO0W6yyzWn3X83q41qtPw+Z6QytqhoR/Ahbe4oMST3vJQrfUiXR4XlKXFjFFdqNIqRMNBeA0GsIckDsLyUVTGCQm0G6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FAfVytEulLOJJg1VpJ2mxgqIY+VI8OBoRXsXpoF4Tas3UCavCztrV9UBthi8nh6CQ/14trse+bOTUYQ4Z56NvNSg7G+qYGzW3n0LcTpAuH4ZM35wF1OYRDLtss= Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f7-20020a056402160700b00561329529d6si4911845edv.22.2024.02.14.10.25.13; Wed, 14 Feb 2024 10:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=HueFisvF; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF40868D220; Wed, 14 Feb 2024 20:24:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F1DA068D20C for ; Wed, 14 Feb 2024 20:24:41 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=HueFisvF; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 8C5E04D26 for ; Wed, 14 Feb 2024 19:24:41 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ddFhci6kN-uR for ; Wed, 14 Feb 2024 19:24:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1707935078; bh=dBhetbQEwhDDE96LE3RWyyBp0j1pd/pg2N9z1O6U8Fc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HueFisvFRwb1dV25Pezm1qdNrRYRJXQmOpjKWN7MWWDJdOXx7hAGOtiAX7PvGVBWm ANFDeqB8gy916zQApQVhisF5IT1mQm6f9voBJWHQPnBMVyHjoLNbvd3cypXwDfsRM5 wpnKs4BiN2PEUEcRAaTfyNjFKPxRw0SS+cXvmhAsLblGzn8YmnRwrhgv3P/EkQxAWV GxQf0TXKkgDAJz1RBXKML1ir5RYdG5GSkF9y+4cIlJijaLv+lo7zbPsuof6t6cTbGJ 880aqGzz4VgEhQcywuiWn4221Z9q46csQ5taPgr9gsPibSL9SybEkZ6MVISGSjEYlq tFVpuAFpe9BOQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 7B3364482 for ; Wed, 14 Feb 2024 19:24:38 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5EF5C3A1684 for ; Wed, 14 Feb 2024 19:24:38 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Feb 2024 19:24:27 +0100 Message-ID: <20240214182435.31380-2-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240214182435.31380-1-anton@khirnov.net> References: <20240214182435.31380-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/10] fftools/ffmpeg_filter: compute input trim start/end in demuxer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ycEf0y1rbLa5 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;