[FFmpeg-devel] [PATCH] lavfi/trim: use AV_OPT_TYPE_DURATION

Paul B Mahol onemda at gmail.com
Wed Jul 10 20:27:18 CEST 2013


This fixes one of major flaws.

Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 doc/filters.texi   | 48 ++++++++++++++++++++++++++++++++++++++++++------
 libavfilter/trim.c | 24 ++++++++++++------------
 2 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 92f8612..10c407a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -949,13 +949,25 @@ Trim the input so that the output contains one continuous subpart of the input.
 This filter accepts the following options:
 @table @option
 @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.
+The accepted syntax is:
+ at example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+ at end example
+See also the function @code{av_parse_time()}.
 
 @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
 the last sample in the output.
+The accepted syntax is:
+ at example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+ at end example
+See also the function @code{av_parse_time()}.
 
 @item start_pts
 Same as @var{start}, except this option sets the start timestamp in samples
@@ -966,7 +978,13 @@ Same as @var{end}, except this option sets the end timestamp in samples instead
 of seconds.
 
 @item duration
-Maximum duration of the output in seconds.
+Specify maximum duration of the output.
+The accepted syntax is:
+ at example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+ at end example
+See also the function @code{av_parse_time()}.
 
 @item start_sample
 Number of the first sample that should be passed to output.
@@ -7066,13 +7084,25 @@ Trim the input so that the output contains one continuous subpart of the input.
 This filter accepts the following options:
 @table @option
 @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.
+The accepted syntax is:
+ at example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+ at end example
+See also the function @code{av_parse_time()}.
 
 @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
 frame in the output.
+The accepted syntax is:
+ at example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+ at end example
+See also the function @code{av_parse_time()}.
 
 @item start_pts
 Same as @var{start}, except this option sets the start timestamp in timebase
@@ -7083,7 +7113,13 @@ Same as @var{end}, except this option sets the end timestamp in timebase units
 instead of seconds.
 
 @item duration
-Maximum duration of the output in seconds.
+Specify maximum duration of the output.
+The accepted syntax is:
+ at example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+ at end example
+See also the function @code{av_parse_time()}.
 
 @item start_frame
 Number of the first frame that should be passed to output.
diff --git a/libavfilter/trim.c b/libavfilter/trim.c
index 29c7c50..b88a43a 100644
--- a/libavfilter/trim.c
+++ b/libavfilter/trim.c
@@ -39,8 +39,8 @@ typedef struct TrimContext {
     /*
      * AVOptions
      */
-    double duration;
-    double start_time, end_time;
+    int64_t duration;
+    int64_t start_time, end_time;
     int64_t start_frame, end_frame;
     /*
      * in the link timebase for video,
@@ -87,18 +87,18 @@ static int config_input(AVFilterLink *inlink)
     AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ?
                      inlink->time_base : (AVRational){ 1, inlink->sample_rate };
 
-    if (s->start_time != DBL_MAX) {
-        int64_t start_pts = lrint(s->start_time / av_q2d(tb));
+    if (s->start_time != INT64_MAX) {
+        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)
             s->start_pts = start_pts;
     }
-    if (s->end_time != DBL_MAX) {
-        int64_t end_pts = lrint(s->end_time / av_q2d(tb));
+    if (s->end_time != INT64_MAX) {
+        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)
             s->end_pts = end_pts;
     }
     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;
 }
@@ -111,15 +111,15 @@ static int config_output(AVFilterLink *outlink)
 
 #define OFFSET(x) offsetof(TrimContext, x)
 #define COMMON_OPTS                                                                                                                                                         \
-    { "start",       "Timestamp in seconds of the first frame that "                                                                                                        \
-        "should be passed",                                              OFFSET(start_time),  AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX },       -DBL_MAX, DBL_MAX,     FLAGS }, \
-    { "end",         "Timestamp in seconds of the first frame that "                                                                                                        \
-        "should be dropped again",                                       OFFSET(end_time),    AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX },       -DBL_MAX, DBL_MAX,     FLAGS }, \
+    { "start",       "Timestamp of the first frame that "                                                                                                        \
+        "should be passed",                                              OFFSET(start_time),  AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX },    INT64_MIN, INT64_MAX, FLAGS }, \
+    { "end",         "Timestamp of the first frame that "                                                                                                        \
+        "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 "                                                                                                         \
        " 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 "                                                                                                         \
         "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
-- 
1.7.11.2



More information about the ffmpeg-devel mailing list