History

avfilter/f_interleave: add duration option

Paul B Mahol committed 6 years ago

Commit b29b9341 parent 6cfb33f2 files · +46 −12Browse files

Unified · Split

2 files
  1. doc/filters.texi +15 −0
  2. libavfilter/f_interleave.c +31 −12
doc/filters.texi+15−0
@@ -23316,6 +23316,21 @@ These filters accept the following options: · 23315 unmodified lines
2331623316 @table @option
2331723317 @item nb_inputs, n
2331823318 Set the number of different inputs, it is 2 by default.
23319+
23320+@item duration
23321+How to determine the end-of-stream.
23322+
23323+@table @option
23324+@item longest
23325+The duration of the longest input. (default)
23326+
23327+@item shortest
23328+The duration of the shortest input.
23329+
23330+@item first
23331+The duration of the first input.
23332+@end table
23333+
2331923334 @end table
2332023335
2332123336 @subsection Examples
libavfilter/f_interleave.c+31−12
@@ -37,15 +37,25 @@ · 36 unmodified lines
3737 typedef struct InterleaveContext {
3838 const AVClass *class;
3939 int nb_inputs;
40+ int duration_mode;
4041 int64_t pts;
4142 } InterleaveContext;
4243
44+#define DURATION_LONGEST 0
45+#define DURATION_SHORTEST 1
46+#define DURATION_FIRST 2
47+
4348 #define OFFSET(x) offsetof(InterleaveContext, x)
4449
4550 #define DEFINE_OPTIONS(filt_name, flags_) \
4651 static const AVOption filt_name##_options[] = { \
4752 { "nb_inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, .flags = flags_ }, \
4853 { "n", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, .flags = flags_ }, \
54+ { "duration", "how to determine the end-of-stream", \
55+ OFFSET(duration_mode), AV_OPT_TYPE_INT, { .i64 = DURATION_LONGEST }, 0, 2, flags_, "duration" }, \
56+ { "longest", "Duration of longest input", 0, AV_OPT_TYPE_CONST, { .i64 = DURATION_LONGEST }, 0, 0, flags_, "duration" }, \
57+ { "shortest", "Duration of shortest input", 0, AV_OPT_TYPE_CONST, { .i64 = DURATION_SHORTEST }, 0, 0, flags_, "duration" }, \
58+ { "first", "Duration of first input", 0, AV_OPT_TYPE_CONST, { .i64 = DURATION_FIRST }, 0, 0, flags_, "duration" }, \
4959 { NULL } \
5060 }
5161
@@ -54,21 +64,26 @@ static int activate(AVFilterContext *ctx) · 2 unmodified lines
5464 AVFilterLink *outlink = ctx->outputs[0];
5565 InterleaveContext *s = ctx->priv;
5666 int64_t q_pts, pts = INT64_MAX;
57− int i, nb_eofs = 0, input_idx = -1;
67+ int i, nb_eofs = 0, input_idx = -1, nb_active_inputs = 0;
68+ int nb_inputs_with_frames = 0;
5869
5970 FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
6071
6172 for (i = 0; i < ctx->nb_inputs; i++) {
62− if (!ff_outlink_get_status(ctx->inputs[i]) &&
63− !ff_inlink_queued_frames(ctx->inputs[i]))
64− break;
73+ if (!ff_outlink_get_status(ctx->inputs[i])) {
74+ nb_active_inputs++;
75+ if (!ff_inlink_queued_frames(ctx->inputs[i]))
76+ break;
77+ nb_inputs_with_frames++;
78+ }
6579 }
6680
67− if (i == ctx->nb_inputs) {
81+ if (nb_active_inputs > 0 && nb_active_inputs == nb_inputs_with_frames) {
6882 for (i = 0; i < ctx->nb_inputs; i++) {
6983 AVFrame *frame;
7084
71− if (ff_outlink_get_status(ctx->inputs[i]))
85+ if (ff_outlink_get_status(ctx->inputs[i]) ||
86+ ff_inlink_queued_frames(ctx->inputs[i]) == 0)
7287 continue;
7388
7489 frame = ff_inlink_peek_frame(ctx->inputs[i], 0);
@@ -104,6 +119,16 @@ static int activate(AVFilterContext *ctx) · 29 unmodified lines
104119 }
105120 }
106121
122+ for (i = 0; i < ctx->nb_inputs; i++)
123+ nb_eofs += !!ff_outlink_get_status(ctx->inputs[i]);
124+
125+ if ((nb_eofs > 0 && s->duration_mode == DURATION_SHORTEST) ||
126+ (nb_eofs == ctx->nb_inputs && s->duration_mode == DURATION_LONGEST) ||
127+ (ff_outlink_get_status(ctx->inputs[0]) && s->duration_mode == DURATION_FIRST)) {
128+ ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
129+ return 0;
130+ }
131+
107132 for (i = 0; i < ctx->nb_inputs; i++) {
108133 if (ff_inlink_queued_frames(ctx->inputs[i]))
109134 continue;
@@ -112,12 +137,6 @@ static int activate(AVFilterContext *ctx) · 2 unmodified lines
112137 ff_inlink_request_frame(ctx->inputs[i]);
113138 return 0;
114139 }
115− nb_eofs++;
116− }
117−
118− if (nb_eofs == ctx->nb_inputs) {
119− ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
120− return 0;
121140 }
122141
123142 return FFERROR_NOT_READY;

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