Go to the documentation of this file.
22 #include "config_components.h"
89 if (
s->start_time != INT64_MAX) {
92 s->start_pts = start_pts;
94 if (
s->end_time != INT64_MAX) {
105 #define OFFSET(x) offsetof(TrimContext, x)
106 #define COMMON_OPTS \
107 { "start", "Timestamp of the first frame that " \
108 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
109 { "starti", "Timestamp of the first frame that " \
110 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
111 { "end", "Timestamp of the first frame that " \
112 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
113 { "endi", "Timestamp of the first frame that " \
114 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
115 { "start_pts", "Timestamp of the first frame that should be " \
116 " passed", OFFSET(start_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
117 { "end_pts", "Timestamp of the first frame that should be " \
118 "dropped again", OFFSET(end_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
119 { "duration", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS }, \
120 { "durationi", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS },
123 #if CONFIG_TRIM_FILTER
138 if (
s->start_frame >= 0 &&
s->nb_frames >=
s->start_frame)
141 frame->pts >=
s->start_pts)
148 s->first_pts =
frame->pts;
150 if (
s->end_frame != INT64_MAX ||
s->end_pts !=
AV_NOPTS_VALUE ||
s->duration_tb) {
153 if (
s->end_frame != INT64_MAX &&
s->nb_frames <
s->end_frame)
159 frame->pts -
s->first_pts <
s->duration_tb)
179 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
180 static const AVOption trim_options[] = {
182 {
"start_frame",
"Number of the first frame that should be passed "
184 {
"end_frame",
"Number of the first frame that should be dropped "
196 .filter_frame = trim_filter_frame,
210 .description =
NULL_IF_CONFIG_SMALL(
"Pick one continuous section from the input, drop the rest."),
213 .priv_class = &trim_class,
217 #endif // CONFIG_TRIM_FILTER
219 #if CONFIG_ATRIM_FILTER
224 int64_t start_sample, end_sample;
246 start_sample =
frame->nb_samples;
248 if (
s->start_sample >= 0 &&
249 s->nb_samples +
frame->nb_samples >
s->start_sample) {
251 start_sample =
FFMIN(start_sample,
s->start_sample -
s->nb_samples);
255 pts +
frame->nb_samples >
s->start_pts) {
257 start_sample =
FFMIN(start_sample,
s->start_pts -
pts);
265 s->first_pts =
pts + start_sample;
268 if (
s->end_sample == INT64_MAX &&
s->end_pts ==
AV_NOPTS_VALUE && !
s->duration_tb) {
269 end_sample =
frame->nb_samples;
274 if (
s->end_sample != INT64_MAX &&
275 s->nb_samples <
s->end_sample) {
277 end_sample =
FFMAX(end_sample,
s->end_sample -
s->nb_samples);
283 end_sample =
FFMAX(end_sample,
s->end_pts -
pts);
286 if (
s->duration_tb &&
pts -
s->first_pts <
s->duration_tb) {
288 end_sample =
FFMAX(end_sample,
s->first_pts +
s->duration_tb -
pts);
298 s->nb_samples +=
frame->nb_samples;
299 start_sample =
FFMAX(0, start_sample);
300 end_sample =
FFMIN(
frame->nb_samples, end_sample);
301 if (start_sample >= end_sample || !
frame->nb_samples)
313 out->nb_samples,
inlink->ch_layout.nb_channels,
322 frame->nb_samples = end_sample;
327 s->nb_samples +=
frame->nb_samples;
332 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
333 static const AVOption atrim_options[] = {
335 {
"start_sample",
"Number of the first audio sample that should be "
337 {
"end_sample",
"Number of the first audio sample that should be "
349 .filter_frame = atrim_filter_frame,
363 .description =
NULL_IF_CONFIG_SMALL(
"Pick one continuous section from the input, drop the rest."),
366 .priv_class = &atrim_class,
371 #endif // CONFIG_ATRIM_FILTER
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
A link between two filters.
A filter pad used for either input or output.
void ff_avfilter_link_set_out_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the destination filter.
static av_cold int init(AVFilterContext *ctx)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_INPUTS(array)
const AVFilter ff_af_atrim
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AVFILTER_DEFINE_CLASS(fname)
int av_samples_copy(uint8_t **dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
const char * name
Pad name.
static int config_input(AVFilterLink *inlink)
const AVFilter ff_vf_trim
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
#define FILTER_OUTPUTS(array)
#define flags(name, subs,...)