Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * This file is part of FFmpeg. | ||
3 | * | ||
4 | * FFmpeg is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * FFmpeg is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with FFmpeg; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | |||
19 | #include <stdint.h> | ||
20 | |||
21 | #include "config.h" | ||
22 | #include "config_components.h" | ||
23 | |||
24 | #include "libavutil/channel_layout.h" | ||
25 | #include "libavutil/common.h" | ||
26 | #include "libavutil/log.h" | ||
27 | #include "libavutil/mathematics.h" | ||
28 | #include "libavutil/opt.h" | ||
29 | #include "libavutil/samplefmt.h" | ||
30 | |||
31 | #include "audio.h" | ||
32 | #include "avfilter.h" | ||
33 | #include "filters.h" | ||
34 | #include "video.h" | ||
35 | |||
36 | typedef struct TrimContext { | ||
37 | const AVClass *class; | ||
38 | |||
39 | /* | ||
40 | * AVOptions | ||
41 | */ | ||
42 | int64_t duration; | ||
43 | int64_t start_time, end_time; | ||
44 | int64_t start_frame, end_frame; | ||
45 | /* | ||
46 | * in the link timebase for video, | ||
47 | * in 1/samplerate for audio | ||
48 | */ | ||
49 | int64_t start_pts, end_pts; | ||
50 | int64_t start_sample, end_sample; | ||
51 | |||
52 | /* | ||
53 | * number of video frames that arrived on this filter so far | ||
54 | */ | ||
55 | int64_t nb_frames; | ||
56 | /* | ||
57 | * number of audio samples that arrived on this filter so far | ||
58 | */ | ||
59 | int64_t nb_samples; | ||
60 | /* | ||
61 | * timestamp of the first frame in the output, in the timebase units | ||
62 | */ | ||
63 | int64_t first_pts; | ||
64 | /* | ||
65 | * duration in the timebase units | ||
66 | */ | ||
67 | int64_t duration_tb; | ||
68 | |||
69 | int64_t next_pts; | ||
70 | |||
71 | int eof; | ||
72 | |||
73 | int (*filter_frame)(AVFilterLink *inlink, AVFrame *frame); | ||
74 | } TrimContext; | ||
75 | |||
76 | 2013 | static av_cold int init(AVFilterContext *ctx) | |
77 | { | ||
78 | 2013 | TrimContext *s = ctx->priv; | |
79 | |||
80 | 2013 | s->first_pts = AV_NOPTS_VALUE; | |
81 | |||
82 | 2013 | return 0; | |
83 | } | ||
84 | |||
85 | #if CONFIG_TRIM_FILTER | ||
86 | 31639 | static int trim_filter_frame(AVFilterLink *inlink, AVFrame *frame) | |
87 | { | ||
88 | 31639 | AVFilterContext *ctx = inlink->dst; | |
89 | 31639 | TrimContext *s = ctx->priv; | |
90 | int drop; | ||
91 | |||
92 | /* drop everything if EOF has already been returned */ | ||
93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31639 times.
|
31639 | if (s->eof) |
94 | ✗ | return 0; | |
95 | |||
96 |
4/4✓ Branch 0 taken 31617 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 155 times.
✓ Branch 3 taken 31462 times.
|
31639 | if (s->start_frame >= 0 || s->start_pts != AV_NOPTS_VALUE) { |
97 | 177 | drop = 1; | |
98 |
4/4✓ Branch 0 taken 22 times.
✓ Branch 1 taken 155 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 4 times.
|
177 | if (s->start_frame >= 0 && s->nb_frames >= s->start_frame) |
99 | 18 | drop = 0; | |
100 |
3/4✓ Branch 0 taken 166 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 166 times.
✗ Branch 3 not taken.
|
177 | if (s->start_pts != AV_NOPTS_VALUE && frame->pts != AV_NOPTS_VALUE && |
101 |
2/2✓ Branch 0 taken 151 times.
✓ Branch 1 taken 15 times.
|
166 | frame->pts >= s->start_pts) |
102 | 151 | drop = 0; | |
103 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 163 times.
|
177 | if (drop) |
104 | 14 | goto drop; | |
105 | } | ||
106 | |||
107 |
3/4✓ Branch 0 taken 1188 times.
✓ Branch 1 taken 30437 times.
✓ Branch 2 taken 1188 times.
✗ Branch 3 not taken.
|
31625 | if (s->first_pts == AV_NOPTS_VALUE && frame->pts != AV_NOPTS_VALUE) |
108 | 1188 | s->first_pts = frame->pts; | |
109 | |||
110 |
6/6✓ Branch 0 taken 31607 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 31604 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 31464 times.
✓ Branch 5 taken 140 times.
|
31625 | if (s->end_frame != INT64_MAX || s->end_pts != AV_NOPTS_VALUE || s->duration_tb) { |
111 | 31485 | drop = 1; | |
112 | |||
113 |
4/4✓ Branch 0 taken 18 times.
✓ Branch 1 taken 31467 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
|
31485 | if (s->end_frame != INT64_MAX && s->nb_frames < s->end_frame) |
114 | 9 | drop = 0; | |
115 |
3/4✓ Branch 0 taken 13 times.
✓ Branch 1 taken 31472 times.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
|
31485 | if (s->end_pts != AV_NOPTS_VALUE && frame->pts != AV_NOPTS_VALUE && |
116 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2 times.
|
13 | frame->pts < s->end_pts) |
117 | 11 | drop = 0; | |
118 |
3/4✓ Branch 0 taken 31464 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 31464 times.
✗ Branch 3 not taken.
|
31485 | if (s->duration_tb && frame->pts != AV_NOPTS_VALUE && |
119 |
2/2✓ Branch 0 taken 30287 times.
✓ Branch 1 taken 1177 times.
|
31464 | frame->pts - s->first_pts < s->duration_tb) |
120 | 30287 | drop = 0; | |
121 | |||
122 |
2/2✓ Branch 0 taken 1180 times.
✓ Branch 1 taken 30305 times.
|
31485 | if (drop) { |
123 | 1180 | s->eof = 1; | |
124 | 1180 | ff_inlink_set_status(inlink, AVERROR_EOF); | |
125 | 1180 | ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, frame->pts); | |
126 | 1180 | goto drop; | |
127 | } | ||
128 | } | ||
129 | |||
130 | 30445 | s->nb_frames++; | |
131 | |||
132 | 30445 | return 1; | |
133 | |||
134 | 1194 | drop: | |
135 | 1194 | s->nb_frames++; | |
136 | 1194 | return 0; | |
137 | } | ||
138 | #endif // CONFIG_TRIM_FILTER | ||
139 | |||
140 | #if CONFIG_ATRIM_FILTER | ||
141 | 10688 | static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame) | |
142 | { | ||
143 | 10688 | AVFilterContext *ctx = inlink->dst; | |
144 | 10688 | TrimContext *s = ctx->priv; | |
145 | int64_t start_sample, end_sample; | ||
146 | int64_t pts; | ||
147 | int drop; | ||
148 | |||
149 | /* drop everything if EOF has already been returned */ | ||
150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10688 times.
|
10688 | if (s->eof) |
151 | ✗ | return 0; | |
152 | |||
153 |
1/2✓ Branch 0 taken 10688 times.
✗ Branch 1 not taken.
|
10688 | if (frame->pts != AV_NOPTS_VALUE) |
154 | 10688 | pts = av_rescale_q(frame->pts, inlink->time_base, | |
155 | 10688 | (AVRational){ 1, inlink->sample_rate }); | |
156 | else | ||
157 | ✗ | pts = s->next_pts; | |
158 | 10688 | s->next_pts = pts + frame->nb_samples; | |
159 | |||
160 | /* check if at least a part of the frame is after the start time */ | ||
161 |
4/4✓ Branch 0 taken 10683 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 8898 times.
✓ Branch 3 taken 1785 times.
|
10688 | if (s->start_sample < 0 && s->start_pts == AV_NOPTS_VALUE) { |
162 | 8898 | start_sample = 0; | |
163 | } else { | ||
164 | 1790 | drop = 1; | |
165 | 1790 | start_sample = frame->nb_samples; | |
166 | |||
167 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1785 times.
|
1790 | if (s->start_sample >= 0 && |
168 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | s->nb_samples + frame->nb_samples > s->start_sample) { |
169 | 5 | drop = 0; | |
170 | 5 | start_sample = FFMIN(start_sample, s->start_sample - s->nb_samples); | |
171 | } | ||
172 | |||
173 |
3/4✓ Branch 0 taken 1788 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1788 times.
✗ Branch 3 not taken.
|
1790 | if (s->start_pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && |
174 |
2/2✓ Branch 0 taken 1464 times.
✓ Branch 1 taken 324 times.
|
1788 | pts + frame->nb_samples > s->start_pts) { |
175 | 1464 | drop = 0; | |
176 | 1464 | start_sample = FFMIN(start_sample, s->start_pts - pts); | |
177 | } | ||
178 | |||
179 |
2/2✓ Branch 0 taken 324 times.
✓ Branch 1 taken 1466 times.
|
1790 | if (drop) |
180 | 324 | goto drop; | |
181 | } | ||
182 | |||
183 |
2/2✓ Branch 0 taken 480 times.
✓ Branch 1 taken 9884 times.
|
10364 | if (s->first_pts == AV_NOPTS_VALUE) |
184 | 480 | s->first_pts = pts + start_sample; | |
185 | |||
186 | /* check if at least a part of the frame is before the end time */ | ||
187 |
6/6✓ Branch 0 taken 5110 times.
✓ Branch 1 taken 5254 times.
✓ Branch 2 taken 5090 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 1456 times.
✓ Branch 5 taken 3634 times.
|
10364 | if (s->end_sample == INT64_MAX && s->end_pts == AV_NOPTS_VALUE && !s->duration_tb) { |
188 | 1456 | end_sample = frame->nb_samples; | |
189 | } else { | ||
190 | 8908 | drop = 1; | |
191 | 8908 | end_sample = 0; | |
192 | |||
193 |
2/2✓ Branch 0 taken 5254 times.
✓ Branch 1 taken 3654 times.
|
8908 | if (s->end_sample != INT64_MAX && |
194 |
2/2✓ Branch 0 taken 4917 times.
✓ Branch 1 taken 337 times.
|
5254 | s->nb_samples < s->end_sample) { |
195 | 4917 | drop = 0; | |
196 | 4917 | end_sample = FFMAX(end_sample, s->end_sample - s->nb_samples); | |
197 | } | ||
198 | |||
199 |
3/4✓ Branch 0 taken 23 times.
✓ Branch 1 taken 8885 times.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
|
8908 | if (s->end_pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && |
200 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 3 times.
|
23 | pts < s->end_pts) { |
201 | 20 | drop = 0; | |
202 | 20 | end_sample = FFMAX(end_sample, s->end_pts - pts); | |
203 | } | ||
204 | |||
205 |
4/4✓ Branch 0 taken 3634 times.
✓ Branch 1 taken 5274 times.
✓ Branch 2 taken 3511 times.
✓ Branch 3 taken 123 times.
|
8908 | if (s->duration_tb && pts - s->first_pts < s->duration_tb) { |
206 | 3511 | drop = 0; | |
207 | 3511 | end_sample = FFMAX(end_sample, s->first_pts + s->duration_tb - pts); | |
208 | } | ||
209 | |||
210 |
2/2✓ Branch 0 taken 462 times.
✓ Branch 1 taken 8446 times.
|
8908 | if (drop) { |
211 | 462 | s->eof = 1; | |
212 | 462 | ff_inlink_set_status(inlink, AVERROR_EOF); | |
213 | 462 | ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, frame->pts); | |
214 | 462 | goto drop; | |
215 | } | ||
216 | } | ||
217 | |||
218 | 9902 | s->nb_samples += frame->nb_samples; | |
219 | 9902 | start_sample = FFMAX(0, start_sample); | |
220 | 9902 | end_sample = FFMIN(frame->nb_samples, end_sample); | |
221 |
2/4✓ Branch 0 taken 9902 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9902 times.
|
9902 | if (start_sample >= end_sample || !frame->nb_samples) |
222 | ✗ | goto drop; | |
223 | |||
224 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9896 times.
|
9902 | if (start_sample) { |
225 | 6 | AVFrame *out = ff_get_audio_buffer(ctx->outputs[0], end_sample - start_sample); | |
226 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!out) |
227 | ✗ | return AVERROR(ENOMEM); | |
228 | |||
229 | 6 | av_frame_copy_props(out, frame); | |
230 | 6 | av_samples_copy(out->extended_data, frame->extended_data, 0, start_sample, | |
231 | 6 | out->nb_samples, inlink->ch_layout.nb_channels, | |
232 | 6 | frame->format); | |
233 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (out->pts != AV_NOPTS_VALUE) |
234 | 6 | out->pts += av_rescale_q(start_sample, (AVRational){ 1, out->sample_rate }, | |
235 | inlink->time_base); | ||
236 | |||
237 | 6 | av_frame_unref(frame); | |
238 | 6 | av_frame_move_ref(frame, out); | |
239 | 6 | av_frame_free(&out); | |
240 | } else | ||
241 | 9896 | frame->nb_samples = end_sample; | |
242 | |||
243 | 9902 | return 1; | |
244 | |||
245 | 786 | drop: | |
246 | 786 | s->nb_samples += frame->nb_samples; | |
247 | 786 | return 0; | |
248 | } | ||
249 | #endif // CONFIG_ATRIM_FILTER | ||
250 | |||
251 | 1668 | static int config_input(AVFilterLink *inlink) | |
252 | { | ||
253 | 1668 | AVFilterContext *ctx = inlink->dst; | |
254 | 1668 | TrimContext *s = ctx->priv; | |
255 | 1188 | AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ? | |
256 |
2/2✓ Branch 0 taken 1188 times.
✓ Branch 1 taken 480 times.
|
1668 | inlink->time_base : (AVRational){ 1, inlink->sample_rate }; |
257 | |||
258 | #if CONFIG_TRIM_FILTER | ||
259 |
2/2✓ Branch 0 taken 1188 times.
✓ Branch 1 taken 480 times.
|
1668 | if (inlink->type == AVMEDIA_TYPE_VIDEO) |
260 | 1188 | s->filter_frame = trim_filter_frame; | |
261 | #endif | ||
262 | #if CONFIG_ATRIM_FILTER | ||
263 |
2/2✓ Branch 0 taken 480 times.
✓ Branch 1 taken 1188 times.
|
1668 | if (inlink->type == AVMEDIA_TYPE_AUDIO) |
264 | 480 | s->filter_frame = atrim_filter_frame; | |
265 | #endif | ||
266 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 1643 times.
|
1668 | if (s->start_time != INT64_MAX) { |
267 | 25 | int64_t start_pts = av_rescale_q(s->start_time, AV_TIME_BASE_Q, tb); | |
268 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
25 | if (s->start_pts == AV_NOPTS_VALUE || start_pts < s->start_pts) |
269 | 25 | s->start_pts = start_pts; | |
270 | } | ||
271 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1663 times.
|
1668 | if (s->end_time != INT64_MAX) { |
272 | 5 | int64_t end_pts = av_rescale_q(s->end_time, AV_TIME_BASE_Q, tb); | |
273 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
5 | if (s->end_pts == AV_NOPTS_VALUE || end_pts > s->end_pts) |
274 | 5 | s->end_pts = end_pts; | |
275 | } | ||
276 |
2/2✓ Branch 0 taken 1307 times.
✓ Branch 1 taken 361 times.
|
1668 | if (s->duration) |
277 | 1307 | s->duration_tb = av_rescale_q(s->duration, AV_TIME_BASE_Q, tb); | |
278 | |||
279 | 1668 | return 0; | |
280 | } | ||
281 | |||
282 | 84865 | static int activate(AVFilterContext *ctx) | |
283 | { | ||
284 | 84865 | TrimContext *s = ctx->priv; | |
285 | 84865 | AVFilterLink *inlink = ctx->inputs[0]; | |
286 | 84865 | AVFilterLink *outlink = ctx->outputs[0]; | |
287 | 84865 | AVFrame *frame = NULL; | |
288 | int ret; | ||
289 | |||
290 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 84857 times.
|
84865 | FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); |
291 | |||
292 |
2/2✓ Branch 1 taken 42327 times.
✓ Branch 2 taken 44510 times.
|
86837 | while ((ret = ff_inlink_consume_frame(inlink, &frame))) { |
293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42327 times.
|
42327 | if (ret < 0) |
294 | ✗ | return ret; | |
295 | |||
296 | 42327 | ret = s->filter_frame(inlink, frame); | |
297 |
2/2✓ Branch 0 taken 40347 times.
✓ Branch 1 taken 1980 times.
|
42327 | if (ret > 0) |
298 | 40347 | return ff_filter_frame(outlink, frame); | |
299 | 1980 | av_frame_free(&frame); | |
300 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1980 times.
|
1980 | if (ret < 0) |
301 | ✗ | return ret; | |
302 | } | ||
303 | |||
304 |
2/2✓ Branch 1 taken 1656 times.
✓ Branch 2 taken 42854 times.
|
44510 | FF_FILTER_FORWARD_STATUS(inlink, outlink); |
305 |
2/2✓ Branch 1 taken 42848 times.
✓ Branch 2 taken 6 times.
|
42854 | FF_FILTER_FORWARD_WANTED(outlink, inlink); |
306 | |||
307 | 6 | return FFERROR_NOT_READY; | |
308 | } | ||
309 | |||
310 | #define OFFSET(x) offsetof(TrimContext, x) | ||
311 | #define COMMON_OPTS \ | ||
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 }, | ||
326 | |||
327 | |||
328 | #if CONFIG_TRIM_FILTER | ||
329 | |||
330 | #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | ||
331 | static const AVOption trim_options[] = { | ||
332 | COMMON_OPTS | ||
333 | { "start_frame", "Number of the first frame that should be passed " | ||
334 | "to the output", OFFSET(start_frame), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, FLAGS }, | ||
335 | { "end_frame", "Number of the first frame that should be dropped " | ||
336 | "again", OFFSET(end_frame), AV_OPT_TYPE_INT64, { .i64 = INT64_MAX }, 0, INT64_MAX, FLAGS }, | ||
337 | { NULL } | ||
338 | }; | ||
339 | #undef FLAGS | ||
340 | |||
341 | AVFILTER_DEFINE_CLASS(trim); | ||
342 | |||
343 | static const AVFilterPad trim_inputs[] = { | ||
344 | { | ||
345 | .name = "default", | ||
346 | .type = AVMEDIA_TYPE_VIDEO, | ||
347 | .config_props = config_input, | ||
348 | }, | ||
349 | }; | ||
350 | |||
351 | const FFFilter ff_vf_trim = { | ||
352 | .p.name = "trim", | ||
353 | .p.description = NULL_IF_CONFIG_SMALL("Pick one continuous section from the input, drop the rest."), | ||
354 | .p.priv_class = &trim_class, | ||
355 | .p.flags = AVFILTER_FLAG_METADATA_ONLY, | ||
356 | .init = init, | ||
357 | .activate = activate, | ||
358 | .priv_size = sizeof(TrimContext), | ||
359 | FILTER_INPUTS(trim_inputs), | ||
360 | FILTER_OUTPUTS(ff_video_default_filterpad), | ||
361 | }; | ||
362 | #endif // CONFIG_TRIM_FILTER | ||
363 | |||
364 | #if CONFIG_ATRIM_FILTER | ||
365 | |||
366 | #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | ||
367 | static const AVOption atrim_options[] = { | ||
368 | COMMON_OPTS | ||
369 | { "start_sample", "Number of the first audio sample that should be " | ||
370 | "passed to the output", OFFSET(start_sample), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, FLAGS }, | ||
371 | { "end_sample", "Number of the first audio sample that should be " | ||
372 | "dropped again", OFFSET(end_sample), AV_OPT_TYPE_INT64, { .i64 = INT64_MAX }, 0, INT64_MAX, FLAGS }, | ||
373 | { NULL } | ||
374 | }; | ||
375 | #undef FLAGS | ||
376 | |||
377 | AVFILTER_DEFINE_CLASS(atrim); | ||
378 | |||
379 | static const AVFilterPad atrim_inputs[] = { | ||
380 | { | ||
381 | .name = "default", | ||
382 | .type = AVMEDIA_TYPE_AUDIO, | ||
383 | .config_props = config_input, | ||
384 | }, | ||
385 | }; | ||
386 | |||
387 | const FFFilter ff_af_atrim = { | ||
388 | .p.name = "atrim", | ||
389 | .p.description = NULL_IF_CONFIG_SMALL("Pick one continuous section from the input, drop the rest."), | ||
390 | .p.priv_class = &atrim_class, | ||
391 | .p.flags = AVFILTER_FLAG_METADATA_ONLY, | ||
392 | .init = init, | ||
393 | .activate = activate, | ||
394 | .priv_size = sizeof(TrimContext), | ||
395 | FILTER_INPUTS(atrim_inputs), | ||
396 | FILTER_OUTPUTS(ff_audio_default_filterpad), | ||
397 | }; | ||
398 | #endif // CONFIG_ATRIM_FILTER | ||
399 |