22#include "config_components.h"
98 if (
s->start_frame >= 0 &&
s->nb_frames >=
s->start_frame)
101 frame->pts >=
s->start_pts)
108 s->first_pts =
frame->pts;
110 if (
s->end_frame != INT64_MAX ||
s->end_pts !=
AV_NOPTS_VALUE ||
s->duration_tb) {
113 if (
s->end_frame != INT64_MAX &&
s->nb_frames <
s->end_frame)
119 frame->pts -
s->first_pts <
s->duration_tb)
140#if CONFIG_ATRIM_FILTER
145 int64_t start_sample, end_sample;
165 start_sample =
frame->nb_samples;
167 if (
s->start_sample >= 0 &&
168 s->nb_samples +
frame->nb_samples >
s->start_sample) {
170 start_sample =
FFMIN(start_sample,
s->start_sample -
s->nb_samples);
174 pts +
frame->nb_samples >
s->start_pts) {
176 start_sample =
FFMIN(start_sample,
s->start_pts -
pts);
184 s->first_pts =
pts + start_sample;
187 if (
s->end_sample == INT64_MAX &&
s->end_pts ==
AV_NOPTS_VALUE && !
s->duration_tb) {
188 end_sample =
frame->nb_samples;
193 if (
s->end_sample != INT64_MAX &&
194 s->nb_samples <
s->end_sample) {
196 end_sample =
FFMAX(end_sample,
s->end_sample -
s->nb_samples);
202 end_sample =
FFMAX(end_sample,
s->end_pts -
pts);
205 if (
s->duration_tb &&
pts -
s->first_pts <
s->duration_tb) {
207 end_sample =
FFMAX(end_sample,
s->first_pts +
s->duration_tb -
pts);
218 s->nb_samples +=
frame->nb_samples;
219 start_sample =
FFMAX(0, start_sample);
220 end_sample =
FFMIN(
frame->nb_samples, end_sample);
221 if (start_sample >= end_sample || !
frame->nb_samples)
241 frame->nb_samples = end_sample;
246 s->nb_samples +=
frame->nb_samples;
258#if CONFIG_TRIM_FILTER
260 s->filter_frame = trim_filter_frame;
262#if CONFIG_ATRIM_FILTER
264 s->filter_frame = atrim_filter_frame;
266 if (
s->start_time != INT64_MAX) {
269 s->start_pts = start_pts;
271 if (
s->end_time != INT64_MAX) {
274 s->end_pts = end_pts;
296 ret =
s->filter_frame(inlink,
frame);
310#define OFFSET(x) offsetof(TrimContext, x)
312 { "start", "Timestamp of the first frame that " \
313 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
314 { "starti", "Timestamp of the first frame that " \
315 "should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
316 { "end", "Timestamp of the first frame that " \
317 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
318 { "endi", "Timestamp of the first frame that " \
319 "should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
320 { "start_pts", "Timestamp of the first frame that should be " \
321 " passed", OFFSET(start_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
322 { "end_pts", "Timestamp of the first frame that should be " \
323 "dropped again", OFFSET(end_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
324 { "duration", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS }, \
325 { "durationi", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS },
328#if CONFIG_TRIM_FILTER
330#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
331static const AVOption trim_options[] = {
333 {
"start_frame",
"Number of the first frame that should be passed "
335 {
"end_frame",
"Number of the first frame that should be dropped "
353 .p.description =
NULL_IF_CONFIG_SMALL(
"Pick one continuous section from the input, drop the rest."),
354 .p.priv_class = &trim_class,
364#if CONFIG_ATRIM_FILTER
366#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
367static const AVOption atrim_options[] = {
369 {
"start_sample",
"Number of the first audio sample that should be "
371 {
"end_sample",
"Number of the first audio sample that should be "
389 .p.description =
NULL_IF_CONFIG_SMALL(
"Pick one continuous section from the input, drop the rest."),
390 .p.priv_class = &atrim_class,
static int config_input(AVFilterLink *inlink)
const FFFilter ff_af_atrim
const FFFilter ff_vf_trim
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Main libavfilter public API header.
Public libavutil channel layout APIs header.
common internal and external API header
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
#define AVERROR_EOF
End of file.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
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 and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
enum AVMediaType type
filter media type
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
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Rational number (pair of numerator and denominator).
int(* filter_frame)(AVFilterLink *inlink, AVFrame *frame)
static AVFormatContext * ctx
static int config_input(AVFilterLink *inlink)
static int activate(AVFilterContext *ctx)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.