History

avfilter/libplacebo: add option for outputting separate fields

cf. the other deinterlacing-aware filters.

Niklas Haas committed 1 year ago

Commit 27814dc1 parent 83c1b342 files · +25 −3Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_libplacebo.c+20−3
@@ -215,6 +215,7 @@ typedef struct LibplaceboContext { · 214 unmodified lines
215215 /* pl_deinterlace_params */
216216 int deinterlace;
217217 int skip_spatial_check;
218+ int send_fields;
218219
219220 /* pl_deband_params */
220221 int deband;
@@ -967,8 +968,7 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) · 746 unmodified lines
967968 int64_t pts;
968969
969970 while ((ret = ff_inlink_consume_frame(inlink, &in)) > 0) {
970− in->opaque = s;
971− pl_queue_push(input->queue, &(struct pl_source_frame) {
971+ struct pl_source_frame src = {
972972 .pts = in->pts * av_q2d(inlink->time_base),
973973 .duration = in->duration * av_q2d(inlink->time_base),
974974 .first_field = s->deinterlace ? pl_field_from_avframe(in) : PL_FIELD_NONE,
@@ -976,12 +976,21 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) · 1 unmodified line
976976 .map = map_frame,
977977 .unmap = unmap_frame,
978978 .discard = discard_frame,
979− });
979+ };
980+
981+ in->opaque = s;
982+ pl_queue_push(input->queue, &src);
980983
981984 if (!s->fps.num) {
982985 /* Internally queue an output frame for the same PTS */
983986 pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base);
984987 av_fifo_write(input->out_pts, &pts, 1);
988+
989+ if (s->send_fields && src.first_field != PL_FIELD_NONE) {
990+ /* Queue the second field for interlaced content */
991+ pts += av_rescale_q(in->duration, inlink->time_base, outlink->time_base) / 2;
992+ av_fifo_write(input->out_pts, &pts, 1);
993+ }
985994 }
986995 }
987996
@@ -1239,6 +1248,13 @@ static int libplacebo_config_output(AVFilterLink *outlink) · 251 unmodified lines
12391248 avctx->inputs[i]->time_base,
12401249 AV_TIME_BASE / 2, AV_TIME_BASE_Q);
12411250 }
1251+
1252+ if (s->deinterlace && s->send_fields) {
1253+ const AVRational q2 = { 2, 1 };
1254+ ol->frame_rate = av_mul_q(ol->frame_rate, q2);
1255+ /* Ensure output frame timestamps are divisible by two */
1256+ outlink->time_base = av_div_q(outlink->time_base, q2);
1257+ }
12421258 }
12431259
12441260 /* Static variables */
@@ -1373,6 +1389,7 @@ static const AVOption libplacebo_options[] = { · 128 unmodified lines
13731389 { "bob", "Naive bob deinterlacing", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BOB}, 0, 0, STATIC, .unit = "deinterlace" },
13741390 { "yadif", "Yet another deinterlacing filter", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_YADIF}, 0, 0, STATIC, .unit = "deinterlace" },
13751391 { "skip_spatial_check", "Skip yadif spatial check", OFFSET(skip_spatial_check), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1392+ { "send_fields", "Output a frame for each field", OFFSET(send_fields), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
13761393
13771394 { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
13781395 { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t