Mercurial > libavformat.hg
comparison mxfenc.c @ 4385:e8e064a00ea5 libavformat
format timestamp correctly according to specs and set it
author | bcoudurier |
---|---|
date | Thu, 05 Feb 2009 20:15:18 +0000 |
parents | bfb10be2b631 |
children | 87a896580005 |
comparison
equal
deleted
inserted
replaced
4384:bfb10be2b631 | 4385:e8e064a00ea5 |
---|---|
31 */ | 31 */ |
32 | 32 |
33 //#define DEBUG | 33 //#define DEBUG |
34 | 34 |
35 #include <math.h> | 35 #include <math.h> |
36 #include <time.h> | |
36 | 37 |
37 #include "libavutil/fifo.h" | 38 #include "libavutil/fifo.h" |
38 #include "mxf.h" | 39 #include "mxf.h" |
39 | 40 |
40 static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 }; | 41 static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 }; |
121 AVRational time_base; | 122 AVRational time_base; |
122 int header_written; | 123 int header_written; |
123 MXFIndexEntry *index_entries; | 124 MXFIndexEntry *index_entries; |
124 unsigned edit_units_count; | 125 unsigned edit_units_count; |
125 int edit_unit_start; ///< index of the stream starting edit unit | 126 int edit_unit_start; ///< index of the stream starting edit unit |
127 uint64_t timestamp; ///< timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8) | |
126 } MXFContext; | 128 } MXFContext; |
127 | 129 |
128 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; | 130 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; |
129 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13,0x00,0x00,0x00 }; | 131 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13,0x00,0x00,0x00 }; |
130 | 132 |
357 // write preface set uid | 359 // write preface set uid |
358 mxf_write_local_tag(pb, 16, 0x3C0A); | 360 mxf_write_local_tag(pb, 16, 0x3C0A); |
359 mxf_write_uuid(pb, Preface, 0); | 361 mxf_write_uuid(pb, Preface, 0); |
360 PRINT_KEY(s, "preface uid", pb->buf_ptr - 16); | 362 PRINT_KEY(s, "preface uid", pb->buf_ptr - 16); |
361 | 363 |
362 // write creation date | 364 // last modified date |
363 mxf_write_local_tag(pb, 8, 0x3B02); | 365 mxf_write_local_tag(pb, 8, 0x3B02); |
364 put_be64(pb, s->timestamp); | 366 put_be64(pb, mxf->timestamp); |
365 | 367 |
366 // write version | 368 // write version |
367 mxf_write_local_tag(pb, 2, 0x3B05); | 369 mxf_write_local_tag(pb, 2, 0x3B05); |
368 put_be16(pb, 1); | 370 put_be16(pb, 1); |
369 | 371 |
399 put_be16(pb, value[i]); | 401 put_be16(pb, value[i]); |
400 } | 402 } |
401 | 403 |
402 static void mxf_write_identification(AVFormatContext *s) | 404 static void mxf_write_identification(AVFormatContext *s) |
403 { | 405 { |
406 MXFContext *mxf = s->priv_data; | |
404 ByteIOContext *pb = s->pb; | 407 ByteIOContext *pb = s->pb; |
405 const char *company = "FFmpeg"; | 408 const char *company = "FFmpeg"; |
406 const char *product = "OP1a Muxer"; | 409 const char *product = "OP1a Muxer"; |
407 const char *version; | 410 const char *version; |
408 int length; | 411 int length; |
432 mxf_write_local_tag(pb, 16, 0x3C05); | 435 mxf_write_local_tag(pb, 16, 0x3C05); |
433 mxf_write_uuid(pb, Identification, 2); | 436 mxf_write_uuid(pb, Identification, 2); |
434 | 437 |
435 // modification date | 438 // modification date |
436 mxf_write_local_tag(pb, 8, 0x3C06); | 439 mxf_write_local_tag(pb, 8, 0x3C06); |
437 put_be64(pb, s->timestamp); | 440 put_be64(pb, mxf->timestamp); |
438 } | 441 } |
439 | 442 |
440 static void mxf_write_content_storage(AVFormatContext *s) | 443 static void mxf_write_content_storage(AVFormatContext *s) |
441 { | 444 { |
442 ByteIOContext *pb = s->pb; | 445 ByteIOContext *pb = s->pb; |
740 mxf_write_wav_common_desc(s, st, mxf_aes3_descriptor_key, 107); | 743 mxf_write_wav_common_desc(s, st, mxf_aes3_descriptor_key, 107); |
741 } | 744 } |
742 | 745 |
743 static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type) | 746 static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type) |
744 { | 747 { |
748 MXFContext *mxf = s->priv_data; | |
745 ByteIOContext *pb = s->pb; | 749 ByteIOContext *pb = s->pb; |
746 int i; | 750 int i; |
747 | 751 |
748 if (type == MaterialPackage) { | 752 if (type == MaterialPackage) { |
749 mxf_write_metadata_key(pb, 0x013600); | 753 mxf_write_metadata_key(pb, 0x013600); |
764 // write package umid | 768 // write package umid |
765 mxf_write_local_tag(pb, 32, 0x4401); | 769 mxf_write_local_tag(pb, 32, 0x4401); |
766 mxf_write_umid(pb, type, 0); | 770 mxf_write_umid(pb, type, 0); |
767 PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16); | 771 PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16); |
768 | 772 |
769 // write create date | 773 // package creation date |
770 mxf_write_local_tag(pb, 8, 0x4405); | 774 mxf_write_local_tag(pb, 8, 0x4405); |
771 put_be64(pb, 0); | 775 put_be64(pb, mxf->timestamp); |
772 | 776 |
773 // write modified date | 777 // package modified date |
774 mxf_write_local_tag(pb, 8, 0x4404); | 778 mxf_write_local_tag(pb, 8, 0x4404); |
775 put_be64(pb, 0); | 779 put_be64(pb, mxf->timestamp); |
776 | 780 |
777 // write track refs | 781 // write track refs |
778 mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x4403); | 782 mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x4403); |
779 mxf_write_refs_count(pb, s->nb_streams); | 783 mxf_write_refs_count(pb, s->nb_streams); |
780 for (i = 0; i < s->nb_streams; i++) | 784 for (i = 0; i < s->nb_streams; i++) |
1114 if (st->codec->codec_type == CODEC_TYPE_AUDIO) | 1118 if (st->codec->codec_type == CODEC_TYPE_AUDIO) |
1115 av_fifo_free(&aic->fifo); | 1119 av_fifo_free(&aic->fifo); |
1116 } | 1120 } |
1117 } | 1121 } |
1118 | 1122 |
1123 static uint64_t mxf_parse_timestamp(time_t timestamp) | |
1124 { | |
1125 struct tm *time = localtime(×tamp); | |
1126 return (uint64_t)(time->tm_year+1900) << 48 | | |
1127 (uint64_t)(time->tm_mon+1) << 40 | | |
1128 (uint64_t) time->tm_mday << 32 | | |
1129 time->tm_hour << 24 | | |
1130 time->tm_min << 16 | | |
1131 time->tm_sec << 8; | |
1132 } | |
1133 | |
1119 static int mxf_write_header(AVFormatContext *s) | 1134 static int mxf_write_header(AVFormatContext *s) |
1120 { | 1135 { |
1121 MXFContext *mxf = s->priv_data; | 1136 MXFContext *mxf = s->priv_data; |
1122 int i; | 1137 int i; |
1123 uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; | 1138 uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; |
1180 MXFStreamContext *sc = s->streams[i]->priv_data; | 1195 MXFStreamContext *sc = s->streams[i]->priv_data; |
1181 // update element count | 1196 // update element count |
1182 sc->track_essence_element_key[13] = present[sc->index]; | 1197 sc->track_essence_element_key[13] = present[sc->index]; |
1183 sc->order = AV_RB32(sc->track_essence_element_key+12); | 1198 sc->order = AV_RB32(sc->track_essence_element_key+12); |
1184 } | 1199 } |
1200 | |
1201 mxf->timestamp = mxf_parse_timestamp(s->timestamp); | |
1185 | 1202 |
1186 if (!samples_per_frame) | 1203 if (!samples_per_frame) |
1187 samples_per_frame = PAL_samples_per_frame; | 1204 samples_per_frame = PAL_samples_per_frame; |
1188 | 1205 |
1189 if (ff_audio_interleave_init(s, samples_per_frame, mxf->time_base) < 0) | 1206 if (ff_audio_interleave_init(s, samples_per_frame, mxf->time_base) < 0) |