Go to the documentation of this file.
22 #include "config_components.h"
85 #if CONFIG_TRIM_FILTER
100 if (
s->start_frame >= 0 &&
s->nb_frames >=
s->start_frame)
103 frame->pts >=
s->start_pts)
110 s->first_pts =
frame->pts;
112 if (
s->end_frame != INT64_MAX ||
s->end_pts !=
AV_NOPTS_VALUE ||
s->duration_tb) {
115 if (
s->end_frame != INT64_MAX &&
s->nb_frames <
s->end_frame)
121 frame->pts -
s->first_pts <
s->duration_tb)
143 #endif // CONFIG_TRIM_FILTER
145 #if CONFIG_ATRIM_FILTER
150 int64_t start_sample, end_sample;
172 start_sample =
frame->nb_samples;
174 if (
s->start_sample >= 0 &&
175 s->nb_samples +
frame->nb_samples >
s->start_sample) {
177 start_sample =
FFMIN(start_sample,
s->start_sample -
s->nb_samples);
181 pts +
frame->nb_samples >
s->start_pts) {
183 start_sample =
FFMIN(start_sample,
s->start_pts -
pts);
191 s->first_pts =
pts + start_sample;
194 if (
s->end_sample == INT64_MAX &&
s->end_pts ==
AV_NOPTS_VALUE && !
s->duration_tb) {
195 end_sample =
frame->nb_samples;
200 if (
s->end_sample != INT64_MAX &&
201 s->nb_samples <
s->end_sample) {
203 end_sample =
FFMAX(end_sample,
s->end_sample -
s->nb_samples);
209 end_sample =
FFMAX(end_sample,
s->end_pts -
pts);
212 if (
s->duration_tb &&
pts -
s->first_pts <
s->duration_tb) {
214 end_sample =
FFMAX(end_sample,
s->first_pts +
s->duration_tb -
pts);
225 s->nb_samples +=
frame->nb_samples;
226 start_sample =
FFMAX(0, start_sample);
227 end_sample =
FFMIN(
frame->nb_samples, end_sample);
228 if (start_sample >= end_sample || !
frame->nb_samples)
240 out->nb_samples,
inlink->ch_layout.nb_channels,
249 frame->nb_samples = end_sample;
256 s->nb_samples +=
frame->nb_samples;
260 #endif // CONFIG_ATRIM_FILTER
269 #if CONFIG_TRIM_FILTER
271 s->filter_frame = trim_filter_frame;
273 #if CONFIG_ATRIM_FILTER
275 s->filter_frame = atrim_filter_frame;
277 if (
s->start_time != INT64_MAX) {
280 s->start_pts = start_pts;
282 if (
s->end_time != INT64_MAX) {
285 s->end_pts = end_pts;
318 #define OFFSET(x) offsetof(TrimContext, x)
319 #define COMMON_OPTS \
320 { "start", "Timestamp of the first frame that " \
321 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
322 { "starti", "Timestamp of the first frame that " \
323 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
324 { "end", "Timestamp of the first frame that " \
325 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
326 { "endi", "Timestamp of the first frame that " \
327 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
328 { "start_pts", "Timestamp of the first frame that should be " \
329 " passed", OFFSET(start_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
330 { "end_pts", "Timestamp of the first frame that should be " \
331 "dropped again", OFFSET(end_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
332 { "duration", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS }, \
333 { "durationi", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS },
336 #if CONFIG_TRIM_FILTER
338 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
339 static const AVOption trim_options[] = {
341 {
"start_frame",
"Number of the first frame that should be passed "
343 {
"end_frame",
"Number of the first frame that should be dropped "
361 .description =
NULL_IF_CONFIG_SMALL(
"Pick one continuous section from the input, drop the rest."),
365 .priv_class = &trim_class,
370 #endif // CONFIG_TRIM_FILTER
372 #if CONFIG_ATRIM_FILTER
374 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
375 static const AVOption atrim_options[] = {
377 {
"start_sample",
"Number of the first audio sample that should be "
379 {
"end_sample",
"Number of the first audio sample that should be "
397 .description =
NULL_IF_CONFIG_SMALL(
"Pick one continuous section from the input, drop the rest."),
401 .priv_class = &atrim_class,
406 #endif // CONFIG_ATRIM_FILTER
int av_samples_copy(uint8_t *const *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.
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.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
int(* filter_frame)(AVFilterLink *inlink, AVFrame *frame)
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
static int activate(AVFilterContext *ctx)
A filter pad used for either input or output.
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
static av_cold int init(AVFilterContext *ctx)
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_OUTPUTS(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).
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
#define AVFILTER_DEFINE_CLASS(fname)
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
#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.
FF_FILTER_FORWARD_WANTED(outlink, inlink)
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.
FF_FILTER_FORWARD_STATUS(inlink, outlink)
#define flags(name, subs,...)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.