Browse code

lavf: deprecate AVFormatContext.timestamp

It's replaced by 'creation_time' metadata tag.

Anton Khirnov authored on 2011/07/07 18:25:03
Showing 7 changed files
... ...
@@ -183,7 +183,6 @@ static float mux_max_delay= 0.7;
183 183
 
184 184
 static int64_t recording_time = INT64_MAX;
185 185
 static int64_t start_time = 0;
186
-static int64_t recording_timestamp = 0;
187 186
 static int64_t input_ts_offset = 0;
188 187
 static int file_overwrite = 0;
189 188
 static AVDictionary *metadata;
... ...
@@ -712,9 +711,6 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename)
712 712
             nopts = 1;
713 713
     }
714 714
 
715
-    if (!nopts)
716
-        s->timestamp = av_gettime();
717
-
718 715
     av_close_input_file(ic);
719 716
     return 0;
720 717
 }
... ...
@@ -3109,7 +3105,14 @@ static int opt_start_time(const char *opt, const char *arg)
3109 3109
 
3110 3110
 static int opt_recording_timestamp(const char *opt, const char *arg)
3111 3111
 {
3112
-    recording_timestamp = parse_time_or_die(opt, arg, 0) / 1000000;
3112
+    char buf[128];
3113
+    int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
3114
+    struct tm time = *gmtime((time_t*)&recording_timestamp);
3115
+    strftime(buf, sizeof(buf), "creation_time=%FT%T%z", &time);
3116
+    opt_metadata("metadata", buf);
3117
+
3118
+    av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
3119
+                                 "tag instead.\n", opt);
3113 3120
     return 0;
3114 3121
 }
3115 3122
 
... ...
@@ -3823,8 +3826,6 @@ static void opt_output_file(const char *filename)
3823 3823
         if (use_subtitle) new_subtitle_stream(oc, nb_output_files);
3824 3824
         if (use_data)     new_data_stream(oc, nb_output_files);
3825 3825
 
3826
-        oc->timestamp = recording_timestamp;
3827
-
3828 3826
         av_dict_copy(&oc->metadata, metadata, 0);
3829 3827
         av_dict_free(&metadata);
3830 3828
     }
