2012-07-17 01:05:05 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Nicolas George
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* concat audio-video filter
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/avassert.h"
|
2012-11-29 12:25:02 +01:00
|
|
|
#include "libavutil/avstring.h"
|
2012-11-13 14:16:48 +01:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-07-17 01:05:05 +02:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "avfilter.h"
|
|
|
|
#define FF_BUFQUEUE_SIZE 256
|
|
|
|
#include "bufferqueue.h"
|
|
|
|
#include "internal.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "audio.h"
|
|
|
|
|
|
|
|
#define TYPE_ALL 2
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const AVClass *class;
|
|
|
|
unsigned nb_streams[TYPE_ALL]; /**< number of out streams of each type */
|
|
|
|
unsigned nb_segments;
|
|
|
|
unsigned cur_idx; /**< index of the first input of current segment */
|
|
|
|
int64_t delta_ts; /**< timestamp to add to produce output timestamps */
|
|
|
|
unsigned nb_in_active; /**< number of active inputs in current segment */
|
2012-10-25 21:27:41 +02:00
|
|
|
unsigned unsafe;
|
2012-07-17 01:05:05 +02:00
|
|
|
struct concat_in {
|
|
|
|
int64_t pts;
|
|
|
|
int64_t nb_frames;
|
|
|
|
unsigned eof;
|
|
|
|
struct FFBufQueue queue;
|
|
|
|
} *in;
|
|
|
|
} ConcatContext;
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(ConcatContext, x)
|
2012-08-13 13:40:01 +02:00
|
|
|
#define A AV_OPT_FLAG_AUDIO_PARAM
|
|
|
|
#define F AV_OPT_FLAG_FILTERING_PARAM
|
|
|
|
#define V AV_OPT_FLAG_VIDEO_PARAM
|
2012-07-17 01:05:05 +02:00
|
|
|
|
|
|
|
static const AVOption concat_options[] = {
|
|
|
|
{ "n", "specify the number of segments", OFFSET(nb_segments),
|
2014-10-21 11:45:30 +02:00
|
|
|
AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, V|A|F},
|
2012-07-17 01:05:05 +02:00
|
|
|
{ "v", "specify the number of video streams",
|
|
|
|
OFFSET(nb_streams[AVMEDIA_TYPE_VIDEO]),
|
2012-09-05 14:26:01 +02:00
|
|
|
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, V|F },
|
2012-07-17 01:05:05 +02:00
|
|
|
{ "a", "specify the number of audio streams",
|
|
|
|
OFFSET(nb_streams[AVMEDIA_TYPE_AUDIO]),
|
2012-09-05 14:26:01 +02:00
|
|
|
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A|F},
|
2012-10-25 21:27:41 +02:00
|
|
|
{ "unsafe", "enable unsafe mode",
|
|
|
|
OFFSET(unsafe),
|
2015-09-08 23:24:12 +02:00
|
|
|
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, V|A|F},
|
2013-09-07 14:13:50 +02:00
|
|
|
{ NULL }
|
2012-07-17 01:05:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(concat);
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned type, nb_str, idx0 = 0, idx, str, seg;
|
2012-12-29 03:20:37 +01:00
|
|
|
AVFilterFormats *formats, *rates = NULL;
|
|
|
|
AVFilterChannelLayouts *layouts = NULL;
|
2015-10-05 05:39:25 +02:00
|
|
|
int ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
|
|
|
|
for (type = 0; type < TYPE_ALL; type++) {
|
|
|
|
nb_str = cat->nb_streams[type];
|
|
|
|
for (str = 0; str < nb_str; str++) {
|
|
|
|
idx = idx0;
|
|
|
|
|
|
|
|
/* Set the output formats */
|
|
|
|
formats = ff_all_formats(type);
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_formats_ref(formats, &ctx->outputs[idx]->in_formats)) < 0)
|
|
|
|
return ret;
|
|
|
|
|
2012-07-17 01:05:05 +02:00
|
|
|
if (type == AVMEDIA_TYPE_AUDIO) {
|
|
|
|
rates = ff_all_samplerates();
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_formats_ref(rates, &ctx->outputs[idx]->in_samplerates)) < 0)
|
|
|
|
return ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
layouts = ff_all_channel_layouts();
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->in_channel_layouts)) < 0)
|
|
|
|
return ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the same formats for each corresponding input */
|
|
|
|
for (seg = 0; seg < cat->nb_segments; seg++) {
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_formats_ref(formats, &ctx->inputs[idx]->out_formats)) < 0)
|
|
|
|
return ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
if (type == AVMEDIA_TYPE_AUDIO) {
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_formats_ref(rates, &ctx->inputs[idx]->out_samplerates)) < 0 ||
|
|
|
|
(ret = ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->out_channel_layouts)) < 0)
|
|
|
|
return ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
idx += ctx->nb_outputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx0++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_output(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned out_no = FF_OUTLINK_IDX(outlink);
|
|
|
|
unsigned in_no = out_no, seg;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[in_no];
|
|
|
|
|
|
|
|
/* enhancement: find a common one */
|
|
|
|
outlink->time_base = AV_TIME_BASE_Q;
|
|
|
|
outlink->w = inlink->w;
|
|
|
|
outlink->h = inlink->h;
|
|
|
|
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
|
|
|
|
outlink->format = inlink->format;
|
|
|
|
for (seg = 1; seg < cat->nb_segments; seg++) {
|
|
|
|
inlink = ctx->inputs[in_no += ctx->nb_outputs];
|
2013-07-18 10:55:52 +02:00
|
|
|
if (!outlink->sample_aspect_ratio.num)
|
|
|
|
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
|
2012-07-17 01:05:05 +02:00
|
|
|
/* possible enhancement: unsafe mode, do not check */
|
|
|
|
if (outlink->w != inlink->w ||
|
|
|
|
outlink->h != inlink->h ||
|
2013-07-18 10:55:52 +02:00
|
|
|
outlink->sample_aspect_ratio.num != inlink->sample_aspect_ratio.num &&
|
|
|
|
inlink->sample_aspect_ratio.num ||
|
2012-07-17 01:05:05 +02:00
|
|
|
outlink->sample_aspect_ratio.den != inlink->sample_aspect_ratio.den) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Input link %s parameters "
|
|
|
|
"(size %dx%d, SAR %d:%d) do not match the corresponding "
|
|
|
|
"output link %s parameters (%dx%d, SAR %d:%d)\n",
|
|
|
|
ctx->input_pads[in_no].name, inlink->w, inlink->h,
|
|
|
|
inlink->sample_aspect_ratio.num,
|
|
|
|
inlink->sample_aspect_ratio.den,
|
|
|
|
ctx->input_pads[out_no].name, outlink->w, outlink->h,
|
|
|
|
outlink->sample_aspect_ratio.num,
|
|
|
|
outlink->sample_aspect_ratio.den);
|
2012-10-25 21:27:41 +02:00
|
|
|
if (!cat->unsafe)
|
|
|
|
return AVERROR(EINVAL);
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:56:18 +01:00
|
|
|
static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned out_no = in_no % ctx->nb_outputs;
|
|
|
|
AVFilterLink * inlink = ctx-> inputs[ in_no];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[out_no];
|
|
|
|
struct concat_in *in = &cat->in[in_no];
|
|
|
|
|
|
|
|
buf->pts = av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);
|
|
|
|
in->pts = buf->pts;
|
|
|
|
in->nb_frames++;
|
|
|
|
/* add duration to input PTS */
|
|
|
|
if (inlink->sample_rate)
|
|
|
|
/* use number of audio samples */
|
2013-03-10 01:30:30 +01:00
|
|
|
in->pts += av_rescale_q(buf->nb_samples,
|
2013-12-31 15:55:44 +01:00
|
|
|
av_make_q(1, inlink->sample_rate),
|
2012-07-17 01:05:05 +02:00
|
|
|
outlink->time_base);
|
|
|
|
else if (in->nb_frames >= 2)
|
|
|
|
/* use mean duration */
|
|
|
|
in->pts = av_rescale(in->pts, in->nb_frames, in->nb_frames - 1);
|
|
|
|
|
|
|
|
buf->pts += cat->delta_ts;
|
2013-03-13 09:56:18 +01:00
|
|
|
return ff_filter_frame(outlink, buf);
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:56:18 +01:00
|
|
|
static int process_frame(AVFilterLink *inlink, AVFrame *buf)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned in_no = FF_INLINK_IDX(inlink);
|
|
|
|
|
|
|
|
if (in_no < cat->cur_idx) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Frame after EOF on input %s\n",
|
|
|
|
ctx->input_pads[in_no].name);
|
2013-03-10 01:30:30 +01:00
|
|
|
av_frame_free(&buf);
|
2012-10-17 19:54:22 +02:00
|
|
|
} else if (in_no >= cat->cur_idx + ctx->nb_outputs) {
|
2012-07-17 01:05:05 +02:00
|
|
|
ff_bufqueue_add(ctx, &cat->in[in_no].queue, buf);
|
|
|
|
} else {
|
2013-03-13 09:56:18 +01:00
|
|
|
return push_frame(ctx, in_no, buf);
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
2013-03-13 09:56:18 +01:00
|
|
|
return 0;
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
unsigned in_no = FF_INLINK_IDX(inlink);
|
|
|
|
AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
|
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
return ff_get_video_buffer(outlink, w, h);
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
unsigned in_no = FF_INLINK_IDX(inlink);
|
|
|
|
AVFilterLink *outlink = ctx->outputs[in_no % ctx->nb_outputs];
|
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
return ff_get_audio_buffer(outlink, nb_samples);
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
2013-03-13 09:56:18 +01:00
|
|
|
return process_frame(inlink, buf);
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void close_input(AVFilterContext *ctx, unsigned in_no)
|
|
|
|
{
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
|
|
|
|
cat->in[in_no].eof = 1;
|
|
|
|
cat->nb_in_active--;
|
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "EOF on %s, %d streams left in segment.\n",
|
|
|
|
ctx->input_pads[in_no].name, cat->nb_in_active);
|
|
|
|
}
|
|
|
|
|
2013-03-16 12:21:14 +01:00
|
|
|
static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned i = cat->cur_idx;
|
|
|
|
unsigned imax = i + ctx->nb_outputs;
|
|
|
|
int64_t pts;
|
|
|
|
|
|
|
|
pts = cat->in[i++].pts;
|
|
|
|
for (; i < imax; i++)
|
|
|
|
pts = FFMAX(pts, cat->in[i].pts);
|
|
|
|
cat->delta_ts += pts;
|
2013-03-16 12:21:14 +01:00
|
|
|
*seg_delta = pts;
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-16 12:21:14 +01:00
|
|
|
static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no,
|
|
|
|
int64_t seg_delta)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
AVFilterLink *outlink = ctx->outputs[out_no];
|
2013-03-16 12:21:14 +01:00
|
|
|
int64_t base_pts = cat->in[in_no].pts + cat->delta_ts - seg_delta;
|
2012-07-17 01:05:05 +02:00
|
|
|
int64_t nb_samples, sent = 0;
|
2013-03-13 09:56:18 +01:00
|
|
|
int frame_nb_samples, ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
AVRational rate_tb = { 1, ctx->inputs[in_no]->sample_rate };
|
2013-03-10 01:30:30 +01:00
|
|
|
AVFrame *buf;
|
2012-07-17 01:05:05 +02:00
|
|
|
int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
|
|
|
|
|
|
|
|
if (!rate_tb.den)
|
2013-03-13 09:56:18 +01:00
|
|
|
return AVERROR_BUG;
|
2013-03-16 12:21:14 +01:00
|
|
|
nb_samples = av_rescale_q(seg_delta - cat->in[in_no].pts,
|
2012-07-17 01:05:05 +02:00
|
|
|
outlink->time_base, rate_tb);
|
|
|
|
frame_nb_samples = FFMAX(9600, rate_tb.den / 5); /* arbitrary */
|
|
|
|
while (nb_samples) {
|
|
|
|
frame_nb_samples = FFMIN(frame_nb_samples, nb_samples);
|
2013-03-10 01:30:30 +01:00
|
|
|
buf = ff_get_audio_buffer(outlink, frame_nb_samples);
|
2012-07-17 01:05:05 +02:00
|
|
|
if (!buf)
|
2013-03-13 09:56:18 +01:00
|
|
|
return AVERROR(ENOMEM);
|
2012-07-17 01:05:05 +02:00
|
|
|
av_samples_set_silence(buf->extended_data, 0, frame_nb_samples,
|
|
|
|
nb_channels, outlink->format);
|
|
|
|
buf->pts = base_pts + av_rescale_q(sent, rate_tb, outlink->time_base);
|
2013-03-13 09:56:18 +01:00
|
|
|
ret = ff_filter_frame(outlink, buf);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
sent += frame_nb_samples;
|
|
|
|
nb_samples -= frame_nb_samples;
|
|
|
|
}
|
2013-03-13 09:56:18 +01:00
|
|
|
return 0;
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:56:18 +01:00
|
|
|
static int flush_segment(AVFilterContext *ctx)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
2013-03-13 09:56:18 +01:00
|
|
|
int ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned str, str_max;
|
2013-03-16 12:21:14 +01:00
|
|
|
int64_t seg_delta;
|
2012-07-17 01:05:05 +02:00
|
|
|
|
2013-03-16 12:21:14 +01:00
|
|
|
find_next_delta_ts(ctx, &seg_delta);
|
2012-07-17 01:05:05 +02:00
|
|
|
cat->cur_idx += ctx->nb_outputs;
|
|
|
|
cat->nb_in_active = ctx->nb_outputs;
|
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "Segment finished at pts=%"PRId64"\n",
|
|
|
|
cat->delta_ts);
|
|
|
|
|
|
|
|
if (cat->cur_idx < ctx->nb_inputs) {
|
|
|
|
/* pad audio streams with silence */
|
|
|
|
str = cat->nb_streams[AVMEDIA_TYPE_VIDEO];
|
|
|
|
str_max = str + cat->nb_streams[AVMEDIA_TYPE_AUDIO];
|
2013-03-13 09:56:18 +01:00
|
|
|
for (; str < str_max; str++) {
|
2013-03-16 12:21:14 +01:00
|
|
|
ret = send_silence(ctx, cat->cur_idx - ctx->nb_outputs + str, str,
|
|
|
|
seg_delta);
|
2013-03-13 09:56:18 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-17 01:05:05 +02:00
|
|
|
/* flush queued buffers */
|
|
|
|
/* possible enhancement: flush in PTS order */
|
|
|
|
str_max = cat->cur_idx + ctx->nb_outputs;
|
2013-03-13 09:56:18 +01:00
|
|
|
for (str = cat->cur_idx; str < str_max; str++) {
|
|
|
|
while (cat->in[str].queue.available) {
|
|
|
|
ret = push_frame(ctx, str, ff_bufqueue_get(&cat->in[str].queue));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
2013-03-13 09:56:18 +01:00
|
|
|
return 0;
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int request_frame(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned out_no = FF_OUTLINK_IDX(outlink);
|
|
|
|
unsigned in_no = out_no + cat->cur_idx;
|
|
|
|
unsigned str, str_max;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (in_no >= ctx->nb_inputs)
|
|
|
|
return AVERROR_EOF;
|
|
|
|
if (!cat->in[in_no].eof) {
|
|
|
|
ret = ff_request_frame(ctx->inputs[in_no]);
|
|
|
|
if (ret != AVERROR_EOF)
|
|
|
|
return ret;
|
|
|
|
close_input(ctx, in_no);
|
|
|
|
}
|
|
|
|
/* cycle on all inputs to finish the segment */
|
|
|
|
/* possible enhancement: request in PTS order */
|
|
|
|
str_max = cat->cur_idx + ctx->nb_outputs - 1;
|
|
|
|
for (str = cat->cur_idx; cat->nb_in_active;
|
|
|
|
str = str == str_max ? cat->cur_idx : str + 1) {
|
|
|
|
if (cat->in[str].eof)
|
|
|
|
continue;
|
|
|
|
ret = ff_request_frame(ctx->inputs[str]);
|
|
|
|
if (ret == AVERROR_EOF)
|
|
|
|
close_input(ctx, str);
|
|
|
|
else if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2013-03-13 09:56:18 +01:00
|
|
|
ret = flush_segment(ctx);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-07-17 01:05:05 +02:00
|
|
|
in_no += ctx->nb_outputs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:13:33 +02:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2012-07-17 01:05:05 +02:00
|
|
|
{
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned seg, type, str;
|
|
|
|
|
|
|
|
/* create input pads */
|
|
|
|
for (seg = 0; seg < cat->nb_segments; seg++) {
|
|
|
|
for (type = 0; type < TYPE_ALL; type++) {
|
|
|
|
for (str = 0; str < cat->nb_streams[type]; str++) {
|
|
|
|
AVFilterPad pad = {
|
|
|
|
.type = type,
|
|
|
|
.get_video_buffer = get_video_buffer,
|
|
|
|
.get_audio_buffer = get_audio_buffer,
|
2012-11-29 12:23:26 +01:00
|
|
|
.filter_frame = filter_frame,
|
2012-07-17 01:05:05 +02:00
|
|
|
};
|
2012-11-29 12:25:02 +01:00
|
|
|
pad.name = av_asprintf("in%d:%c%d", seg, "va"[type], str);
|
2012-07-17 01:05:05 +02:00
|
|
|
ff_insert_inpad(ctx, ctx->nb_inputs, &pad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* create output pads */
|
|
|
|
for (type = 0; type < TYPE_ALL; type++) {
|
|
|
|
for (str = 0; str < cat->nb_streams[type]; str++) {
|
|
|
|
AVFilterPad pad = {
|
|
|
|
.type = type,
|
|
|
|
.config_props = config_output,
|
|
|
|
.request_frame = request_frame,
|
|
|
|
};
|
2012-11-29 12:25:02 +01:00
|
|
|
pad.name = av_asprintf("out:%c%d", "va"[type], str);
|
2012-07-17 01:05:05 +02:00
|
|
|
ff_insert_outpad(ctx, ctx->nb_outputs, &pad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cat->in = av_calloc(ctx->nb_inputs, sizeof(*cat->in));
|
|
|
|
if (!cat->in)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
cat->nb_in_active = ctx->nb_outputs;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
ConcatContext *cat = ctx->priv;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < ctx->nb_inputs; i++) {
|
|
|
|
av_freep(&ctx->input_pads[i].name);
|
|
|
|
ff_bufqueue_discard_all(&cat->in[i].queue);
|
|
|
|
}
|
|
|
|
for (i = 0; i < ctx->nb_outputs; i++)
|
|
|
|
av_freep(&ctx->output_pads[i].name);
|
2014-11-22 18:44:35 +01:00
|
|
|
av_freep(&cat->in);
|
2012-07-17 01:05:05 +02:00
|
|
|
}
|
|
|
|
|
2013-10-29 11:50:56 +01:00
|
|
|
AVFilter ff_avf_concat = {
|
2012-07-17 01:05:05 +02:00
|
|
|
.name = "concat",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Concatenate audio and video streams."),
|
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.query_formats = query_formats,
|
|
|
|
.priv_size = sizeof(ConcatContext),
|
2012-11-28 20:01:59 +01:00
|
|
|
.inputs = NULL,
|
|
|
|
.outputs = NULL,
|
2012-08-13 13:40:01 +02:00
|
|
|
.priv_class = &concat_class,
|
2013-04-13 19:43:17 +02:00
|
|
|
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_DYNAMIC_OUTPUTS,
|
2012-07-17 01:05:05 +02:00
|
|
|
};
|