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
59 {
"n",
"specify the number of segments",
OFFSET(nb_segments),
61 {
"v",
"specify the number of video streams",
64 {
"a",
"specify the number of audio streams",
67 {
"unsafe",
"enable unsafe mode",
78 unsigned type, nb_str, idx0 = 0, idx,
str, seg;
103 for (seg = 0; seg <
cat->nb_segments; seg++) {
111 idx +=
ctx->nb_outputs;
125 unsigned in_no = out_no, seg;
130 outlink->
w = inlink->
w;
131 outlink->
h = inlink->
h;
136 for (seg = 1; seg <
cat->nb_segments; seg++) {
137 inlink =
ctx->inputs[in_no + seg *
ctx->nb_outputs];
141 "Video inputs have different frame rates, output will be VFR\n");
147 for (seg = 1; seg <
cat->nb_segments; seg++) {
148 inlink =
ctx->inputs[in_no + seg *
ctx->nb_outputs];
152 if (outlink->
w != inlink->
w ||
153 outlink->
h != inlink->
h ||
158 "(size %dx%d, SAR %d:%d) do not match the corresponding "
159 "output link %s parameters (%dx%d, SAR %d:%d)\n",
160 ctx->input_pads[in_no].name, inlink->
w, inlink->
h,
163 ctx->input_pads[out_no].name, outlink->
w, outlink->
h,
177 unsigned out_no = in_no %
ctx->nb_outputs;
180 struct concat_in *
in = &
cat->in[in_no];
191 else if (
in->nb_frames >= 2)
195 buf->
pts +=
cat->delta_ts;
221 cat->in[in_no].eof = 1;
224 ctx->input_pads[in_no].name,
cat->nb_in_active);
230 unsigned i =
cat->cur_idx;
231 unsigned imax =
i +
ctx->nb_outputs;
235 for (;
i < imax;
i++)
246 int64_t base_pts =
cat->in[in_no].pts +
cat->delta_ts - seg_delta;
248 int frame_nb_samples, ret;
254 if (
cat->in[in_no].pts < INT64_MIN + seg_delta)
256 if (seg_delta < cat->
in[in_no].
pts)
260 frame_nb_samples =
FFMAX(9600, rate_tb.
den / 5);
262 frame_nb_samples =
FFMIN(frame_nb_samples, nb_samples);
272 sent += frame_nb_samples;
273 nb_samples -= frame_nb_samples;
282 unsigned str, str_max;
286 cat->cur_idx +=
ctx->nb_outputs;
287 cat->nb_in_active =
ctx->nb_outputs;
291 if (
cat->cur_idx <
ctx->nb_inputs) {
295 for (;
str < str_max;
str++) {
312 for (seg = 0; seg <
cat->nb_segments; seg++) {
346 cat->nb_in_active =
ctx->nb_outputs;
355 for (
i = 0;
i <
ctx->nb_inputs;
i++)
357 for (
i = 0;
i <
ctx->nb_outputs;
i++)
371 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
375 for (j =
i; j <
ctx->nb_inputs; j +=
ctx->nb_outputs) {
376 if (!
cat->in[j].eof) {
386 if (
cat->cur_idx <
ctx->nb_inputs) {
387 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
399 if (
cat->cur_idx <
ctx->nb_inputs) {
400 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
405 if (
cat->cur_idx +
ctx->nb_outputs >=
ctx->nb_inputs) {
408 if (!
cat->nb_in_active) {
420 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
422 if (
cat->in[
cat->cur_idx +
i].eof) {
423 for (j = 0; j <
ctx->nb_outputs; j++)
424 if (!
cat->in[
cat->cur_idx + j].eof)
438 char *res,
int res_len,
int flags)
442 if (!strcmp(cmd,
"next")) {
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
static void close_input(AVFilterContext *ctx, unsigned in_no)
static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no, int64_t seg_delta)
static int query_formats(AVFilterContext *ctx)
static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
static void find_next_delta_ts(AVFilterContext *ctx, int64_t *seg_delta)
static AVFrame * get_audio_buffer(AVFilterLink *inlink, int nb_samples)
AVFILTER_DEFINE_CLASS(concat)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int activate(AVFilterContext *ctx)
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
static int flush_segment(AVFilterContext *ctx)
static const AVOption concat_options[]
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
#define flags(name, subs,...)
audio channel layout utility functions
static const AVClass concat_class
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions.
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
#define FF_INLINK_IDX(link)
Find the index of a link.
#define FF_OUTLINK_IDX(link)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum MovChannelLayoutTag * layouts
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
int channels
Number of channels.
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
enum AVMediaType type
AVFilterPad type.
const char * name
Pad name.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t ** extended_data
pointers to the data planes/channels.
Rational number (pair of numerator and denominator).
int64_t delta_ts
timestamp to add to produce output timestamps
struct ConcatContext::concat_in * in
unsigned nb_streams[TYPE_ALL]
number of out streams of each type
unsigned cur_idx
index of the first input of current segment
unsigned nb_in_active
number of active inputs in current segment
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.