... ...
@@ -674,7 +674,12 @@ typedef struct AVFormatContext {
674 674
     AVStream **streams;
675 675
     char filename[1024]; /**< input or output filename */
676 676
     /* stream info */
677
-    int64_t timestamp;
677
+#if FF_API_TIMESTAMP
678
+    /**
679
+     * @deprecated use 'creation_time' metadata tag instead
680
+     */
681
+    attribute_deprecated int64_t timestamp;
682
+#endif
678 683
 
679 684
     int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
680 685
     /* private data for pts handling (do not modify directly). */
... ...
@@ -43,7 +43,7 @@ struct DVMuxContext {
43 43
     AVStream         *ast[2];        /* stereo audio streams */
44 44
     AVFifoBuffer     *audio_data[2]; /* FIFO for storing excessive amounts of PCM */
45 45
     int               frames;        /* current frame number */
46
-    time_t            start_time;    /* recording start time */
46
+    int64_t           start_time;    /* recording start time */
47 47
     int               has_audio;     /* frame under contruction has audio */
48 48
     int               has_video;     /* frame under contruction has video */
49 49
     uint8_t           frame_buf[DV_MAX_FRAME_SIZE]; /* frame under contruction */
... ...
@@ -290,6 +290,7 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
290 290
 {
291 291
     DVMuxContext *c = s->priv_data;
292 292
     AVStream *vst = NULL;
293
+    AVDictionaryEntry *t;
293 294
     int i;
294 295
 
295 296
     /* we support at most 1 video and 2 audio streams */
... ...
@@ -337,7 +338,16 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
337 337
     c->frames     = 0;
338 338
     c->has_audio  = 0;
339 339
     c->has_video  = 0;
340
-    c->start_time = (time_t)s->timestamp;
340
+#if FF_API_TIMESTAMP
341
+    if (s->timestamp)
342
+        c->start_time = s->timestamp;
343
+    else
344
+#endif
345
+    if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
346
+        struct tm time = {0};
347
+        strptime(t->value, "%Y - %m - %dT%T", &time);
348
+        c->start_time = mktime(&time);
349
+    }
341 350
 
342 351
     for (i=0; i < c->n_ast; i++) {
343 352
         if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(100*AVCODEC_MAX_AUDIO_FRAME_SIZE))) {
... ...
@@ -394,6 +394,20 @@ static int gxf_write_umf_material_description(AVFormatContext *s)
394 394
     GXFContext *gxf = s->priv_data;
395 395
     AVIOContext *pb = s->pb;
396 396
     int timecode_base = gxf->time_base.den == 60000 ? 60 : 50;
397
+    int64_t timestamp = 0;
398
+    AVDictionaryEntry *t;
399
+
400
+#if FF_API_TIMESTAMP
401
+    if (s->timestamp)
402
+        timestamp = s->timestamp;
403
+    else
404
+#endif
405
+    if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
406
+        struct tm time = {0};
407
+        strptime(t->value, "%Y - %m - %dT%T", &time);
408
+        timestamp = mktime(&time);
409
+    }
410
+
397 411
 
398 412
     // XXX drop frame
399 413
     uint32_t timecode =
... ...
@@ -409,8 +423,8 @@ static int gxf_write_umf_material_description(AVFormatContext *s)
409 409
     avio_wl32(pb, gxf->nb_fields); /* mark out */
410 410
     avio_wl32(pb, 0); /* timecode mark in */
411 411
     avio_wl32(pb, timecode); /* timecode mark out */
412
-    avio_wl64(pb, s->timestamp); /* modification time */
413
-    avio_wl64(pb, s->timestamp); /* creation time */
412
+    avio_wl64(pb, timestamp); /* modification time */
413
+    avio_wl64(pb, timestamp); /* creation time */
414 414
     avio_wl16(pb, 0); /* reserved */
415 415
     avio_wl16(pb, 0); /* reserved */
416 416
     avio_wl16(pb, gxf->audio_tracks);
... ...
@@ -2129,6 +2129,7 @@ static int mov_write_header(AVFormatContext *s)
2129 2129
 {
2130 2130
     AVIOContext *pb = s->pb;
2131 2131
     MOVMuxContext *mov = s->priv_data;
2132
+    AVDictionaryEntry *t;
2132 2133
     int i, hint_track = 0;
2133 2134
 
2134 2135
     if (!s->pb->seekable) {
... ...
@@ -2259,7 +2260,18 @@ static int mov_write_header(AVFormatContext *s)
2259 2259
     }
2260 2260
 
2261 2261
     mov_write_mdat_tag(pb, mov);
2262
-    mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based
2262
+
2263
+#if FF_API_TIMESTAMP
2264
+    if (s->timestamp)
2265
+        mov->time = s->timestamp;
2266
+    else
2267
+#endif
2268
+    if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
2269
+        struct tm time = {0};
2270
+        strptime(t->value, "%Y - %m - %dT%T", &time);
2271
+        mov->time = mktime(&time);
2272
+    }
2273
+    mov->time += 0x7C25B080; //1970 based -> 1904 based
2263 2274
 
2264 2275
     if (mov->chapter_track)
2265 2276
         mov_create_chapter_track(s, mov->chapter_track);
... ...
@@ -1407,6 +1407,8 @@ static int mxf_write_header(AVFormatContext *s)
1407 1407
     int i;
1408 1408
     uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
1409 1409
     const int *samples_per_frame = NULL;
1410
+    AVDictionaryEntry *t;
1411
+    int64_t timestamp = 0;
1410 1412
 
1411 1413
     if (!s->nb_streams)
1412 1414
         return -1;
... ...
@@ -1512,8 +1514,18 @@ static int mxf_write_header(AVFormatContext *s)
1512 1512
         sc->order = AV_RB32(sc->track_essence_element_key+12);
1513 1513
     }
1514 1514
 
1515
+#if FF_API_TIMESTAMP
1515 1516
     if (s->timestamp)
1516
-        mxf->timestamp = mxf_parse_timestamp(s->timestamp);
1517
+        timestamp = s->timestamp;
1518
+    else
1519
+#endif
1520
+    if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
1521
+        struct tm time = {0};
1522
+        strptime(t->value, "%Y - %m - %dT%T", &time);
1523
+        timestamp = mktime(&time);
1524
+    }
1525
+    if (timestamp)
1526
+        mxf->timestamp = mxf_parse_timestamp(timestamp);
1517 1527
     mxf->duration = -1;
1518 1528
 
1519 1529
     mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
... ...
@@ -83,5 +83,8 @@
83 83
 #ifndef FF_API_LOOP_OUTPUT
84 84
 #define FF_API_LOOP_OUTPUT             (LIBAVFORMAT_VERSION_MAJOR < 54)
85 85
 #endif
86
+#ifndef FF_API_TIMESTAMP
87
+#define FF_API_TIMESTAMP               (LIBAVFORMAT_VERSION_MAJOR < 54)
88
+#endif
86 89
 
87 90
 #endif /* AVFORMAT_VERSION_H */