Browse code

lavf/segment: make use of av_parse_time() when parsing the -segment_time value

Increase flexibility/consistency.

Also rename recording_time field to time, for enhanced
consistency/readability.

Stefano Sabatini authored on 2012/07/09 00:26:33
Showing 3 changed files
... ...
@@ -472,8 +472,8 @@ the segment start and end time expressed in seconds.
472 472
 @end table
473 473
 
474 474
 Default value is "flat".
475
-@item segment_time @var{t}
476
-Set segment duration to @var{t} seconds. Default value is 2.
475
+@item segment_time @var{time}
476
+Set segment duration to @var{time}. Default value is "2".
477 477
 @item segment_wrap @var{limit}
478 478
 Wrap around segment index once it reaches @var{limit}.
479 479
 @end table
... ...
@@ -45,9 +45,9 @@ typedef struct {
45 45
     int   list_size;       ///< number of entries for the segment list file
46 46
     ListType list_type;    ///< set the list type
47 47
     AVIOContext *list_pb;  ///< list file put-byte context
48
-    float time;            ///< segment duration
49 48
     int  wrap;             ///< number after which the index wraps
50
-    int64_t recording_time;
49
+    char *time_str;        ///< segment duration specification string
50
+    int64_t time;          ///< segment duration
51 51
     int has_video;
52 52
     double start_time, end_time;
53 53
 } SegmentContext;
... ...
@@ -143,7 +143,13 @@ static int seg_write_header(AVFormatContext *s)
143 143
     int ret, i;
144 144
 
145 145
     seg->number = 0;
146
-    seg->recording_time = seg->time * 1000000;
146
+
147
+    if ((ret = av_parse_time(&seg->time, seg->time_str, 1)) < 0) {
148
+        av_log(s, AV_LOG_ERROR,
149
+               "Invalid time duration specification '%s' for segment_time option\n",
150
+               seg->time_str);
151
+        return ret;
152
+    }
147 153
 
148 154
     oc = avformat_alloc_context();
149 155
 
... ...
@@ -215,7 +221,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
215 215
     SegmentContext *seg = s->priv_data;
216 216
     AVFormatContext *oc = seg->avf;
217 217
     AVStream *st = oc->streams[pkt->stream_index];
218
-    int64_t end_pts = seg->recording_time * seg->number;
218
+    int64_t end_pts = seg->time * seg->number;
219 219
     int ret;
220 220
 
221 221
     /* if the segment has video, start a new segment *only* with a key video frame */
... ...
@@ -256,6 +262,9 @@ static int seg_write_trailer(struct AVFormatContext *s)
256 256
     int ret = segment_end(s);
257 257
     if (seg->list)
258 258
         avio_close(seg->list_pb);
259
+
260
+    av_opt_free(seg);
261
+
259 262
     oc->streams = NULL;
260 263
     oc->nb_streams = 0;
261 264
     avformat_free_context(oc);
... ...
@@ -266,7 +275,7 @@ static int seg_write_trailer(struct AVFormatContext *s)
266 266
 #define E AV_OPT_FLAG_ENCODING_PARAM
267 267
 static const AVOption options[] = {
268 268
     { "segment_format",    "set container format used for the segments", OFFSET(format),  AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E },
269
-    { "segment_time",      "set segment length in seconds",              OFFSET(time),    AV_OPT_TYPE_FLOAT,  {.dbl = 2},     0, FLT_MAX, E },
269
+    { "segment_time",      "set segment duration",                       OFFSET(time_str),AV_OPT_TYPE_STRING, {.str = "2"},   0, 0,       E },
270 270
     { "segment_list",      "set the segment list filename",              OFFSET(list),    AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E },
271 271
     { "segment_list_size", "set the maximum number of playlist entries", OFFSET(list_size), AV_OPT_TYPE_INT,  {.dbl = 5},     0, INT_MAX, E },
272 272
     { "segment_list_type", "set the segment list type",                  OFFSET(list_type), AV_OPT_TYPE_INT,  {.dbl = LIST_TYPE_FLAT}, 0, LIST_TYPE_NB-1, E, "list_type" },
... ...
@@ -31,7 +31,7 @@
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 54
33 33
 #define LIBAVFORMAT_VERSION_MINOR 15
34
-#define LIBAVFORMAT_VERSION_MICRO 101
34
+#define LIBAVFORMAT_VERSION_MICRO 102
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
                                                LIBAVFORMAT_VERSION_MINOR, \