Browse code

avfilter/trim: add compatibility layer to not break ABI used by ffmpeg

This is a hotfix to fix -t / -ss
a different solution might be choosen later, i just dont want to leave
this broken

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/07/13 04:21:29
Showing 1 changed files
... ...
@@ -16,6 +16,9 @@
16 16
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 17
  */
18 18
 
19
+#include <float.h>
20
+#include <math.h>
21
+
19 22
 #include "config.h"
20 23
 
21 24
 #include "libavutil/avassert.h"
... ...
@@ -39,6 +42,9 @@ typedef struct TrimContext {
39 39
     int64_t duration;
40 40
     int64_t start_time, end_time;
41 41
     int64_t start_frame, end_frame;
42
+
43
+    double duration_dbl;
44
+    double start_time_dbl, end_time_dbl;
42 45
     /*
43 46
      * in the link timebase for video,
44 47
      * in 1/samplerate for audio
... ...
@@ -84,6 +90,13 @@ static int config_input(AVFilterLink *inlink)
84 84
     AVRational tb = (inlink->type == AVMEDIA_TYPE_VIDEO) ?
85 85
                      inlink->time_base : (AVRational){ 1, inlink->sample_rate };
86 86
 
87
+    if (s->start_time_dbl != DBL_MAX)
88
+        s->start_time = s->start_time_dbl * 1e6;
89
+    if (s->end_time_dbl != DBL_MAX)
90
+        s->end_time = s->end_time_dbl * 1e6;
91
+    if (s->duration_dbl != DBL_MAX)
92
+        s->duration = s->duration_dbl * 1e6;
93
+
87 94
     if (s->start_time != INT64_MAX) {
88 95
         int64_t start_pts = av_rescale_q(s->start_time, AV_TIME_BASE_Q, tb);
89 96
         if (s->start_pts == AV_NOPTS_VALUE || start_pts < s->start_pts)
... ...
@@ -108,15 +121,22 @@ static int config_output(AVFilterLink *outlink)
108 108
 
109 109
 #define OFFSET(x) offsetof(TrimContext, x)
110 110
 #define COMMON_OPTS                                                                                                                                                         \
111
-    { "start",       "Timestamp of the first frame that "                                                                                                        \
111
+    { "starti",      "Timestamp of the first frame that "                                                                                                        \
112 112
         "should be passed",                                              OFFSET(start_time),  AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX },    INT64_MIN, INT64_MAX, FLAGS }, \
113
-    { "end",         "Timestamp of the first frame that "                                                                                                        \
113
+    { "endi",        "Timestamp of the first frame that "                                                                                                        \
114 114
         "should be dropped again",                                       OFFSET(end_time),    AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX },    INT64_MIN, INT64_MAX, FLAGS }, \
115 115
     { "start_pts",   "Timestamp of the first frame that should be "                                                                                                         \
116 116
        " passed",                                                        OFFSET(start_pts),   AV_OPT_TYPE_INT64,  { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
117 117
     { "end_pts",     "Timestamp of the first frame that should be "                                                                                                         \
118 118
         "dropped again",                                                 OFFSET(end_pts),     AV_OPT_TYPE_INT64,  { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS }, \
119
-    { "duration",    "Maximum duration of the output",                   OFFSET(duration),    AV_OPT_TYPE_DURATION, { .i64 = 0 },                    0, INT64_MAX, FLAGS },
119
+    { "durationi",   "Maximum duration of the output",                   OFFSET(duration),    AV_OPT_TYPE_DURATION, { .i64 = 0 },                    0, INT64_MAX, FLAGS },
120
+
121
+#define COMPAT_OPTS \
122
+    { "start",       "Timestamp in seconds of the first frame that "                                                                                                        \
123
+        "should be passed",                                              OFFSET(start_time_dbl),AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX },       -DBL_MAX, DBL_MAX,     FLAGS }, \
124
+    { "end",         "Timestamp in seconds of the first frame that "                                                                                                        \
125
+        "should be dropped again",                                       OFFSET(end_time_dbl),  AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX },       -DBL_MAX, DBL_MAX,     FLAGS }, \
126
+    { "duration",    "Maximum duration of the output in seconds",        OFFSET(duration_dbl),  AV_OPT_TYPE_DOUBLE, { .dbl = 0 },                      0,   DBL_MAX, FLAGS },
120 127
 
121 128
 
122 129
 #if CONFIG_TRIM_FILTER
... ...
@@ -181,6 +201,7 @@ static const AVOption trim_options[] = {
181 181
         "to the output",                                                 OFFSET(start_frame), AV_OPT_TYPE_INT64,  { .i64 = -1 },       -1, INT64_MAX, FLAGS },
182 182
     { "end_frame",   "Number of the first frame that should be dropped "
183 183
         "again",                                                         OFFSET(end_frame),   AV_OPT_TYPE_INT64,  { .i64 = INT64_MAX }, 0, INT64_MAX, FLAGS },
184
+    COMPAT_OPTS
184 185
     { NULL },
185 186
 };
186 187
 #undef FLAGS
... ...
@@ -338,6 +359,7 @@ static const AVOption atrim_options[] = {
338 338
         "passed to the output",                                          OFFSET(start_sample), AV_OPT_TYPE_INT64,  { .i64 = -1 },       -1, INT64_MAX, FLAGS },
339 339
     { "end_sample",   "Number of the first audio sample that should be "
340 340
         "dropped again",                                                 OFFSET(end_sample),   AV_OPT_TYPE_INT64,  { .i64 = INT64_MAX }, 0, INT64_MAX, FLAGS },
341
+    COMPAT_OPTS
341 342
     { NULL },
342 343
 };
343 344
 #undef FLAGS