From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 9F8B14CB36 for ; Sun, 16 Feb 2025 16:02:24 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 112F668BE03; Sun, 16 Feb 2025 18:01:36 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5852F68BA75 for ; Sun, 16 Feb 2025 18:01:24 +0200 (EET) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with ESMTP id 2394F434F7; Sun, 16 Feb 2025 17:01:24 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 16 Feb 2025 16:58:55 +0100 Message-ID: <20250216155855.450044-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250216155855.450044-1-ffmpeg@haasn.xyz> References: <20250216155855.450044-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avfilter/libplacebo: add option for outputting separate fields 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 Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas cf. the other deinterlacing-aware filters. --- doc/filters.texi | 5 +++++ libavfilter/vf_libplacebo.c | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index c7c8a5668e..6f0c89489e 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16632,6 +16632,11 @@ Yet another deinterlacing filter. See the @ref{yadif} filter for more details. @item skip_spatial_check Skip the spatial deinterlacing check when using @code{yadif} deinterlacing. + +@item send_fields +Output a frame for each field, rather than for each frame. Note that this will +always double the tagged output frame rate, even if the input does not contain +any interlaced frames. Disabled by default. @end table @subsubsection Debanding diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 7dc275f565..528eabd6d0 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -215,6 +215,7 @@ typedef struct LibplaceboContext { /* pl_deinterlace_params */ int deinterlace; int skip_spatial_check; + int send_fields; /* pl_deband_params */ int deband; @@ -970,8 +971,7 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) int64_t pts; while ((ret = ff_inlink_consume_frame(inlink, &in)) > 0) { - in->opaque = s; - pl_queue_push(input->queue, &(struct pl_source_frame) { + struct pl_source_frame src = { .pts = in->pts * av_q2d(inlink->time_base), .duration = in->duration * av_q2d(inlink->time_base), .first_field = s->deinterlace ? pl_field_from_avframe(in) : PL_FIELD_NONE, @@ -979,12 +979,21 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) .map = map_frame, .unmap = unmap_frame, .discard = discard_frame, - }); + }; + + in->opaque = s; + pl_queue_push(input->queue, &src); if (!s->fps.num) { /* Internally queue an output frame for the same PTS */ pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base); av_fifo_write(input->out_pts, &pts, 1); + + if (s->send_fields && src.first_field != PL_FIELD_NONE) { + /* Queue the second field for interlaced content */ + pts += av_rescale_q(in->duration, inlink->time_base, outlink->time_base) / 2; + av_fifo_write(input->out_pts, &pts, 1); + } } } @@ -1242,6 +1251,13 @@ static int libplacebo_config_output(AVFilterLink *outlink) avctx->inputs[i]->time_base, AV_TIME_BASE / 2, AV_TIME_BASE_Q); } + + if (s->deinterlace && s->send_fields) { + const AVRational q2 = { 2, 1 }; + ol->frame_rate = av_mul_q(ol->frame_rate, q2); + /* Ensure output frame timestamps are divisible by two */ + outlink->time_base = av_div_q(outlink->time_base, q2); + } } /* Static variables */ @@ -1376,6 +1392,7 @@ static const AVOption libplacebo_options[] = { { "bob", "Naive bob deinterlacing", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BOB}, 0, 0, STATIC, .unit = "deinterlace" }, { "yadif", "Yet another deinterlacing filter", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_YADIF}, 0, 0, STATIC, .unit = "deinterlace" }, { "skip_spatial_check", "Skip yadif spatial check", OFFSET(skip_spatial_check), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, + { "send_fields", "Output a frame for each field", OFFSET(send_fields), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC }, -- 2.47.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".