mirror of https://git.videolan.org/git/ffmpeg.git
lavfi/trim: use AV_OPT_TYPE_DURATION
Workarounds for rounding differences between platforms should not be needed any more. Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
8aea97a49d
commit
b3405b1bda
|
@ -949,11 +949,11 @@ Trim the input so that the output contains one continuous subpart of the input.
|
||||||
This filter accepts the following options:
|
This filter accepts the following options:
|
||||||
@table @option
|
@table @option
|
||||||
@item start
|
@item start
|
||||||
Timestamp (in seconds) of the start of the kept section. I.e. the audio sample
|
Specify time of the start of the kept section, i.e. the audio sample
|
||||||
with the timestamp @var{start} will be the first sample in the output.
|
with the timestamp @var{start} will be the first sample in the output.
|
||||||
|
|
||||||
@item end
|
@item end
|
||||||
Timestamp (in seconds) of the first audio sample that will be dropped. I.e. the
|
Specify time of the first audio sample that will be dropped, i.e. the
|
||||||
audio sample immediately preceding the one with the timestamp @var{end} will be
|
audio sample immediately preceding the one with the timestamp @var{end} will be
|
||||||
the last sample in the output.
|
the last sample in the output.
|
||||||
|
|
||||||
|
@ -966,7 +966,7 @@ Same as @var{end}, except this option sets the end timestamp in samples instead
|
||||||
of seconds.
|
of seconds.
|
||||||
|
|
||||||
@item duration
|
@item duration
|
||||||
Maximum duration of the output in seconds.
|
Specify maximum duration of the output.
|
||||||
|
|
||||||
@item start_sample
|
@item start_sample
|
||||||
Number of the first sample that should be passed to output.
|
Number of the first sample that should be passed to output.
|
||||||
|
@ -975,6 +975,10 @@ Number of the first sample that should be passed to output.
|
||||||
Number of the first sample that should be dropped.
|
Number of the first sample that should be dropped.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@option{start}, @option{end}, @option{duration} are expressed as time
|
||||||
|
duration specifications, check the "Time duration" section in the
|
||||||
|
ffmpeg-utils manual.
|
||||||
|
|
||||||
Note that the first two sets of the start/end options and the @option{duration}
|
Note that the first two sets of the start/end options and the @option{duration}
|
||||||
option look at the frame timestamp, while the _sample options simply count the
|
option look at the frame timestamp, while the _sample options simply count the
|
||||||
samples that pass through the filter. So start/end_pts and start/end_sample will
|
samples that pass through the filter. So start/end_pts and start/end_sample will
|
||||||
|
@ -7066,11 +7070,11 @@ Trim the input so that the output contains one continuous subpart of the input.
|
||||||
This filter accepts the following options:
|
This filter accepts the following options:
|
||||||
@table @option
|
@table @option
|
||||||
@item start
|
@item start
|
||||||
Timestamp (in seconds) of the start of the kept section. I.e. the frame with the
|
Specify time of the start of the kept section, i.e. the frame with the
|
||||||
timestamp @var{start} will be the first frame in the output.
|
timestamp @var{start} will be the first frame in the output.
|
||||||
|
|
||||||
@item end
|
@item end
|
||||||
Timestamp (in seconds) of the first frame that will be dropped. I.e. the frame
|
Specify time of the first frame that will be dropped, i.e. the frame
|
||||||
immediately preceding the one with the timestamp @var{end} will be the last
|
immediately preceding the one with the timestamp @var{end} will be the last
|
||||||
frame in the output.
|
frame in the output.
|
||||||
|
|
||||||
|
@ -7083,7 +7087,7 @@ Same as @var{end}, except this option sets the end timestamp in timebase units
|
||||||
instead of seconds.
|
instead of seconds.
|
||||||
|
|
||||||
@item duration
|
@item duration
|
||||||
Maximum duration of the output in seconds.
|
Specify maximum duration of the output.
|
||||||
|
|
||||||
@item start_frame
|
@item start_frame
|
||||||
Number of the first frame that should be passed to output.
|
Number of the first frame that should be passed to output.
|
||||||
|
@ -7092,6 +7096,10 @@ Number of the first frame that should be passed to output.
|
||||||
Number of the first frame that should be dropped.
|
Number of the first frame that should be dropped.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@option{start}, @option{end}, @option{duration} are expressed as time
|
||||||
|
duration specifications, check the "Time duration" section in the
|
||||||
|
ffmpeg-utils manual.
|
||||||
|
|
||||||
Note that the first two sets of the start/end options and the @option{duration}
|
Note that the first two sets of the start/end options and the @option{duration}
|
||||||
option look at the frame timestamp, while the _frame variants simply count the
|
option look at the frame timestamp, while the _frame variants simply count the
|
||||||
frames that pass through the filter. Also note that this filter does not modify
|
frames that pass through the filter. Also note that this filter does not modify
|
||||||
|
|
|
@ -16,9 +16,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <float.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "libavutil/avassert.h"
|
#include "libavutil/avassert.h"
|
||||||
|
@ -39,8 +36,8 @@ typedef struct TrimContext {
|
||||||
/*
|
/*
|
||||||
* AVOptions
|
* AVOptions
|
||||||
*/
|
*/
|
||||||
double duration;
|
int64_t duration;
|
||||||
double start_time, end_time;
|
int64_t start_time, end_time;
|
||||||
int64_t start_frame, end_frame;
|
int64_t start_frame, end_frame;
|
||||||
/*
|
/*
|
||||||
* in the link timebase for video,
|
* in the link timebase for video,
|
||||||
|
@ -87,18 +84,18 @@ static int config_input(AVFilterLink *inlink)
|
||||||
AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ?
|
AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ?
|
||||||
inlink->time_base : (AVRational){ 1, inlink->sample_rate };
|
inlink->time_base : (AVRational){ 1, inlink->sample_rate };
|
||||||
|
|
||||||
if (s->start_time != DBL_MAX) {
|
if (s->start_time != INT64_MAX) {
|
||||||
int64_t start_pts = lrint(s->start_time / av_q2d(tb));
|
int64_t start_pts = av_rescale_q(s->start_time, AV_TIME_BASE_Q, tb);
|
||||||
if (s->start_pts == AV_NOPTS_VALUE || start_pts < s->start_pts)
|
if (s->start_pts == AV_NOPTS_VALUE || start_pts < s->start_pts)
|
||||||
s->start_pts = start_pts;
|
s->start_pts = start_pts;
|
||||||
}
|
}
|
||||||
if (s->end_time != DBL_MAX) {
|
if (s->end_time != INT64_MAX) {
|
||||||
int64_t end_pts = lrint(s->end_time / av_q2d(tb));
|
int64_t end_pts = av_rescale_q(s->end_time, AV_TIME_BASE_Q, tb);
|
||||||
if (s->end_pts == AV_NOPTS_VALUE || end_pts > s->end_pts)
|
if (s->end_pts == AV_NOPTS_VALUE || end_pts > s->end_pts)
|
||||||
s->end_pts = end_pts;
|
s->end_pts = end_pts;
|
||||||
}
|
}
|
||||||
if (s->duration)
|
if (s->duration)
|
||||||
s->duration_tb = lrint(s->duration / av_q2d(tb));
|
s->duration_tb = av_rescale_q(s->duration, AV_TIME_BASE_Q, tb);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -111,15 +108,15 @@ static int config_output(AVFilterLink *outlink)
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(TrimContext, x)
|
#define OFFSET(x) offsetof(TrimContext, x)
|
||||||
#define COMMON_OPTS \
|
#define COMMON_OPTS \
|
||||||
{ "start", "Timestamp in seconds of the first frame that " \
|
{ "start", "Timestamp of the first frame that " \
|
||||||
"should be passed", OFFSET(start_time), AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX }, -DBL_MAX, DBL_MAX, FLAGS }, \
|
"should be passed", OFFSET(start_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
|
||||||
{ "end", "Timestamp in seconds of the first frame that " \
|
{ "end", "Timestamp of the first frame that " \
|
||||||
"should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX }, -DBL_MAX, DBL_MAX, FLAGS }, \
|
"should be dropped again", OFFSET(end_time), AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX }, INT64_MIN, INT64_MAX, FLAGS }, \
|
||||||
{ "start_pts", "Timestamp of the first frame that should be " \
|
{ "start_pts", "Timestamp of the first frame that should be " \
|
||||||
" passed", OFFSET(start_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
|
" passed", OFFSET(start_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
|
||||||
{ "end_pts", "Timestamp of the first frame that should be " \
|
{ "end_pts", "Timestamp of the first frame that should be " \
|
||||||
"dropped again", OFFSET(end_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
|
"dropped again", OFFSET(end_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
|
||||||
{ "duration", "Maximum duration of the output in seconds", OFFSET(duration), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, DBL_MAX, FLAGS },
|
{ "duration", "Maximum duration of the output", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, FLAGS },
|
||||||
|
|
||||||
|
|
||||||
#if CONFIG_TRIM_FILTER
|
#if CONFIG_TRIM_FILTER
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
#define LIBAVFILTER_VERSION_MAJOR 3
|
#define LIBAVFILTER_VERSION_MAJOR 3
|
||||||
#define LIBAVFILTER_VERSION_MINOR 80
|
#define LIBAVFILTER_VERSION_MINOR 80
|
||||||
#define LIBAVFILTER_VERSION_MICRO 100
|
#define LIBAVFILTER_VERSION_MICRO 101
|
||||||
|
|
||||||
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
||||||
LIBAVFILTER_VERSION_MINOR, \
|
LIBAVFILTER_VERSION_MINOR, \
|
||||||
|
|
Loading…
Reference in New Issue