| 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 | 2082 | static av_cold int init(AVFilterContext *ctx) | |
| 77 | { | ||
| 78 | 2082 | TrimContext *s = ctx->priv; | |
| 79 | |||
| 80 | 2082 | s->first_pts = AV_NOPTS_VALUE; | |
| 81 | |||
| 82 | 2082 | return 0; | |
| 83 | } | ||
| 84 | |||
| 85 | #if CONFIG_TRIM_FILTER | ||
| 86 | 32898 | static int trim_filter_frame(AVFilterLink *inlink, AVFrame *frame) | |
| 87 | { | ||
| 88 | 32898 | AVFilterContext *ctx = inlink->dst; | |
| 89 | 32898 | 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 32898 times.
|
32898 | if (s->eof) |
| 94 | ✗ | return 0; | |
| 95 | |||
| 96 |
4/4✓ Branch 0 taken 32876 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 157 times.
✓ Branch 3 taken 32719 times.
|
32898 | if (s->start_frame >= 0 || s->start_pts != AV_NOPTS_VALUE) { |
| 97 | 179 | drop = 1; | |
| 98 |
4/4✓ Branch 0 taken 22 times.
✓ Branch 1 taken 157 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 4 times.
|
179 | if (s->start_frame >= 0 && s->nb_frames >= s->start_frame) |
| 99 | 18 | drop = 0; | |
| 100 |
3/4✓ Branch 0 taken 168 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
|
179 | if (s->start_pts != AV_NOPTS_VALUE && frame->pts != AV_NOPTS_VALUE && |
| 101 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 15 times.
|
168 | frame->pts >= s->start_pts) |
| 102 | 153 | drop = 0; | |
| 103 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 165 times.
|
179 | if (drop) |
| 104 | 14 | goto drop; | |
| 105 | } | ||
| 106 | |||
| 107 |
3/4✓ Branch 0 taken 1240 times.
✓ Branch 1 taken 31644 times.
✓ Branch 2 taken 1240 times.
✗ Branch 3 not taken.
|
32884 | if (s->first_pts == AV_NOPTS_VALUE && frame->pts != AV_NOPTS_VALUE) |
| 108 | 1240 | s->first_pts = frame->pts; | |
| 109 | |||
| 110 |
6/6✓ Branch 0 taken 32866 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 32863 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 32721 times.
✓ Branch 5 taken 142 times.
|
32884 | if (s->end_frame != INT64_MAX || s->end_pts != AV_NOPTS_VALUE || s->duration_tb) { |
| 111 | 32742 | drop = 1; | |
| 112 | |||
| 113 |
4/4✓ Branch 0 taken 18 times.
✓ Branch 1 taken 32724 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
|
32742 | 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 32729 times.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
|
32742 | 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 32721 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 32721 times.
✗ Branch 3 not taken.
|
32742 | if (s->duration_tb && frame->pts != AV_NOPTS_VALUE && |
| 119 |
2/2✓ Branch 0 taken 31496 times.
✓ Branch 1 taken 1225 times.
|
32721 | frame->pts - s->first_pts < s->duration_tb) |
| 120 | 31496 | drop = 0; | |
| 121 | |||
| 122 |
2/2✓ Branch 0 taken 1228 times.
✓ Branch 1 taken 31514 times.
|
32742 | if (drop) { |
| 123 | 1228 | s->eof = 1; | |
| 124 | 1228 | ff_inlink_set_status(inlink, AVERROR_EOF); | |
| 125 | 1228 | ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, frame->pts); | |
| 126 | 1228 | goto drop; | |
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | 31656 | s->nb_frames++; | |
| 131 | |||
| 132 | 31656 | return 1; | |
| 133 | |||
| 134 | 1242 | drop: | |
| 135 | 1242 | s->nb_frames++; | |
| 136 | 1242 | return 0; | |
| 137 | } | ||
| 138 | #endif // CONFIG_TRIM_FILTER | ||
| 139 | |||
| 140 | #if CONFIG_ATRIM_FILTER | ||
| 141 | 11313 | static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame) | |
| 142 | { | ||
| 143 | 11313 | AVFilterContext *ctx = inlink->dst; | |
| 144 | 11313 | 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 11313 times.
|
11313 | if (s->eof) |
| 151 | ✗ | return 0; | |
| 152 | |||
| 153 |
1/2✓ Branch 0 taken 11313 times.
✗ Branch 1 not taken.
|
11313 | if (frame->pts != AV_NOPTS_VALUE) |
| 154 | 11313 | pts = av_rescale_q(frame->pts, inlink->time_base, | |
| 155 | 11313 | (AVRational){ 1, inlink->sample_rate }); | |
| 156 | else | ||
| 157 | ✗ | pts = s->next_pts; | |
| 158 | 11313 | 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 11308 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 9104 times.
✓ Branch 3 taken 2204 times.
|
11313 | if (s->start_sample < 0 && s->start_pts == AV_NOPTS_VALUE) { |
| 162 | 9104 | start_sample = 0; | |
| 163 | } else { | ||
| 164 | 2209 | drop = 1; | |
| 165 | 2209 | start_sample = frame->nb_samples; | |
| 166 | |||
| 167 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2204 times.
|
2209 | 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 2207 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2207 times.
✗ Branch 3 not taken.
|
2209 | if (s->start_pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && |
| 174 |
2/2✓ Branch 0 taken 1883 times.
✓ Branch 1 taken 324 times.
|
2207 | pts + frame->nb_samples > s->start_pts) { |
| 175 | 1883 | drop = 0; | |
| 176 | 1883 | start_sample = FFMIN(start_sample, s->start_pts - pts); | |
| 177 | } | ||
| 178 | |||
| 179 |
2/2✓ Branch 0 taken 324 times.
✓ Branch 1 taken 1885 times.
|
2209 | if (drop) |
| 180 | 324 | goto drop; | |
| 181 | } | ||
| 182 | |||
| 183 |
2/2✓ Branch 0 taken 497 times.
✓ Branch 1 taken 10492 times.
|
10989 | if (s->first_pts == AV_NOPTS_VALUE) |
| 184 | 497 | 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 5735 times.
✓ Branch 1 taken 5254 times.
✓ Branch 2 taken 5715 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 1875 times.
✓ Branch 5 taken 3840 times.
|
10989 | if (s->end_sample == INT64_MAX && s->end_pts == AV_NOPTS_VALUE && !s->duration_tb) { |
| 188 | 1875 | end_sample = frame->nb_samples; | |
| 189 | } else { | ||
| 190 | 9114 | drop = 1; | |
| 191 | 9114 | end_sample = 0; | |
| 192 | |||
| 193 |
2/2✓ Branch 0 taken 5254 times.
✓ Branch 1 taken 3860 times.
|
9114 | 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 9091 times.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
|
9114 | 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 3840 times.
✓ Branch 1 taken 5274 times.
✓ Branch 2 taken 3706 times.
✓ Branch 3 taken 134 times.
|
9114 | if (s->duration_tb && pts - s->first_pts < s->duration_tb) { |
| 206 | 3706 | drop = 0; | |
| 207 | 3706 | end_sample = FFMAX(end_sample, s->first_pts + s->duration_tb - pts); | |
| 208 | } | ||
| 209 | |||
| 210 |
2/2✓ Branch 0 taken 473 times.
✓ Branch 1 taken 8641 times.
|
9114 | if (drop) { |
| 211 | 473 | s->eof = 1; | |
| 212 | 473 | ff_inlink_set_status(inlink, AVERROR_EOF); | |
| 213 | 473 | ff_outlink_set_status(ctx->outputs[0], AVERROR_EOF, frame->pts); | |
| 214 | 473 | goto drop; | |
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | 10516 | s->nb_samples += frame->nb_samples; | |
| 219 | 10516 | start_sample = FFMAX(0, start_sample); | |
| 220 | 10516 | end_sample = FFMIN(frame->nb_samples, end_sample); | |
| 221 |
2/4✓ Branch 0 taken 10516 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10516 times.
|
10516 | if (start_sample >= end_sample || !frame->nb_samples) |
| 222 | ✗ | goto drop; | |
| 223 | |||
| 224 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 10510 times.
|
10516 | 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 | 10510 | frame->nb_samples = end_sample; | |
| 242 | |||
| 243 | 10516 | return 1; | |
| 244 | |||
| 245 | 797 | drop: | |
| 246 | 797 | s->nb_samples += frame->nb_samples; | |
| 247 | 797 | return 0; | |
| 248 | } | ||
| 249 | #endif // CONFIG_ATRIM_FILTER | ||
| 250 | |||
| 251 | 1737 | static int config_input(AVFilterLink *inlink) | |
| 252 | { | ||
| 253 | 1737 | AVFilterContext *ctx = inlink->dst; | |
| 254 | 1737 | TrimContext *s = ctx->priv; | |
| 255 | 1240 | AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ? | |
| 256 |
2/2✓ Branch 0 taken 1240 times.
✓ Branch 1 taken 497 times.
|
1737 | inlink->time_base : (AVRational){ 1, inlink->sample_rate }; |
| 257 | |||
| 258 | #if CONFIG_TRIM_FILTER | ||
| 259 |
2/2✓ Branch 0 taken 1240 times.
✓ Branch 1 taken 497 times.
|
1737 | if (inlink->type == AVMEDIA_TYPE_VIDEO) |
| 260 | 1240 | s->filter_frame = trim_filter_frame; | |
| 261 | #endif | ||
| 262 | #if CONFIG_ATRIM_FILTER | ||
| 263 |
2/2✓ Branch 0 taken 497 times.
✓ Branch 1 taken 1240 times.
|
1737 | if (inlink->type == AVMEDIA_TYPE_AUDIO) |
| 264 | 497 | s->filter_frame = atrim_filter_frame; | |
| 265 | #endif | ||
| 266 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 1704 times.
|
1737 | if (s->start_time != INT64_MAX) { |
| 267 | 33 | 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 33 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
33 | if (s->start_pts == AV_NOPTS_VALUE || start_pts < s->start_pts) |
| 269 | 33 | s->start_pts = start_pts; | |
| 270 | } | ||
| 271 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1732 times.
|
1737 | 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 1368 times.
✓ Branch 1 taken 369 times.
|
1737 | if (s->duration) |
| 277 | 1368 | s->duration_tb = av_rescale_q(s->duration, AV_TIME_BASE_Q, tb); | |
| 278 | |||
| 279 | 1737 | return 0; | |
| 280 | } | ||
| 281 | |||
| 282 | 88687 | static int activate(AVFilterContext *ctx) | |
| 283 | { | ||
| 284 | 88687 | TrimContext *s = ctx->priv; | |
| 285 | 88687 | AVFilterLink *inlink = ctx->inputs[0]; | |
| 286 | 88687 | AVFilterLink *outlink = ctx->outputs[0]; | |
| 287 | 88687 | AVFrame *frame = NULL; | |
| 288 | int ret; | ||
| 289 | |||
| 290 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 2 taken 88674 times.
|
88687 | FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); |
| 291 | |||
| 292 |
2/2✓ Branch 1 taken 44211 times.
✓ Branch 2 taken 46502 times.
|
90713 | while ((ret = ff_inlink_consume_frame(inlink, &frame))) { |
| 293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44211 times.
|
44211 | if (ret < 0) |
| 294 | ✗ | return ret; | |
| 295 | |||
| 296 | 44211 | ret = s->filter_frame(inlink, frame); | |
| 297 |
2/2✓ Branch 0 taken 42172 times.
✓ Branch 1 taken 2039 times.
|
44211 | if (ret > 0) |
| 298 | 42172 | return ff_filter_frame(outlink, frame); | |
| 299 | 2039 | av_frame_free(&frame); | |
| 300 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2039 times.
|
2039 | if (ret < 0) |
| 301 | ✗ | return ret; | |
| 302 | } | ||
| 303 | |||
| 304 |
2/2✓ Branch 1 taken 1718 times.
✓ Branch 2 taken 44784 times.
|
46502 | FF_FILTER_FORWARD_STATUS(inlink, outlink); |
| 305 |
2/2✓ Branch 1 taken 44778 times.
✓ Branch 2 taken 6 times.
|
44784 | 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 |