1 |
|
|
/* |
2 |
|
|
* Copyright (c) 2012 Nicolas George |
3 |
|
|
* |
4 |
|
|
* This file is part of FFmpeg. |
5 |
|
|
* |
6 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public |
8 |
|
|
* License as published by the Free Software Foundation; either |
9 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
14 |
|
|
* See the GNU Lesser General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
17 |
|
|
* along with FFmpeg; if not, write to the Free Software Foundation, Inc., |
18 |
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* @file |
23 |
|
|
* concat audio-video filter |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
#include "libavutil/avassert.h" |
27 |
|
|
#include "libavutil/avstring.h" |
28 |
|
|
#include "libavutil/channel_layout.h" |
29 |
|
|
#include "libavutil/opt.h" |
30 |
|
|
#include "avfilter.h" |
31 |
|
|
#include "filters.h" |
32 |
|
|
#include "internal.h" |
33 |
|
|
#include "video.h" |
34 |
|
|
#include "audio.h" |
35 |
|
|
|
36 |
|
|
#define TYPE_ALL 2 |
37 |
|
|
|
38 |
|
|
typedef struct ConcatContext { |
39 |
|
|
const AVClass *class; |
40 |
|
|
unsigned nb_streams[TYPE_ALL]; /**< number of out streams of each type */ |
41 |
|
|
unsigned nb_segments; |
42 |
|
|
unsigned cur_idx; /**< index of the first input of current segment */ |
43 |
|
|
int64_t delta_ts; /**< timestamp to add to produce output timestamps */ |
44 |
|
|
unsigned nb_in_active; /**< number of active inputs in current segment */ |
45 |
|
|
unsigned unsafe; |
46 |
|
|
struct concat_in { |
47 |
|
|
int64_t pts; |
48 |
|
|
int64_t nb_frames; |
49 |
|
|
unsigned eof; |
50 |
|
|
} *in; |
51 |
|
|
} ConcatContext; |
52 |
|
|
|
53 |
|
|
#define OFFSET(x) offsetof(ConcatContext, x) |
54 |
|
|
#define A AV_OPT_FLAG_AUDIO_PARAM |
55 |
|
|
#define F AV_OPT_FLAG_FILTERING_PARAM |
56 |
|
|
#define V AV_OPT_FLAG_VIDEO_PARAM |
57 |
|
|
|
58 |
|
|
static const AVOption concat_options[] = { |
59 |
|
|
{ "n", "specify the number of segments", OFFSET(nb_segments), |
60 |
|
|
AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, V|A|F}, |
61 |
|
|
{ "v", "specify the number of video streams", |
62 |
|
|
OFFSET(nb_streams[AVMEDIA_TYPE_VIDEO]), |
63 |
|
|
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, V|F }, |
64 |
|
|
{ "a", "specify the number of audio streams", |
65 |
|
|
OFFSET(nb_streams[AVMEDIA_TYPE_AUDIO]), |
66 |
|
|
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A|F}, |
67 |
|
|
{ "unsafe", "enable unsafe mode", |
68 |
|
|
OFFSET(unsafe), |
69 |
|
|
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, V|A|F}, |
70 |
|
|
{ NULL } |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
|
AVFILTER_DEFINE_CLASS(concat); |
74 |
|
|
|
75 |
|
3 |
static int query_formats(AVFilterContext *ctx) |
76 |
|
|
{ |
77 |
|
3 |
ConcatContext *cat = ctx->priv; |
78 |
|
3 |
unsigned type, nb_str, idx0 = 0, idx, str, seg; |
79 |
|
3 |
AVFilterFormats *formats, *rates = NULL; |
80 |
|
3 |
AVFilterChannelLayouts *layouts = NULL; |
81 |
|
|
int ret; |
82 |
|
|
|
83 |
✓✓ |
9 |
for (type = 0; type < TYPE_ALL; type++) { |
84 |
|
6 |
nb_str = cat->nb_streams[type]; |
85 |
✓✓ |
11 |
for (str = 0; str < nb_str; str++) { |
86 |
|
5 |
idx = idx0; |
87 |
|
|
|
88 |
|
|
/* Set the output formats */ |
89 |
|
5 |
formats = ff_all_formats(type); |
90 |
✗✓ |
5 |
if ((ret = ff_formats_ref(formats, &ctx->outputs[idx]->incfg.formats)) < 0) |
91 |
|
|
return ret; |
92 |
|
|
|
93 |
✓✓ |
5 |
if (type == AVMEDIA_TYPE_AUDIO) { |
94 |
|
2 |
rates = ff_all_samplerates(); |
95 |
✗✓ |
2 |
if ((ret = ff_formats_ref(rates, &ctx->outputs[idx]->incfg.samplerates)) < 0) |
96 |
|
|
return ret; |
97 |
|
2 |
layouts = ff_all_channel_layouts(); |
98 |
✗✓ |
2 |
if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->incfg.channel_layouts)) < 0) |
99 |
|
|
return ret; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
/* Set the same formats for each corresponding input */ |
103 |
✓✓ |
19 |
for (seg = 0; seg < cat->nb_segments; seg++) { |
104 |
✗✓ |
14 |
if ((ret = ff_formats_ref(formats, &ctx->inputs[idx]->outcfg.formats)) < 0) |
105 |
|
|
return ret; |
106 |
✓✓ |
14 |
if (type == AVMEDIA_TYPE_AUDIO) { |
107 |
✓✗✗✓
|
12 |
if ((ret = ff_formats_ref(rates, &ctx->inputs[idx]->outcfg.samplerates)) < 0 || |
108 |
|
6 |
(ret = ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->outcfg.channel_layouts)) < 0) |
109 |
|
|
return ret; |
110 |
|
|
} |
111 |
|
14 |
idx += ctx->nb_outputs; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
5 |
idx0++; |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
3 |
return 0; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
5 |
static int config_output(AVFilterLink *outlink) |
121 |
|
|
{ |
122 |
|
5 |
AVFilterContext *ctx = outlink->src; |
123 |
|
5 |
ConcatContext *cat = ctx->priv; |
124 |
|
5 |
unsigned out_no = FF_OUTLINK_IDX(outlink); |
125 |
|
5 |
unsigned in_no = out_no, seg; |
126 |
|
5 |
AVFilterLink *inlink = ctx->inputs[in_no]; |
127 |
|
|
|
128 |
|
|
/* enhancement: find a common one */ |
129 |
|
5 |
outlink->time_base = AV_TIME_BASE_Q; |
130 |
|
5 |
outlink->w = inlink->w; |
131 |
|
5 |
outlink->h = inlink->h; |
132 |
|
5 |
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; |
133 |
|
5 |
outlink->format = inlink->format; |
134 |
|
5 |
outlink->frame_rate = inlink->frame_rate; |
135 |
|
|
|
136 |
✓✓ |
12 |
for (seg = 1; seg < cat->nb_segments; seg++) { |
137 |
|
8 |
inlink = ctx->inputs[in_no + seg * ctx->nb_outputs]; |
138 |
✓✓ |
8 |
if (outlink->frame_rate.num != inlink->frame_rate.num || |
139 |
✗✓ |
7 |
outlink->frame_rate.den != inlink->frame_rate.den) { |
140 |
|
1 |
av_log(ctx, AV_LOG_VERBOSE, |
141 |
|
|
"Video inputs have different frame rates, output will be VFR\n"); |
142 |
|
1 |
outlink->frame_rate = av_make_q(1, 0); |
143 |
|
1 |
break; |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
|
147 |
✓✓ |
14 |
for (seg = 1; seg < cat->nb_segments; seg++) { |
148 |
|
9 |
inlink = ctx->inputs[in_no + seg * ctx->nb_outputs]; |
149 |
✓✓ |
9 |
if (!outlink->sample_aspect_ratio.num) |
150 |
|
4 |
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; |
151 |
|
|
/* possible enhancement: unsafe mode, do not check */ |
152 |
✓✓ |
9 |
if (outlink->w != inlink->w || |
153 |
✓✗ |
8 |
outlink->h != inlink->h || |
154 |
✗✓ |
8 |
outlink->sample_aspect_ratio.num != inlink->sample_aspect_ratio.num && |
155 |
|
|
inlink->sample_aspect_ratio.num || |
156 |
✗✓ |
8 |
outlink->sample_aspect_ratio.den != inlink->sample_aspect_ratio.den) { |
157 |
|
1 |
av_log(ctx, AV_LOG_ERROR, "Input link %s parameters " |
158 |
|
|
"(size %dx%d, SAR %d:%d) do not match the corresponding " |
159 |
|
|
"output link %s parameters (%dx%d, SAR %d:%d)\n", |
160 |
|
1 |
ctx->input_pads[in_no].name, inlink->w, inlink->h, |
161 |
|
|
inlink->sample_aspect_ratio.num, |
162 |
|
|
inlink->sample_aspect_ratio.den, |
163 |
|
1 |
ctx->input_pads[out_no].name, outlink->w, outlink->h, |
164 |
|
|
outlink->sample_aspect_ratio.num, |
165 |
|
|
outlink->sample_aspect_ratio.den); |
166 |
✗✓ |
1 |
if (!cat->unsafe) |
167 |
|
|
return AVERROR(EINVAL); |
168 |
|
|
} |
169 |
|
|
} |
170 |
|
|
|
171 |
|
5 |
return 0; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
413 |
static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf) |
175 |
|
|
{ |
176 |
|
413 |
ConcatContext *cat = ctx->priv; |
177 |
|
413 |
unsigned out_no = in_no % ctx->nb_outputs; |
178 |
|
413 |
AVFilterLink * inlink = ctx-> inputs[ in_no]; |
179 |
|
413 |
AVFilterLink *outlink = ctx->outputs[out_no]; |
180 |
|
413 |
struct concat_in *in = &cat->in[in_no]; |
181 |
|
|
|
182 |
|
413 |
buf->pts = av_rescale_q(buf->pts, inlink->time_base, outlink->time_base); |
183 |
|
413 |
in->pts = buf->pts; |
184 |
|
413 |
in->nb_frames++; |
185 |
|
|
/* add duration to input PTS */ |
186 |
✓✓ |
413 |
if (inlink->sample_rate) |
187 |
|
|
/* use number of audio samples */ |
188 |
|
350 |
in->pts += av_rescale_q(buf->nb_samples, |
189 |
|
|
av_make_q(1, inlink->sample_rate), |
190 |
|
|
outlink->time_base); |
191 |
✓✓ |
63 |
else if (in->nb_frames >= 2) |
192 |
|
|
/* use mean duration */ |
193 |
|
55 |
in->pts = av_rescale(in->pts, in->nb_frames, in->nb_frames - 1); |
194 |
|
|
|
195 |
|
413 |
buf->pts += cat->delta_ts; |
196 |
|
413 |
return ff_filter_frame(outlink, buf); |
197 |
|
|
} |
198 |
|
|
|
199 |
|
63 |
static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h) |
200 |
|
|
{ |
201 |
|
63 |
AVFilterContext *ctx = inlink->dst; |
202 |
|
63 |
unsigned in_no = FF_INLINK_IDX(inlink); |
203 |
|
63 |
AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs]; |
204 |
|
|
|
205 |
|
63 |
return ff_get_video_buffer(outlink, w, h); |
206 |
|
|
} |
207 |
|
|
|
208 |
|
350 |
static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples) |
209 |
|
|
{ |
210 |
|
350 |
AVFilterContext *ctx = inlink->dst; |
211 |
|
350 |
unsigned in_no = FF_INLINK_IDX(inlink); |
212 |
|
350 |
AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs]; |
213 |
|
|
|
214 |
|
350 |
return ff_get_audio_buffer(outlink, nb_samples); |
215 |
|
|
} |
216 |
|
|
|
217 |
|
14 |
static void close_input(AVFilterContext *ctx, unsigned in_no) |
218 |
|
|
{ |
219 |
|
14 |
ConcatContext *cat = ctx->priv; |
220 |
|
|
|
221 |
|
14 |
cat->in[in_no].eof = 1; |
222 |
|
14 |
cat->nb_in_active--; |
223 |
|
14 |
av_log(ctx, AV_LOG_VERBOSE, "EOF on %s, %d streams left in segment.\n", |
224 |
|
14 |
ctx->input_pads[in_no].name, cat->nb_in_active); |
225 |
|
14 |
} |
226 |
|
|
|
227 |
|
8 |
static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta) |
228 |
|
|
{ |
229 |
|
8 |
ConcatContext *cat = ctx->priv; |
230 |
|
8 |
unsigned i = cat->cur_idx; |
231 |
|
8 |
unsigned imax = i + ctx->nb_outputs; |
232 |
|
|
int64_t pts; |
233 |
|
|
|
234 |
|
8 |
pts = cat->in[i++].pts; |
235 |
✓✓ |
14 |
for (; i < imax; i++) |
236 |
|
6 |
pts = FFMAX(pts, cat->in[i].pts); |
237 |
|
8 |
cat->delta_ts += pts; |
238 |
|
8 |
*seg_delta = pts; |
239 |
|
8 |
} |
240 |
|
|
|
241 |
|
4 |
static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no, |
242 |
|
|
int64_t seg_delta) |
243 |
|
|
{ |
244 |
|
4 |
ConcatContext *cat = ctx->priv; |
245 |
|
4 |
AVFilterLink *outlink = ctx->outputs[out_no]; |
246 |
|
4 |
int64_t base_pts = cat->in[in_no].pts + cat->delta_ts - seg_delta; |
247 |
|
4 |
int64_t nb_samples, sent = 0; |
248 |
|
|
int frame_nb_samples, ret; |
249 |
|
4 |
AVRational rate_tb = { 1, ctx->inputs[in_no]->sample_rate }; |
250 |
|
|
AVFrame *buf; |
251 |
|
|
|
252 |
✗✓ |
4 |
if (!rate_tb.den) |
253 |
|
|
return AVERROR_BUG; |
254 |
✗✓ |
4 |
if (cat->in[in_no].pts < INT64_MIN + seg_delta) |
255 |
|
|
return AVERROR_INVALIDDATA; |
256 |
✗✓ |
4 |
if (seg_delta < cat->in[in_no].pts) |
257 |
|
|
return AVERROR_INVALIDDATA; |
258 |
|
4 |
nb_samples = av_rescale_q(seg_delta - cat->in[in_no].pts, |
259 |
|
|
outlink->time_base, rate_tb); |
260 |
✗✓ |
4 |
frame_nb_samples = FFMAX(9600, rate_tb.den / 5); /* arbitrary */ |
261 |
✓✓ |
14 |
while (nb_samples) { |
262 |
|
10 |
frame_nb_samples = FFMIN(frame_nb_samples, nb_samples); |
263 |
|
10 |
buf = ff_get_audio_buffer(outlink, frame_nb_samples); |
264 |
✗✓ |
10 |
if (!buf) |
265 |
|
|
return AVERROR(ENOMEM); |
266 |
|
10 |
av_samples_set_silence(buf->extended_data, 0, frame_nb_samples, |
267 |
|
10 |
outlink->channels, outlink->format); |
268 |
|
10 |
buf->pts = base_pts + av_rescale_q(sent, rate_tb, outlink->time_base); |
269 |
|
10 |
ret = ff_filter_frame(outlink, buf); |
270 |
✗✓ |
10 |
if (ret < 0) |
271 |
|
|
return ret; |
272 |
|
10 |
sent += frame_nb_samples; |
273 |
|
10 |
nb_samples -= frame_nb_samples; |
274 |
|
|
} |
275 |
|
4 |
return 0; |
276 |
|
|
} |
277 |
|
|
|
278 |
|
8 |
static int flush_segment(AVFilterContext *ctx) |
279 |
|
|
{ |
280 |
|
|
int ret; |
281 |
|
8 |
ConcatContext *cat = ctx->priv; |
282 |
|
|
unsigned str, str_max; |
283 |
|
|
int64_t seg_delta; |
284 |
|
|
|
285 |
|
8 |
find_next_delta_ts(ctx, &seg_delta); |
286 |
|
8 |
cat->cur_idx += ctx->nb_outputs; |
287 |
|
8 |
cat->nb_in_active = ctx->nb_outputs; |
288 |
|
8 |
av_log(ctx, AV_LOG_VERBOSE, "Segment finished at pts=%"PRId64"\n", |
289 |
|
|
cat->delta_ts); |
290 |
|
|
|
291 |
✓✓ |
8 |
if (cat->cur_idx < ctx->nb_inputs) { |
292 |
|
|
/* pad audio streams with silence */ |
293 |
|
5 |
str = cat->nb_streams[AVMEDIA_TYPE_VIDEO]; |
294 |
|
5 |
str_max = str + cat->nb_streams[AVMEDIA_TYPE_AUDIO]; |
295 |
✓✓ |
9 |
for (; str < str_max; str++) { |
296 |
|
4 |
ret = send_silence(ctx, cat->cur_idx - ctx->nb_outputs + str, str, |
297 |
|
|
seg_delta); |
298 |
✗✓ |
4 |
if (ret < 0) |
299 |
|
|
return ret; |
300 |
|
|
} |
301 |
|
|
} |
302 |
|
8 |
return 0; |
303 |
|
|
} |
304 |
|
|
|
305 |
|
5 |
static av_cold int init(AVFilterContext *ctx) |
306 |
|
|
{ |
307 |
|
5 |
ConcatContext *cat = ctx->priv; |
308 |
|
|
unsigned seg, type, str; |
309 |
|
|
int ret; |
310 |
|
|
|
311 |
|
|
/* create input pads */ |
312 |
✓✓ |
19 |
for (seg = 0; seg < cat->nb_segments; seg++) { |
313 |
✓✓ |
42 |
for (type = 0; type < TYPE_ALL; type++) { |
314 |
✓✓ |
54 |
for (str = 0; str < cat->nb_streams[type]; str++) { |
315 |
|
26 |
AVFilterPad pad = { |
316 |
|
|
.type = type, |
317 |
|
|
.get_video_buffer = get_video_buffer, |
318 |
|
|
.get_audio_buffer = get_audio_buffer, |
319 |
|
|
}; |
320 |
|
26 |
pad.name = av_asprintf("in%d:%c%d", seg, "va"[type], str); |
321 |
✗✓ |
26 |
if ((ret = ff_insert_inpad(ctx, ctx->nb_inputs, &pad)) < 0) { |
322 |
|
|
av_freep(&pad.name); |
323 |
|
|
return ret; |
324 |
|
|
} |
325 |
|
|
} |
326 |
|
|
} |
327 |
|
|
} |
328 |
|
|
/* create output pads */ |
329 |
✓✓ |
15 |
for (type = 0; type < TYPE_ALL; type++) { |
330 |
✓✓ |
19 |
for (str = 0; str < cat->nb_streams[type]; str++) { |
331 |
|
9 |
AVFilterPad pad = { |
332 |
|
|
.type = type, |
333 |
|
|
.config_props = config_output, |
334 |
|
|
}; |
335 |
|
9 |
pad.name = av_asprintf("out:%c%d", "va"[type], str); |
336 |
✗✓ |
9 |
if ((ret = ff_insert_outpad(ctx, ctx->nb_outputs, &pad)) < 0) { |
337 |
|
|
av_freep(&pad.name); |
338 |
|
|
return ret; |
339 |
|
|
} |
340 |
|
|
} |
341 |
|
|
} |
342 |
|
|
|
343 |
|
5 |
cat->in = av_calloc(ctx->nb_inputs, sizeof(*cat->in)); |
344 |
✗✓ |
5 |
if (!cat->in) |
345 |
|
|
return AVERROR(ENOMEM); |
346 |
|
5 |
cat->nb_in_active = ctx->nb_outputs; |
347 |
|
5 |
return 0; |
348 |
|
|
} |
349 |
|
|
|
350 |
|
5 |
static av_cold void uninit(AVFilterContext *ctx) |
351 |
|
|
{ |
352 |
|
5 |
ConcatContext *cat = ctx->priv; |
353 |
|
|
unsigned i; |
354 |
|
|
|
355 |
✓✓ |
31 |
for (i = 0; i < ctx->nb_inputs; i++) |
356 |
|
26 |
av_freep(&ctx->input_pads[i].name); |
357 |
✓✓ |
14 |
for (i = 0; i < ctx->nb_outputs; i++) |
358 |
|
9 |
av_freep(&ctx->output_pads[i].name); |
359 |
|
5 |
av_freep(&cat->in); |
360 |
|
5 |
} |
361 |
|
|
|
362 |
|
854 |
static int activate(AVFilterContext *ctx) |
363 |
|
|
{ |
364 |
|
854 |
ConcatContext *cat = ctx->priv; |
365 |
|
|
AVFrame *frame; |
366 |
|
|
unsigned i, j; |
367 |
|
|
int ret, status; |
368 |
|
|
int64_t pts; |
369 |
|
|
|
370 |
|
|
/* Forward status back */ |
371 |
✓✓ |
2538 |
for (i = 0; i < ctx->nb_outputs; i++) { |
372 |
|
1684 |
status = ff_outlink_get_status(ctx->outputs[i]); |
373 |
✓✓ |
1684 |
if (!status) |
374 |
|
1654 |
continue; |
375 |
✓✓ |
120 |
for (j = i; j < ctx->nb_inputs; j += ctx->nb_outputs) { |
376 |
✗✓ |
90 |
if (!cat->in[j].eof) { |
377 |
|
|
cat->in[j].eof = 1; |
378 |
|
|
ff_inlink_set_status(ctx->inputs[j], status); |
379 |
|
|
return 0; |
380 |
|
|
} |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
} |
384 |
|
|
|
385 |
|
|
/* Forward available frames */ |
386 |
✓✗ |
854 |
if (cat->cur_idx < ctx->nb_inputs) { |
387 |
✓✓ |
2072 |
for (i = 0; i < ctx->nb_outputs; i++) { |
388 |
|
1631 |
ret = ff_inlink_consume_frame(ctx->inputs[cat->cur_idx + i], &frame); |
389 |
✗✓ |
1631 |
if (ret < 0) |
390 |
|
|
return ret; |
391 |
✓✓ |
1631 |
if (ret) { |
392 |
|
413 |
ff_filter_set_ready(ctx, 10); |
393 |
|
413 |
return push_frame(ctx, cat->cur_idx + i, frame); |
394 |
|
|
} |
395 |
|
|
} |
396 |
|
|
} |
397 |
|
|
|
398 |
|
|
/* Forward status change */ |
399 |
✓✗ |
441 |
if (cat->cur_idx < ctx->nb_inputs) { |
400 |
✓✓ |
1289 |
for (i = 0; i < ctx->nb_outputs; i++) { |
401 |
|
862 |
ret = ff_inlink_acknowledge_status(ctx->inputs[cat->cur_idx + i], &status, &pts); |
402 |
|
|
/* TODO use pts */ |
403 |
✓✓ |
862 |
if (ret > 0) { |
404 |
|
14 |
close_input(ctx, cat->cur_idx + i); |
405 |
✓✓ |
14 |
if (cat->cur_idx + ctx->nb_outputs >= ctx->nb_inputs) { |
406 |
|
5 |
ff_outlink_set_status(ctx->outputs[i], status, pts); |
407 |
|
|
} |
408 |
✓✓ |
14 |
if (!cat->nb_in_active) { |
409 |
|
8 |
ret = flush_segment(ctx); |
410 |
✗✓ |
8 |
if (ret < 0) |
411 |
|
|
return ret; |
412 |
|
|
} |
413 |
|
14 |
ff_filter_set_ready(ctx, 10); |
414 |
|
14 |
return 0; |
415 |
|
|
} |
416 |
|
|
} |
417 |
|
|
} |
418 |
|
|
|
419 |
|
427 |
ret = FFERROR_NOT_READY; |
420 |
✓✓ |
1063 |
for (i = 0; i < ctx->nb_outputs; i++) { |
421 |
✓✓ |
744 |
if (ff_outlink_frame_wanted(ctx->outputs[i])) { |
422 |
✓✓ |
427 |
if (cat->in[cat->cur_idx + i].eof) { |
423 |
✓✓ |
324 |
for (j = 0; j < ctx->nb_outputs; j++) |
424 |
✓✓ |
216 |
if (!cat->in[cat->cur_idx + j].eof) |
425 |
|
108 |
ff_inlink_request_frame(ctx->inputs[cat->cur_idx + j]); |
426 |
|
108 |
return 0; |
427 |
|
|
} else { |
428 |
|
319 |
ff_inlink_request_frame(ctx->inputs[cat->cur_idx + i]); |
429 |
|
319 |
ret = 0; |
430 |
|
|
} |
431 |
|
|
} |
432 |
|
|
} |
433 |
|
|
|
434 |
|
319 |
return ret; |
435 |
|
|
} |
436 |
|
|
|
437 |
|
|
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, |
438 |
|
|
char *res, int res_len, int flags) |
439 |
|
|
{ |
440 |
|
|
int ret = AVERROR(ENOSYS); |
441 |
|
|
|
442 |
|
|
if (!strcmp(cmd, "next")) { |
443 |
|
|
av_log(ctx, AV_LOG_VERBOSE, "Command received: next\n"); |
444 |
|
|
return flush_segment(ctx); |
445 |
|
|
} |
446 |
|
|
|
447 |
|
|
return ret; |
448 |
|
|
} |
449 |
|
|
|
450 |
|
|
AVFilter ff_avf_concat = { |
451 |
|
|
.name = "concat", |
452 |
|
|
.description = NULL_IF_CONFIG_SMALL("Concatenate audio and video streams."), |
453 |
|
|
.init = init, |
454 |
|
|
.uninit = uninit, |
455 |
|
|
.query_formats = query_formats, |
456 |
|
|
.activate = activate, |
457 |
|
|
.priv_size = sizeof(ConcatContext), |
458 |
|
|
.inputs = NULL, |
459 |
|
|
.outputs = NULL, |
460 |
|
|
.priv_class = &concat_class, |
461 |
|
|
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_DYNAMIC_OUTPUTS, |
462 |
|
|
.process_command = process_command, |
463 |
|
|
}; |