Go to the documentation of this file.
22 #include "config_components.h"
86 #if CONFIG_TRIM_FILTER
101 if (
s->start_frame >= 0 &&
s->nb_frames >=
s->start_frame)
113 if (
s->end_frame != INT64_MAX ||
s->end_pts !=
AV_NOPTS_VALUE ||
s->duration_tb) {
116 if (
s->end_frame != INT64_MAX &&
s->nb_frames <
s->end_frame)
144 #endif // CONFIG_TRIM_FILTER
146 #if CONFIG_ATRIM_FILTER
151 int64_t start_sample, end_sample;
175 if (
s->start_sample >= 0 &&
178 start_sample =
FFMIN(start_sample,
s->start_sample -
s->nb_samples);
184 start_sample =
FFMIN(start_sample,
s->start_pts -
pts);
192 s->first_pts =
pts + start_sample;
195 if (
s->end_sample == INT64_MAX &&
s->end_pts ==
AV_NOPTS_VALUE && !
s->duration_tb) {
201 if (
s->end_sample != INT64_MAX &&
202 s->nb_samples <
s->end_sample) {
204 end_sample =
FFMAX(end_sample,
s->end_sample -
s->nb_samples);
210 end_sample =
FFMAX(end_sample,
s->end_pts -
pts);
213 if (
s->duration_tb &&
pts -
s->first_pts <
s->duration_tb) {
215 end_sample =
FFMAX(end_sample,
s->first_pts +
s->duration_tb -
pts);
227 start_sample =
FFMAX(0, start_sample);
241 out->nb_samples,
inlink->ch_layout.nb_channels,
261 #endif // CONFIG_ATRIM_FILTER
270 #if CONFIG_TRIM_FILTER
272 s->filter_frame = trim_filter_frame;
274 #if CONFIG_ATRIM_FILTER
276 s->filter_frame = atrim_filter_frame;
278 if (
s->start_time != INT64_MAX) {
281 s->start_pts = start_pts;
283 if (
s->end_time != INT64_MAX) {
286 s->end_pts = end_pts;
319 #define OFFSET(x) offsetof(TrimContext, x)
320 #define COMMON_OPTS \
321 { "start", "Timestamp of the first frame that " \
322 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
323 { "starti", "Timestamp of the first frame that " \
324 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
325 { "end", "Timestamp of the first frame that " \
326 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
327 { "endi", "Timestamp of the first frame that " \
328 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
329 { "start_pts", "Timestamp of the first frame that should be " \
330 " passed", OFFSET(start_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
331 { "end_pts", "Timestamp of the first frame that should be " \
332 "dropped again", OFFSET(end_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
333 { "duration", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS }, \
334 { "durationi", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS },
337 #if CONFIG_TRIM_FILTER
339 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
340 static const AVOption trim_options[] = {
342 {
"start_frame",
"Number of the first frame that should be passed "
344 {
"end_frame",
"Number of the first frame that should be dropped "
362 .description =
NULL_IF_CONFIG_SMALL(
"Pick one continuous section from the input, drop the rest."),
366 .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.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
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)
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).
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
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.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
FF_FILTER_FORWARD_WANTED(outlink, inlink)
#define AVFILTER_DEFINE_CLASS(fname)
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t ** extended_data
pointers to the data planes/channels.
const char * name
Pad name.
static int config_input(AVFilterLink *inlink)
const AVFilter ff_vf_trim
#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 FILTER_OUTPUTS(array)
#define flags(name, subs,...)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.