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
23316@table @option23316@table @option
23317@item nb_inputs, n23317@item nb_inputs, n
23318Set the number of different inputs, it is 2 by default.23318Set the number of different inputs, it is 2 by default.
23319
23320@item duration
23321How to determine the end-of-stream.
23322
23323@table @option
23324@item longest
23325The duration of the longest input. (default)
23326
23327@item shortest
23328The duration of the shortest input.
23329
23330@item first
23331The duration of the first input.
23332@end table
23333
23319@end table23334@end table
23320 23335
23321@subsection Examples23336@subsection Examples
libavfilter/f_interleave.c+31−12
@@ -37,15 +37,25 @@ · 36 unmodified lines
37typedef struct InterleaveContext {37typedef struct InterleaveContext {
38 const AVClass *class;38 const AVClass *class;
39 int nb_inputs;39 int nb_inputs;
40 int duration_mode;
40 int64_t pts;41 int64_t pts;
41} InterleaveContext;42} InterleaveContext;
42 43
44#define DURATION_LONGEST 0
45#define DURATION_SHORTEST 1
46#define DURATION_FIRST 2
47
43#define OFFSET(x) offsetof(InterleaveContext, x)48#define OFFSET(x) offsetof(InterleaveContext, x)
44 49
45#define DEFINE_OPTIONS(filt_name, flags_) \50#define DEFINE_OPTIONS(filt_name, flags_) \
46static const AVOption filt_name##_options[] = { \51static const AVOption filt_name##_options[] = { \
47 { "nb_inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, .flags = flags_ }, \52 { "nb_inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, .flags = flags_ }, \
48 { "n", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, .flags = flags_ }, \53 { "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" }, \
49 { NULL } \59 { NULL } \
50}60}
51 61
@@ -54,21 +64,26 @@ static int activate(AVFilterContext *ctx) · 2 unmodified lines
54 AVFilterLink *outlink = ctx->outputs[0];64 AVFilterLink *outlink = ctx->outputs[0];
55 InterleaveContext *s = ctx->priv;65 InterleaveContext *s = ctx->priv;
56 int64_t q_pts, pts = INT64_MAX;66 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;
58 69
59 FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);70 FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
60 71
61 for (i = 0; i < ctx->nb_inputs; i++) {72 for (i = 0; i < ctx->nb_inputs; i++) {
62 if (!ff_outlink_get_status(ctx->inputs[i]) &&73 if (!ff_outlink_get_status(ctx->inputs[i])) {
63 !ff_inlink_queued_frames(ctx->inputs[i]))74 nb_active_inputs++;
64 break;75 if (!ff_inlink_queued_frames(ctx->inputs[i]))
76 break;
77 nb_inputs_with_frames++;
78 }
65 }79 }
66 80
67 if (i == ctx->nb_inputs) {81 if (nb_active_inputs > 0 && nb_active_inputs == nb_inputs_with_frames) {
68 for (i = 0; i < ctx->nb_inputs; i++) {82 for (i = 0; i < ctx->nb_inputs; i++) {
69 AVFrame *frame;83 AVFrame *frame;
70 84
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)
72 continue;87 continue;
73 88
74 frame = ff_inlink_peek_frame(ctx->inputs[i], 0);89 frame = ff_inlink_peek_frame(ctx->inputs[i], 0);
@@ -104,6 +119,16 @@ static int activate(AVFilterContext *ctx) · 29 unmodified lines
104 }119 }
105 }120 }
106 121
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
107 for (i = 0; i < ctx->nb_inputs; i++) {132 for (i = 0; i < ctx->nb_inputs; i++) {
108 if (ff_inlink_queued_frames(ctx->inputs[i]))133 if (ff_inlink_queued_frames(ctx->inputs[i]))
109 continue;134 continue;
@@ -112,12 +137,6 @@ static int activate(AVFilterContext *ctx) · 2 unmodified lines
112 ff_inlink_request_frame(ctx->inputs[i]);137 ff_inlink_request_frame(ctx->inputs[i]);
113 return 0;138 return 0;
114 }139 }
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;
121 }140 }
122 141
123 return FFERROR_NOT_READY;142 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