Mercurial > libavformat.hg
annotate mxfenc.c @ 4696:ee1ca2a4e43f libavformat
attempt to try to generate an random umid
| author | bcoudurier |
|---|---|
| date | Wed, 11 Mar 2009 06:15:00 +0000 |
| parents | b330c2e275f9 |
| children | ca6a35b5c915 |
| rev | line source |
|---|---|
| 3721 | 1 /* |
| 2 * MXF muxer | |
| 3 * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com> | |
| 4325 | 4 * Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com> |
| 3721 | 5 * |
| 6 * This file is part of FFmpeg. | |
| 7 * | |
| 8 * FFmpeg is free software; you can redistribute it and/or | |
| 9 * modify it under the terms of the GNU Lesser General Public | |
| 10 * License as published by the Free Software Foundation; either | |
| 11 * version 2.1 of the License, or (at your option) any later version. | |
| 12 * | |
| 13 * FFmpeg is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 16 * Lesser General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU Lesser General Public | |
| 19 * License along with FFmpeg; if not, write to the Free Software | |
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 21 */ | |
| 22 | |
| 23 /* | |
| 24 * References | |
| 25 * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value | |
| 26 * SMPTE 377M MXF File Format Specifications | |
| 27 * SMPTE 379M MXF Generic Container | |
| 28 * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container | |
| 29 * SMPTE RP210: SMPTE Metadata Dictionary | |
| 30 * SMPTE RP224: Registry of SMPTE Universal Labels | |
| 31 */ | |
| 32 | |
| 33 //#define DEBUG | |
| 34 | |
| 4363 | 35 #include <math.h> |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
36 #include <time.h> |
| 4363 | 37 |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
38 #include "libavutil/fifo.h" |
| 4696 | 39 #include "libavutil/random_seed.h" |
| 4403 | 40 #include "libavcodec/bytestream.h" |
|
4400
65adb9e5214f
extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
4397
diff
changeset
|
41 #include "audiointerleave.h" |
| 4403 | 42 #include "avformat.h" |
| 3735 | 43 #include "mxf.h" |
| 44 | |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
45 static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 }; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
46 static const int PAL_samples_per_frame[] = { 1920, 0 }; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
47 |
| 4473 | 48 AVOutputFormat mxf_d10_muxer; |
| 49 | |
| 4440 | 50 #define EDIT_UNITS_PER_BODY 250 |
| 4393 | 51 #define KAG_SIZE 512 |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
52 |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
53 typedef struct { |
| 3735 | 54 int local_tag; |
| 55 UID uid; | |
| 56 } MXFLocalTagPair; | |
| 57 | |
| 3740 | 58 typedef struct { |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
59 uint8_t flags; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
60 uint64_t offset; |
| 4407 | 61 unsigned slice_offset; ///< offset of audio slice |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
62 } MXFIndexEntry; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
63 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
64 typedef struct { |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
65 AudioInterleaveContext aic; |
| 3740 | 66 UID track_essence_element_key; |
| 4324 | 67 int index; ///< index in mxf_essence_container_uls table |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
68 const UID *codec_ul; |
| 4323 | 69 int order; ///< interleaving order if dts are equal |
| 70 int interlaced; ///< wether picture is interlaced | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
71 int temporal_reordering; |
| 4505 | 72 AVRational aspect_ratio; ///< display aspect ratio |
| 3740 | 73 } MXFStreamContext; |
| 74 | |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
75 typedef struct { |
|
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
76 UID container_ul; |
|
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
77 UID element_ul; |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
78 UID codec_ul; |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
79 void (*write_desc)(); |
| 3847 | 80 } MXFContainerEssenceEntry; |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
81 |
| 4345 | 82 static const struct { |
| 83 enum CodecID id; | |
| 84 int index; | |
| 85 } mxf_essence_mappings[] = { | |
| 86 { CODEC_ID_MPEG2VIDEO, 0 }, | |
| 4346 | 87 { CODEC_ID_PCM_S24LE, 1 }, |
| 4345 | 88 { CODEC_ID_PCM_S16LE, 1 }, |
| 89 { 0 } | |
| 90 }; | |
| 91 | |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
92 static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st); |
| 4320 | 93 static void mxf_write_aes3_desc(AVFormatContext *s, AVStream *st); |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
94 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st); |
| 4473 | 95 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st); |
| 96 static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st); | |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
97 |
| 3847 | 98 static const MXFContainerEssenceEntry mxf_essence_container_uls[] = { |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
99 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
100 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 }, |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
101 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 }, |
| 4345 | 102 mxf_write_mpegvideo_desc }, |
| 4320 | 103 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 }, |
| 104 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x03,0x00 }, | |
| 105 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | |
| 4345 | 106 mxf_write_aes3_desc }, |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
107 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
108 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 }, |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
109 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, |
| 4345 | 110 mxf_write_wav_desc }, |
| 4473 | 111 // D-10 625/50 PAL 50mb/s |
| 112 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, | |
| 113 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }, | |
| 114 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, | |
| 115 mxf_write_cdci_desc }, | |
| 116 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, | |
| 117 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 }, | |
| 118 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | |
| 119 mxf_write_generic_sound_desc }, | |
| 120 // D-10 525/60 NTSC 50mb/s | |
| 121 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 }, | |
| 122 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }, | |
| 123 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x02 }, | |
| 124 mxf_write_cdci_desc }, | |
| 125 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 }, | |
| 126 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 }, | |
| 127 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | |
| 128 mxf_write_generic_sound_desc }, | |
| 129 // D-10 625/50 PAL 40mb/s | |
| 130 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, | |
| 131 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }, | |
| 132 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x03 }, | |
| 133 mxf_write_cdci_desc }, | |
| 134 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, | |
| 135 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 }, | |
| 136 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | |
| 137 mxf_write_generic_sound_desc }, | |
| 138 // D-10 525/60 NTSC 40mb/s | |
| 139 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, | |
| 140 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }, | |
| 141 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x04 }, | |
| 142 mxf_write_cdci_desc }, | |
| 143 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, | |
| 144 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 }, | |
| 145 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | |
| 146 mxf_write_generic_sound_desc }, | |
| 147 // D-10 625/50 PAL 30mb/s | |
| 148 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, | |
| 149 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }, | |
| 150 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, | |
| 151 mxf_write_cdci_desc }, | |
| 152 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, | |
| 153 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 }, | |
| 154 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | |
| 155 mxf_write_generic_sound_desc }, | |
| 156 // D-10 525/60 NTSC 30mb/s | |
| 157 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 }, | |
| 158 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }, | |
| 159 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 }, | |
| 160 mxf_write_cdci_desc }, | |
| 161 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 }, | |
| 162 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 }, | |
| 163 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, | |
| 164 mxf_write_generic_sound_desc }, | |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
165 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
166 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
167 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, |
| 4345 | 168 NULL }, |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
169 }; |
|
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
170 |
| 3740 | 171 typedef struct MXFContext { |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
172 int64_t footer_partition_offset; |
| 3740 | 173 int essence_container_count; |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
174 AVRational time_base; |
| 4313 | 175 int header_written; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
176 MXFIndexEntry *index_entries; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
177 unsigned edit_units_count; |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
178 uint64_t timestamp; ///< timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8) |
| 4407 | 179 uint8_t slice_count; ///< index slice count minus 1 (1 if no audio, 0 otherwise) |
| 4440 | 180 int last_indexed_edit_unit; |
| 181 uint64_t *body_partition_offset; | |
| 182 unsigned body_partitions_count; | |
| 183 int last_key_index; ///< index of last key frame | |
| 4448 | 184 uint64_t duration; |
| 185 AVStream *timecode_track; | |
| 186 int timecode_base; ///< rounded time code base (25 or 30) | |
| 4449 | 187 int timecode_start; ///< frame number computed from mpeg-2 gop header timecode |
| 4448 | 188 int timecode_drop_frame; ///< time code use drop frame method frop mpeg-2 essence gop header |
| 4473 | 189 int edit_unit_byte_count; ///< fixed edit unit byte count |
|
4481
27fd3af46000
compute body offset and index entry offset correctly
bcoudurier
parents:
4478
diff
changeset
|
190 uint64_t body_offset; |
| 4696 | 191 uint32_t instance_number; |
| 192 uint8_t umid[16]; ///< unique material identifier | |
| 3740 | 193 } MXFContext; |
| 3743 | 194 |
| 3735 | 195 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; |
| 4696 | 196 static const uint8_t umid_ul[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13 }; |
| 3735 | 197 |
| 198 /** | |
| 199 * complete key for operation pattern, partitions, and primer pack | |
| 200 */ | |
|
4536
b94bedbb59d7
always use multi track since timecode track is present
bcoudurier
parents:
4535
diff
changeset
|
201 static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x09,0x00 }; |
| 4351 | 202 static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete |
| 203 static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }; | |
| 204 static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 }; | |
| 205 static const uint8_t random_index_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x11,0x01,0x00 }; | |
| 3839 | 206 static const uint8_t header_open_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }; // OpenIncomplete |
| 207 static const uint8_t header_closed_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }; // ClosedComplete | |
| 4393 | 208 static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 }; |
| 4440 | 209 static const uint8_t body_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }; // ClosedComplete |
| 3839 | 210 |
| 3743 | 211 /** |
| 212 * partial key for header metadata | |
| 213 */ | |
| 214 static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 }; | |
| 4351 | 215 static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 }; |
| 3743 | 216 |
| 3749 | 217 /** |
| 218 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html | |
| 219 */ | |
| 220 static const MXFLocalTagPair mxf_local_tag_batch[] = { | |
| 221 // preface set | |
| 222 { 0x3C0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x02,0x00,0x00,0x00,0x00}}, /* Instance UID */ | |
| 223 { 0x3B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x04,0x00,0x00}}, /* Last Modified Date */ | |
| 224 { 0x3B05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x05,0x00,0x00,0x00}}, /* Version */ | |
| 225 { 0x3B06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x04,0x00,0x00}}, /* Identifications reference */ | |
| 226 { 0x3B03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x01,0x00,0x00}}, /* Content Storage reference */ | |
| 227 { 0x3B09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x03,0x00,0x00,0x00,0x00}}, /* Operational Pattern UL */ | |
| 228 { 0x3B0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x01,0x00,0x00}}, /* Essence Containers UL batch */ | |
| 229 { 0x3B0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x02,0x00,0x00}}, /* DM Schemes UL batch */ | |
| 230 // Identification | |
| 231 { 0x3C09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x01,0x00,0x00,0x00}}, /* This Generation UID */ | |
| 232 { 0x3C01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x02,0x01,0x00,0x00}}, /* Company Name */ | |
| 233 { 0x3C02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x03,0x01,0x00,0x00}}, /* Product Name */ | |
| 3792 | 234 { 0x3C04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x05,0x01,0x00,0x00}}, /* Version String */ |
| 3749 | 235 { 0x3C05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x07,0x00,0x00,0x00}}, /* Product ID */ |
| 236 { 0x3C06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x03,0x00,0x00}}, /* Modification Date */ | |
| 237 // Content Storage | |
| 238 { 0x1901, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x01,0x00,0x00}}, /* Package strong reference batch */ | |
| 4279 | 239 { 0x1902, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x02,0x00,0x00}}, /* Package strong reference batch */ |
| 3749 | 240 // Essence Container Data |
| 241 { 0x2701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x06,0x01,0x00,0x00,0x00}}, /* Linked Package UID */ | |
| 242 { 0x3F07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x04,0x00,0x00,0x00,0x00}}, /* BodySID */ | |
| 243 // Package | |
| 244 { 0x4401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x10,0x00,0x00,0x00,0x00}}, /* Package UID */ | |
| 245 { 0x4405, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x01,0x03,0x00,0x00}}, /* Package Creation Date */ | |
| 246 { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */ | |
| 247 { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */ | |
| 248 { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */ | |
| 249 // Track | |
| 250 { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */ | |
| 3827 | 251 { 0x4804, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x04,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Track Number */ |
| 3749 | 252 { 0x4B01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x30,0x04,0x05,0x00,0x00,0x00,0x00}}, /* Edit Rate */ |
| 253 { 0x4B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x03,0x00,0x00}}, /* Origin */ | |
| 254 { 0x4803, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x04,0x00,0x00}}, /* Sequence reference */ | |
| 255 // Sequence | |
| 256 { 0x0201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x07,0x01,0x00,0x00,0x00,0x00,0x00}}, /* Data Definition UL */ | |
| 257 { 0x0202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x02,0x01,0x01,0x03,0x00,0x00}}, /* Duration */ | |
| 258 { 0x1001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x09,0x00,0x00}}, /* Structural Components reference array */ | |
| 259 // Source Clip | |
| 4431 | 260 { 0x1201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x04,0x00,0x00}}, /* Start position */ |
| 3749 | 261 { 0x1101, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x01,0x00,0x00,0x00}}, /* SourcePackageID */ |
| 262 { 0x1102, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x02,0x00,0x00,0x00}}, /* SourceTrackID */ | |
| 4448 | 263 // Timecode Component |
| 264 { 0x1501, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x05,0x00,0x00}}, /* Start Time Code */ | |
| 265 { 0x1502, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x04,0x01,0x01,0x02,0x06,0x00,0x00}}, /* Rounded Time Code Base */ | |
| 266 { 0x1503, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x04,0x01,0x01,0x05,0x00,0x00,0x00}}, /* Drop Frame */ | |
| 3794 | 267 // File Descriptor |
| 268 { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */ | |
| 3749 | 269 { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */ |
| 270 { 0x3001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x00,0x00,0x00,0x00}}, /* SampleRate */ | |
| 3794 | 271 { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */ |
| 272 // Generic Picture Essence Descriptor | |
| 4321 | 273 { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */ |
| 4431 | 274 { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */ |
| 3794 | 275 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */ |
| 276 { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */ | |
| 4335 | 277 { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */ |
| 278 { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */ | |
| 3794 | 279 { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */ |
| 280 { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */ | |
|
4434
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
281 // CDCI Picture Essence Descriptor |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
282 { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */ |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
283 { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */ |
| 3794 | 284 // Generic Sound Essence Descriptor |
| 4431 | 285 { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */ |
| 3794 | 286 { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */ |
| 287 { 0x3D07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}}, /* ChannelCount */ | |
| 288 { 0x3D01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}}, /* Quantization bits */ | |
| 4011 | 289 { 0x3D06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}}, /* Sound Essence Compression */ |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
290 // Index Table Segment |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
291 { 0x3F0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x05,0x30,0x04,0x06,0x00,0x00,0x00,0x00}}, /* Index Edit Rate */ |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
292 { 0x3F0C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x01,0x03,0x01,0x0A,0x00,0x00}}, /* Index Start Position */ |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
293 { 0x3F0D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x02,0x01,0x01,0x02,0x00,0x00}}, /* Index Duration */ |
| 4431 | 294 { 0x3F05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x06,0x02,0x01,0x00,0x00,0x00,0x00}}, /* Edit Unit Byte Count */ |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
295 { 0x3F06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x05,0x00,0x00,0x00,0x00}}, /* IndexSID */ |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
296 { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */ |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
297 { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */ |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
298 { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */ |
| 4336 | 299 // MPEG video Descriptor |
| 300 { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */ | |
| 4339 | 301 // Wave Audio Essence Descriptor |
| 302 { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */ | |
| 303 { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */ | |
| 3749 | 304 }; |
| 305 | |
| 3844 | 306 static void mxf_write_uuid(ByteIOContext *pb, enum MXFMetadataSetType type, int value) |
| 3735 | 307 { |
| 308 put_buffer(pb, uuid_base, 12); | |
| 309 put_be16(pb, type); | |
| 310 put_be16(pb, value); | |
| 311 } | |
| 312 | |
| 4696 | 313 static void mxf_write_umid(AVFormatContext *s, int type) |
| 3740 | 314 { |
| 4696 | 315 MXFContext *mxf = s->priv_data; |
| 316 put_buffer(s->pb, umid_ul, 13); | |
| 317 put_be24(s->pb, mxf->instance_number); | |
| 318 put_buffer(s->pb, mxf->umid, 15); | |
| 319 put_buffer(s->pb, mxf->umid, type); | |
| 3740 | 320 } |
| 3743 | 321 |
| 322 static void mxf_write_refs_count(ByteIOContext *pb, int ref_count) | |
| 323 { | |
| 324 put_be32(pb, ref_count); | |
| 325 put_be32(pb, 16); | |
| 326 } | |
| 327 | |
| 4393 | 328 static int klv_ber_length(uint64_t len) |
| 329 { | |
| 330 if (len < 128) | |
| 331 return 1; | |
| 332 else | |
| 333 return (av_log2(len) >> 3) + 2; | |
| 334 } | |
| 335 | |
| 3735 | 336 static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len) |
| 337 { | |
| 338 // Determine the best BER size | |
| 339 int size; | |
| 340 if (len < 128) { | |
| 341 //short form | |
| 342 put_byte(pb, len); | |
| 343 return 1; | |
| 344 } | |
| 345 | |
| 346 size = (av_log2(len) >> 3) + 1; | |
| 347 | |
| 348 // long form | |
| 349 put_byte(pb, 0x80 + size); | |
| 350 while(size) { | |
| 4351 | 351 size--; |
| 3735 | 352 put_byte(pb, len >> 8 * size & 0xff); |
| 353 } | |
| 354 return 0; | |
| 355 } | |
| 356 | |
|
4469
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
357 static void klv_encode_ber4_length(ByteIOContext *pb, int len) |
|
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
358 { |
|
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
359 put_byte(pb, 0x80 + 3); |
|
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
360 put_be24(pb, len); |
|
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
361 } |
|
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
362 |
|
3818
ae0d01b63679
compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents:
3817
diff
changeset
|
363 /* |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
364 * Get essence container ul index |
|
3818
ae0d01b63679
compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents:
3817
diff
changeset
|
365 */ |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
366 static int mxf_get_essence_container_ul_index(enum CodecID id) |
| 3721 | 367 { |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
368 int i; |
| 4345 | 369 for (i = 0; mxf_essence_mappings[i].id; i++) |
| 370 if (mxf_essence_mappings[i].id == id) | |
| 371 return mxf_essence_mappings[i].index; | |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
372 return -1; |
| 3721 | 373 } |
| 374 | |
| 3749 | 375 static void mxf_write_primer_pack(AVFormatContext *s) |
| 3735 | 376 { |
| 377 ByteIOContext *pb = s->pb; | |
| 378 int local_tag_number, i = 0; | |
| 379 | |
| 4001 | 380 local_tag_number = FF_ARRAY_ELEMS(mxf_local_tag_batch); |
| 3735 | 381 |
| 382 put_buffer(pb, primer_pack_key, 16); | |
| 383 klv_encode_ber_length(pb, local_tag_number * 18 + 8); | |
| 384 | |
| 385 put_be32(pb, local_tag_number); // local_tag num | |
| 386 put_be32(pb, 18); // item size, always 18 according to the specs | |
| 387 | |
| 388 for (i = 0; i < local_tag_number; i++) { | |
| 389 put_be16(pb, mxf_local_tag_batch[i].local_tag); | |
| 390 put_buffer(pb, mxf_local_tag_batch[i].uid, 16); | |
| 391 } | |
| 392 } | |
| 393 | |
| 3815 | 394 static void mxf_write_local_tag(ByteIOContext *pb, int size, int tag) |
| 3735 | 395 { |
| 396 put_be16(pb, tag); | |
| 3815 | 397 put_be16(pb, size); |
| 3735 | 398 } |
| 399 | |
| 3740 | 400 static void mxf_write_metadata_key(ByteIOContext *pb, unsigned int value) |
| 401 { | |
| 402 put_buffer(pb, header_metadata_key, 13); | |
| 403 put_be24(pb, value); | |
| 404 } | |
| 405 | |
| 3721 | 406 static void mxf_free(AVFormatContext *s) |
| 407 { | |
| 408 int i; | |
| 409 | |
| 410 for (i = 0; i < s->nb_streams; i++) { | |
| 3823 | 411 AVStream *st = s->streams[i]; |
| 3721 | 412 av_freep(&st->priv_data); |
| 413 } | |
| 414 } | |
| 415 | |
| 4404 | 416 static const MXFCodecUL *mxf_get_data_definition_ul(int type) |
| 3721 | 417 { |
| 4404 | 418 const MXFCodecUL *uls = ff_mxf_data_definition_uls; |
| 419 while (uls->uid[0]) { | |
| 420 if (type == uls->id) | |
| 3721 | 421 break; |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
422 uls++; |
| 3721 | 423 } |
| 424 return uls; | |
| 425 } | |
| 426 | |
| 3821 | 427 static void mxf_write_essence_container_refs(AVFormatContext *s) |
|
3780
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
428 { |
|
3818
ae0d01b63679
compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents:
3817
diff
changeset
|
429 MXFContext *c = s->priv_data; |
|
3780
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
430 ByteIOContext *pb = s->pb; |
|
3818
ae0d01b63679
compute essence containers in mxf_write_header, this simplifies the code
bcoudurier
parents:
3817
diff
changeset
|
431 int i; |
|
3780
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
432 |
| 3822 | 433 mxf_write_refs_count(pb, c->essence_container_count); |
| 434 av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count); | |
| 435 for (i = 0; i < c->essence_container_count; i++) { | |
| 4475 | 436 MXFStreamContext *sc = s->streams[i]->priv_data; |
| 437 put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16); | |
| 3822 | 438 } |
|
3780
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
439 } |
|
261cd3e672e5
Remaining parts of GSoC MXF muxer by Zhentan Feng.
cehoyos
parents:
3778
diff
changeset
|
440 |
| 3749 | 441 static void mxf_write_preface(AVFormatContext *s) |
| 442 { | |
| 443 MXFContext *mxf = s->priv_data; | |
| 444 ByteIOContext *pb = s->pb; | |
| 445 | |
| 446 mxf_write_metadata_key(pb, 0x012f00); | |
| 447 PRINT_KEY(s, "preface key", pb->buf_ptr - 16); | |
| 448 klv_encode_ber_length(pb, 130 + 16 * mxf->essence_container_count); | |
| 449 | |
| 450 // write preface set uid | |
| 451 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 452 mxf_write_uuid(pb, Preface, 0); | |
| 453 PRINT_KEY(s, "preface uid", pb->buf_ptr - 16); | |
| 454 | |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
455 // last modified date |
| 3749 | 456 mxf_write_local_tag(pb, 8, 0x3B02); |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
457 put_be64(pb, mxf->timestamp); |
| 3749 | 458 |
| 459 // write version | |
| 460 mxf_write_local_tag(pb, 2, 0x3B05); | |
| 4535 | 461 put_be16(pb, 258); // v1.2 |
| 3749 | 462 |
| 463 // write identification_refs | |
| 464 mxf_write_local_tag(pb, 16 + 8, 0x3B06); | |
| 465 mxf_write_refs_count(pb, 1); | |
| 466 mxf_write_uuid(pb, Identification, 0); | |
| 467 | |
| 468 // write content_storage_refs | |
| 469 mxf_write_local_tag(pb, 16, 0x3B03); | |
| 470 mxf_write_uuid(pb, ContentStorage, 0); | |
| 471 | |
| 4430 | 472 // operational pattern |
| 3749 | 473 mxf_write_local_tag(pb, 16, 0x3B09); |
|
4536
b94bedbb59d7
always use multi track since timecode track is present
bcoudurier
parents:
4535
diff
changeset
|
474 put_buffer(pb, op1a_ul, 16); |
| 3749 | 475 |
| 476 // write essence_container_refs | |
| 477 mxf_write_local_tag(pb, 8 + 16 * mxf->essence_container_count, 0x3B0A); | |
| 3821 | 478 mxf_write_essence_container_refs(s); |
| 3749 | 479 |
| 480 // write dm_scheme_refs | |
| 481 mxf_write_local_tag(pb, 8, 0x3B0B); | |
| 482 put_be64(pb, 0); | |
| 483 } | |
| 484 | |
| 3804 | 485 /* |
|
3806
fa043e93fc66
introduce mxf_write_local_tag_utf16 and factorize
bcoudurier
parents:
3805
diff
changeset
|
486 * Write a local tag containing an ascii string as utf-16 |
| 3804 | 487 */ |
|
3806
fa043e93fc66
introduce mxf_write_local_tag_utf16 and factorize
bcoudurier
parents:
3805
diff
changeset
|
488 static void mxf_write_local_tag_utf16(ByteIOContext *pb, int tag, const char *value) |
| 3804 | 489 { |
|
3805
d8a6432c76f3
use strlen and do not write useless trailing 0 according to specs
bcoudurier
parents:
3804
diff
changeset
|
490 int i, size = strlen(value); |
|
3806
fa043e93fc66
introduce mxf_write_local_tag_utf16 and factorize
bcoudurier
parents:
3805
diff
changeset
|
491 mxf_write_local_tag(pb, size*2, tag); |
| 3804 | 492 for (i = 0; i < size; i++) |
| 493 put_be16(pb, value[i]); | |
| 494 } | |
| 495 | |
| 3749 | 496 static void mxf_write_identification(AVFormatContext *s) |
| 497 { | |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
498 MXFContext *mxf = s->priv_data; |
| 3749 | 499 ByteIOContext *pb = s->pb; |
| 3810 | 500 const char *company = "FFmpeg"; |
| 501 const char *product = "OP1a Muxer"; | |
| 3807 | 502 const char *version; |
| 3810 | 503 int length; |
| 3749 | 504 |
| 505 mxf_write_metadata_key(pb, 0x013000); | |
| 506 PRINT_KEY(s, "identification key", pb->buf_ptr - 16); | |
| 507 | |
| 3808 | 508 version = s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT ? |
| 3809 | 509 "0.0.0" : AV_STRINGIFY(LIBAVFORMAT_VERSION); |
| 3810 | 510 length = 84 + (strlen(company)+strlen(product)+strlen(version))*2; // utf-16 |
| 3749 | 511 klv_encode_ber_length(pb, length); |
| 512 | |
| 513 // write uid | |
| 514 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 515 mxf_write_uuid(pb, Identification, 0); | |
| 516 PRINT_KEY(s, "identification uid", pb->buf_ptr - 16); | |
| 3811 | 517 |
| 3749 | 518 // write generation uid |
| 519 mxf_write_local_tag(pb, 16, 0x3C09); | |
| 520 mxf_write_uuid(pb, Identification, 1); | |
| 521 | |
| 3810 | 522 mxf_write_local_tag_utf16(pb, 0x3C01, company); // Company Name |
| 523 mxf_write_local_tag_utf16(pb, 0x3C02, product); // Product Name | |
| 3807 | 524 mxf_write_local_tag_utf16(pb, 0x3C04, version); // Version String |
| 3749 | 525 |
| 526 // write product uid | |
| 527 mxf_write_local_tag(pb, 16, 0x3C05); | |
| 528 mxf_write_uuid(pb, Identification, 2); | |
| 529 | |
| 4384 | 530 // modification date |
| 3749 | 531 mxf_write_local_tag(pb, 8, 0x3C06); |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
532 put_be64(pb, mxf->timestamp); |
| 3749 | 533 } |
| 534 | |
| 535 static void mxf_write_content_storage(AVFormatContext *s) | |
| 536 { | |
| 537 ByteIOContext *pb = s->pb; | |
| 538 | |
| 539 mxf_write_metadata_key(pb, 0x011800); | |
| 540 PRINT_KEY(s, "content storage key", pb->buf_ptr - 16); | |
| 4279 | 541 klv_encode_ber_length(pb, 92); |
| 3749 | 542 |
| 543 // write uid | |
| 544 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 545 mxf_write_uuid(pb, ContentStorage, 0); | |
| 546 PRINT_KEY(s, "content storage uid", pb->buf_ptr - 16); | |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
547 |
| 3749 | 548 // write package reference |
| 549 mxf_write_local_tag(pb, 16 * 2 + 8, 0x1901); | |
| 550 mxf_write_refs_count(pb, 2); | |
| 551 mxf_write_uuid(pb, MaterialPackage, 0); | |
| 552 mxf_write_uuid(pb, SourcePackage, 0); | |
| 4279 | 553 |
| 554 // write essence container data | |
| 555 mxf_write_local_tag(pb, 8 + 16, 0x1902); | |
| 556 mxf_write_refs_count(pb, 1); | |
| 557 mxf_write_uuid(pb, EssenceContainerData, 0); | |
| 3749 | 558 } |
| 559 | |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
560 static void mxf_write_track(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
561 { |
| 4374 | 562 MXFContext *mxf = s->priv_data; |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
563 ByteIOContext *pb = s->pb; |
| 3823 | 564 MXFStreamContext *sc = st->priv_data; |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
565 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
566 mxf_write_metadata_key(pb, 0x013b00); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
567 PRINT_KEY(s, "track key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
568 klv_encode_ber_length(pb, 80); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
569 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
570 // write track uid |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
571 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
572 mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, st->index); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
573 PRINT_KEY(s, "track uid", pb->buf_ptr - 16); |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
574 |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
575 // write track id |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
576 mxf_write_local_tag(pb, 4, 0x4801); |
| 4565 | 577 put_be32(pb, st->index+2); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
578 |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
579 // write track number |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
580 mxf_write_local_tag(pb, 4, 0x4804); |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
581 if (type == MaterialPackage) |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
582 put_be32(pb, 0); // track number of material package is 0 |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
583 else |
|
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
584 put_buffer(pb, sc->track_essence_element_key + 12, 4); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
585 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
586 mxf_write_local_tag(pb, 8, 0x4B01); |
| 4374 | 587 put_be32(pb, mxf->time_base.den); |
| 588 put_be32(pb, mxf->time_base.num); | |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
589 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
590 // write origin |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
591 mxf_write_local_tag(pb, 8, 0x4B02); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
592 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
593 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
594 // write sequence refs |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
595 mxf_write_local_tag(pb, 16, 0x4803); |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
596 mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, st->index); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
597 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
598 |
| 4448 | 599 static const uint8_t smpte_12m_timecode_track_data_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x01,0x01,0x00,0x00,0x00 }; |
| 600 | |
| 601 static void mxf_write_common_fields(AVFormatContext *s, AVStream *st) | |
| 3743 | 602 { |
| 4448 | 603 MXFContext *mxf = s->priv_data; |
| 604 ByteIOContext *pb = s->pb; | |
| 3834 | 605 |
| 3743 | 606 // find data define uls |
| 607 mxf_write_local_tag(pb, 16, 0x0201); | |
| 4448 | 608 if (st == mxf->timecode_track) |
| 609 put_buffer(pb, smpte_12m_timecode_track_data_ul, 16); | |
| 610 else { | |
| 611 const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type); | |
| 612 put_buffer(pb, data_def_ul->uid, 16); | |
| 613 } | |
| 3743 | 614 |
| 615 // write duration | |
| 616 mxf_write_local_tag(pb, 8, 0x0202); | |
| 4448 | 617 put_be64(pb, mxf->duration); |
| 3743 | 618 } |
| 619 | |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
620 static void mxf_write_sequence(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
621 { |
| 4448 | 622 MXFContext *mxf = s->priv_data; |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
623 ByteIOContext *pb = s->pb; |
| 4448 | 624 enum MXFMetadataSetType component; |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
625 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
626 mxf_write_metadata_key(pb, 0x010f00); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
627 PRINT_KEY(s, "sequence key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
628 klv_encode_ber_length(pb, 80); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
629 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
630 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
631 mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, st->index); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
632 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
633 PRINT_KEY(s, "sequence uid", pb->buf_ptr - 16); |
| 4448 | 634 mxf_write_common_fields(s, st); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
635 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
636 // write structural component |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
637 mxf_write_local_tag(pb, 16 + 8, 0x1001); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
638 mxf_write_refs_count(pb, 1); |
| 4448 | 639 if (st == mxf->timecode_track) |
| 640 component = TimecodeComponent; | |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
641 else |
| 4448 | 642 component = SourceClip; |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
643 if (type == SourcePackage) |
|
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
644 component += TypeBottom; |
| 4448 | 645 mxf_write_uuid(pb, component, st->index); |
| 646 } | |
| 647 | |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
648 static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) |
| 4448 | 649 { |
| 650 MXFContext *mxf = s->priv_data; | |
| 651 ByteIOContext *pb = s->pb; | |
| 652 | |
| 653 mxf_write_metadata_key(pb, 0x011400); | |
| 654 klv_encode_ber_length(pb, 75); | |
| 655 | |
| 656 // UID | |
| 657 mxf_write_local_tag(pb, 16, 0x3C0A); | |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
658 mxf_write_uuid(pb, type == MaterialPackage ? TimecodeComponent : |
|
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
659 TimecodeComponent + TypeBottom, st->index); |
| 4448 | 660 |
| 661 mxf_write_common_fields(s, st); | |
| 662 | |
| 663 // Start Time Code | |
| 664 mxf_write_local_tag(pb, 8, 0x1501); | |
| 665 put_be64(pb, mxf->timecode_start); | |
| 666 | |
| 667 // Rounded Time Code Base | |
| 668 mxf_write_local_tag(pb, 2, 0x1502); | |
| 669 put_be16(pb, mxf->timecode_base); | |
| 670 | |
| 671 // Drop Frame | |
| 672 mxf_write_local_tag(pb, 1, 0x1503); | |
| 673 put_byte(pb, mxf->timecode_drop_frame); | |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
674 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
675 |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
676 static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
677 { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
678 ByteIOContext *pb = s->pb; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
679 int i; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
680 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
681 mxf_write_metadata_key(pb, 0x011100); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
682 PRINT_KEY(s, "sturctural component key", pb->buf_ptr - 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
683 klv_encode_ber_length(pb, 108); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
684 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
685 // write uid |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
686 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
687 mxf_write_uuid(pb, type == MaterialPackage ? SourceClip: SourceClip + TypeBottom, st->index); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
688 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
689 PRINT_KEY(s, "structural component uid", pb->buf_ptr - 16); |
| 4448 | 690 mxf_write_common_fields(s, st); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
691 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
692 // write start_position |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
693 mxf_write_local_tag(pb, 8, 0x1201); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
694 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
695 |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
696 // write source package uid, end of the reference |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
697 mxf_write_local_tag(pb, 32, 0x1101); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
698 if (type == SourcePackage) { |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
699 for (i = 0; i < 4; i++) |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
700 put_be64(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
701 } else |
| 4696 | 702 mxf_write_umid(s, 1); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
703 |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
704 // write source track id |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
705 mxf_write_local_tag(pb, 4, 0x1102); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
706 if (type == SourcePackage) |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
707 put_be32(pb, 0); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
708 else |
| 4565 | 709 put_be32(pb, st->index+2); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
710 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
711 |
| 3749 | 712 static void mxf_write_multi_descriptor(AVFormatContext *s) |
| 713 { | |
| 4376 | 714 MXFContext *mxf = s->priv_data; |
| 3749 | 715 ByteIOContext *pb = s->pb; |
| 4473 | 716 const uint8_t *ul; |
| 3749 | 717 int i; |
| 718 | |
| 719 mxf_write_metadata_key(pb, 0x014400); | |
| 720 PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16); | |
| 721 klv_encode_ber_length(pb, 64 + 16 * s->nb_streams); | |
| 722 | |
| 723 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 724 mxf_write_uuid(pb, MultipleDescriptor, 0); | |
| 725 PRINT_KEY(s, "multi_desc uid", pb->buf_ptr - 16); | |
| 726 | |
| 727 // write sample rate | |
| 728 mxf_write_local_tag(pb, 8, 0x3001); | |
| 4376 | 729 put_be32(pb, mxf->time_base.den); |
| 730 put_be32(pb, mxf->time_base.num); | |
| 3749 | 731 |
| 732 // write essence container ul | |
| 733 mxf_write_local_tag(pb, 16, 0x3004); | |
| 4473 | 734 if (mxf->essence_container_count > 1) |
| 735 ul = multiple_desc_ul; | |
| 4475 | 736 else { |
| 737 MXFStreamContext *sc = s->streams[0]->priv_data; | |
| 738 ul = mxf_essence_container_uls[sc->index].container_ul; | |
| 739 } | |
| 4473 | 740 put_buffer(pb, ul, 16); |
| 3749 | 741 |
| 742 // write sub descriptor refs | |
| 743 mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x3F01); | |
| 744 mxf_write_refs_count(pb, s->nb_streams); | |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
745 for (i = 0; i < s->nb_streams; i++) |
| 3749 | 746 mxf_write_uuid(pb, SubDescriptor, i); |
| 747 } | |
| 748 | |
| 4376 | 749 static void mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const UID key, unsigned size) |
| 3743 | 750 { |
| 4376 | 751 MXFContext *mxf = s->priv_data; |
|
3817
22831cc65a35
get essence container ul in header and set it per track, check for unsupported codec
bcoudurier
parents:
3816
diff
changeset
|
752 MXFStreamContext *sc = st->priv_data; |
| 4376 | 753 ByteIOContext *pb = s->pb; |
| 3743 | 754 |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
755 put_buffer(pb, key, 16); |
| 4527 | 756 klv_encode_ber_length(pb, size+20+8+12+20); |
| 3743 | 757 |
| 758 mxf_write_local_tag(pb, 16, 0x3C0A); | |
| 759 mxf_write_uuid(pb, SubDescriptor, st->index); | |
| 760 | |
| 761 mxf_write_local_tag(pb, 4, 0x3006); | |
| 4565 | 762 put_be32(pb, st->index+2); |
| 3743 | 763 |
| 3749 | 764 mxf_write_local_tag(pb, 8, 0x3001); |
| 4376 | 765 put_be32(pb, mxf->time_base.den); |
| 766 put_be32(pb, mxf->time_base.num); | |
| 3749 | 767 |
| 3743 | 768 mxf_write_local_tag(pb, 16, 0x3004); |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
769 put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16); |
| 3743 | 770 } |
| 771 | |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
772 static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }; |
|
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
773 static const UID mxf_wav_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }; |
| 4320 | 774 static const UID mxf_aes3_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }; |
| 4473 | 775 static const UID mxf_cdci_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }; |
| 776 static const UID mxf_generic_sound_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }; | |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
777 |
|
4471
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
778 static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) |
| 3743 | 779 { |
| 4316 | 780 MXFStreamContext *sc = st->priv_data; |
| 3743 | 781 ByteIOContext *pb = s->pb; |
| 4277 | 782 int stored_height = (st->codec->height+15)/16*16; |
| 4472 | 783 int display_height; |
| 4322 | 784 int f1, f2; |
| 3743 | 785 |
| 4527 | 786 mxf_write_generic_desc(s, st, key, size+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20); |
| 3743 | 787 |
| 788 mxf_write_local_tag(pb, 4, 0x3203); | |
| 789 put_be32(pb, st->codec->width); | |
| 790 | |
| 791 mxf_write_local_tag(pb, 4, 0x3202); | |
| 4316 | 792 put_be32(pb, stored_height>>sc->interlaced); |
| 3743 | 793 |
| 4335 | 794 mxf_write_local_tag(pb, 4, 0x3209); |
| 795 put_be32(pb, st->codec->width); | |
| 796 | |
| 4472 | 797 if (st->codec->height == 608) // PAL + VBI |
| 798 display_height = 576; | |
| 799 else if (st->codec->height == 512) // NTSC + VBI | |
| 800 display_height = 486; | |
| 801 else | |
| 802 display_height = st->codec->height; | |
| 803 | |
| 4335 | 804 mxf_write_local_tag(pb, 4, 0x3208); |
| 4472 | 805 put_be32(pb, display_height>>sc->interlaced); |
| 4335 | 806 |
|
4434
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
807 // component depth |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
808 mxf_write_local_tag(pb, 4, 0x3301); |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
809 put_be32(pb, 8); |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
810 |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
811 // horizontal subsampling |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
812 mxf_write_local_tag(pb, 4, 0x3302); |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
813 put_be32(pb, 2); |
|
a75d42745d16
write component depth and horizontal subsampling best effort local tags
bcoudurier
parents:
4433
diff
changeset
|
814 |
| 4321 | 815 // frame layout |
| 816 mxf_write_local_tag(pb, 1, 0x320C); | |
| 817 put_byte(pb, sc->interlaced); | |
| 818 | |
| 4322 | 819 // video line map |
| 820 switch (st->codec->height) { | |
| 821 case 576: f1 = 23; f2 = 336; break; | |
| 822 case 608: f1 = 7; f2 = 320; break; | |
| 823 case 480: f1 = 20; f2 = 283; break; | |
| 824 case 512: f1 = 7; f2 = 270; break; | |
| 825 case 720: f1 = 26; f2 = 0; break; // progressive | |
| 826 case 1080: f1 = 21; f2 = 584; break; | |
| 827 default: f1 = 0; f2 = 0; break; | |
| 828 } | |
| 829 | |
| 830 if (!sc->interlaced) { | |
| 831 f2 = 0; | |
| 832 f1 *= 2; | |
| 833 } | |
| 834 | |
| 4343 | 835 mxf_write_local_tag(pb, 12+sc->interlaced*4, 0x320D); |
| 4337 | 836 put_be32(pb, sc->interlaced ? 2 : 1); |
| 837 put_be32(pb, 4); | |
| 4322 | 838 put_be32(pb, f1); |
| 4337 | 839 if (sc->interlaced) |
| 840 put_be32(pb, f2); | |
| 4322 | 841 |
| 3743 | 842 mxf_write_local_tag(pb, 8, 0x320E); |
| 4505 | 843 put_be32(pb, sc->aspect_ratio.num); |
| 844 put_be32(pb, sc->aspect_ratio.den); | |
|
4317
b978795a9e37
local tag 3201 is picture essence coding, so do not write it for wav
bcoudurier
parents:
4316
diff
changeset
|
845 |
|
b978795a9e37
local tag 3201 is picture essence coding, so do not write it for wav
bcoudurier
parents:
4316
diff
changeset
|
846 mxf_write_local_tag(pb, 16, 0x3201); |
|
b978795a9e37
local tag 3201 is picture essence coding, so do not write it for wav
bcoudurier
parents:
4316
diff
changeset
|
847 put_buffer(pb, *sc->codec_ul, 16); |
| 3743 | 848 } |
| 849 | |
| 4473 | 850 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st) |
| 851 { | |
| 4527 | 852 mxf_write_cdci_common(s, st, mxf_cdci_descriptor_key, 0); |
| 4473 | 853 } |
| 854 | |
|
4471
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
855 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
856 { |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
857 ByteIOContext *pb = s->pb; |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
858 |
| 4527 | 859 mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8); |
|
4471
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
860 |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
861 // bit rate |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
862 mxf_write_local_tag(pb, 4, 0x8000); |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
863 put_be32(pb, st->codec->bit_rate); |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
864 } |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
865 |
|
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
866 static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) |
| 3743 | 867 { |
| 868 ByteIOContext *pb = s->pb; | |
| 869 | |
| 4527 | 870 mxf_write_generic_desc(s, st, key, size+5+12+8+8); |
| 4318 | 871 |
| 4319 | 872 // audio locked |
| 4318 | 873 mxf_write_local_tag(pb, 1, 0x3D02); |
| 874 put_byte(pb, 1); | |
| 3743 | 875 |
| 876 // write audio sampling rate | |
| 877 mxf_write_local_tag(pb, 8, 0x3D03); | |
| 878 put_be32(pb, st->codec->sample_rate); | |
| 879 put_be32(pb, 1); | |
| 880 | |
| 881 mxf_write_local_tag(pb, 4, 0x3D07); | |
| 882 put_be32(pb, st->codec->channels); | |
| 883 | |
| 884 mxf_write_local_tag(pb, 4, 0x3D01); | |
| 4346 | 885 put_be32(pb, av_get_bits_per_sample(st->codec->codec_id)); |
| 3743 | 886 } |
| 887 | |
|
4471
bac4bfb54ff7
split mpegvideo descriptor into cdci descriptor and wav common in sound common
bcoudurier
parents:
4470
diff
changeset
|
888 static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) |
| 4319 | 889 { |
| 4339 | 890 ByteIOContext *pb = s->pb; |
| 891 | |
| 4527 | 892 mxf_write_generic_sound_common(s, st, key, size+6+8); |
| 4339 | 893 |
| 894 mxf_write_local_tag(pb, 2, 0x3D0A); | |
| 895 put_be16(pb, st->codec->block_align); | |
| 896 | |
| 897 // avg bytes per sec | |
| 898 mxf_write_local_tag(pb, 4, 0x3D09); | |
| 899 put_be32(pb, st->codec->block_align*st->codec->sample_rate); | |
| 4319 | 900 } |
| 901 | |
| 4340 | 902 static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st) |
| 903 { | |
| 4527 | 904 mxf_write_wav_common(s, st, mxf_wav_descriptor_key, 0); |
| 4340 | 905 } |
| 906 | |
| 4320 | 907 static void mxf_write_aes3_desc(AVFormatContext *s, AVStream *st) |
| 908 { | |
| 4527 | 909 mxf_write_wav_common(s, st, mxf_aes3_descriptor_key, 0); |
| 4320 | 910 } |
| 911 | |
| 4473 | 912 static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st) |
| 913 { | |
| 4527 | 914 mxf_write_generic_sound_common(s, st, mxf_generic_sound_descriptor_key, 0); |
| 4473 | 915 } |
| 916 | |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
917 static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type) |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
918 { |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
919 MXFContext *mxf = s->priv_data; |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
920 ByteIOContext *pb = s->pb; |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
921 int i, track_count = s->nb_streams+1; |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
922 |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
923 if (type == MaterialPackage) { |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
924 mxf_write_metadata_key(pb, 0x013600); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
925 PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16); |
| 4448 | 926 klv_encode_ber_length(pb, 92 + 16*track_count); |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
927 } else { |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
928 mxf_write_metadata_key(pb, 0x013700); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
929 PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16); |
| 4448 | 930 klv_encode_ber_length(pb, 112 + 16*track_count); // 20 bytes length for descriptor reference |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
931 } |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
932 |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
933 // write uid |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
934 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
935 mxf_write_uuid(pb, type, 0); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
936 av_log(s,AV_LOG_DEBUG, "package type:%d\n", type); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
937 PRINT_KEY(s, "package uid", pb->buf_ptr - 16); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
938 |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
939 // write package umid |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
940 mxf_write_local_tag(pb, 32, 0x4401); |
| 4696 | 941 mxf_write_umid(s, type == SourcePackage); |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
942 PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
943 |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
944 // package creation date |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
945 mxf_write_local_tag(pb, 8, 0x4405); |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
946 put_be64(pb, mxf->timestamp); |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
947 |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
948 // package modified date |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
949 mxf_write_local_tag(pb, 8, 0x4404); |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
950 put_be64(pb, mxf->timestamp); |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
951 |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
952 // write track refs |
| 4448 | 953 mxf_write_local_tag(pb, track_count*16 + 8, 0x4403); |
| 954 mxf_write_refs_count(pb, track_count); | |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
955 mxf_write_uuid(pb, type == MaterialPackage ? Track : |
|
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
956 Track + TypeBottom, -1); // timecode track |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
957 for (i = 0; i < s->nb_streams; i++) |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
958 mxf_write_uuid(pb, type == MaterialPackage ? Track : Track + TypeBottom, i); |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
959 |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
960 // write multiple descriptor reference |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
961 if (type == SourcePackage) { |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
962 mxf_write_local_tag(pb, 16, 0x4701); |
|
3851
9b3ad7f292a4
do no write multi descriptor when only one track is present
bcoudurier
parents:
3850
diff
changeset
|
963 if (s->nb_streams > 1) { |
|
9b3ad7f292a4
do no write multi descriptor when only one track is present
bcoudurier
parents:
3850
diff
changeset
|
964 mxf_write_uuid(pb, MultipleDescriptor, 0); |
|
9b3ad7f292a4
do no write multi descriptor when only one track is present
bcoudurier
parents:
3850
diff
changeset
|
965 mxf_write_multi_descriptor(s); |
|
9b3ad7f292a4
do no write multi descriptor when only one track is present
bcoudurier
parents:
3850
diff
changeset
|
966 } else |
|
9b3ad7f292a4
do no write multi descriptor when only one track is present
bcoudurier
parents:
3850
diff
changeset
|
967 mxf_write_uuid(pb, SubDescriptor, 0); |
|
3848
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
968 } |
|
1b5106f2b3f4
move mxf_write_package to permit function merge
bcoudurier
parents:
3847
diff
changeset
|
969 |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
970 // write timecode track |
|
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
971 mxf_write_track(s, mxf->timecode_track, type); |
|
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
972 mxf_write_sequence(s, mxf->timecode_track, type); |
|
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
973 mxf_write_timecode_component(s, mxf->timecode_track, type); |
|
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
974 |
| 3831 | 975 for (i = 0; i < s->nb_streams; i++) { |
|
3832
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
976 AVStream *st = s->streams[i]; |
|
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
977 mxf_write_track(s, st, type); |
|
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
978 mxf_write_sequence(s, st, type); |
|
f3a099c0fdf8
simplify, pass AVStream directly instead of index
bcoudurier
parents:
3831
diff
changeset
|
979 mxf_write_structural_component(s, st, type); |
| 3743 | 980 |
| 981 if (type == SourcePackage) { | |
|
3845
c266530d56b4
merge descriptor write table with essence container uls table and simplify
bcoudurier
parents:
3844
diff
changeset
|
982 MXFStreamContext *sc = st->priv_data; |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
983 mxf_essence_container_uls[sc->index].write_desc(s, st); |
| 3743 | 984 } |
| 985 } | |
| 986 } | |
| 987 | |
| 4279 | 988 static int mxf_write_essence_container_data(AVFormatContext *s) |
| 989 { | |
| 990 ByteIOContext *pb = s->pb; | |
| 991 | |
| 992 mxf_write_metadata_key(pb, 0x012300); | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
993 klv_encode_ber_length(pb, 72); |
| 4279 | 994 |
| 995 mxf_write_local_tag(pb, 16, 0x3C0A); // Instance UID | |
| 996 mxf_write_uuid(pb, EssenceContainerData, 0); | |
| 997 | |
| 998 mxf_write_local_tag(pb, 32, 0x2701); // Linked Package UID | |
| 4696 | 999 mxf_write_umid(s, 1); |
| 4279 | 1000 |
| 1001 mxf_write_local_tag(pb, 4, 0x3F07); // BodySID | |
| 1002 put_be32(pb, 1); | |
| 1003 | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1004 mxf_write_local_tag(pb, 4, 0x3F06); // IndexSID |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1005 put_be32(pb, 2); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1006 |
| 4279 | 1007 return 0; |
| 1008 } | |
| 1009 | |
| 3740 | 1010 static int mxf_write_header_metadata_sets(AVFormatContext *s) |
| 1011 { | |
| 3749 | 1012 mxf_write_preface(s); |
| 1013 mxf_write_identification(s); | |
| 1014 mxf_write_content_storage(s); | |
| 3849 | 1015 mxf_write_package(s, MaterialPackage); |
| 1016 mxf_write_package(s, SourcePackage); | |
| 4279 | 1017 mxf_write_essence_container_data(s); |
| 3740 | 1018 return 0; |
| 1019 } | |
| 1020 | |
|
4397
6d1626886974
only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents:
4396
diff
changeset
|
1021 static unsigned klv_fill_size(uint64_t size) |
| 4393 | 1022 { |
|
4397
6d1626886974
only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents:
4396
diff
changeset
|
1023 unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1)); |
|
4469
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
1024 if (pad < 20) // smallest fill item possible |
| 4393 | 1025 return pad + KAG_SIZE; |
| 1026 else | |
| 1027 return pad & (KAG_SIZE-1); | |
| 1028 } | |
| 1029 | |
| 4408 | 1030 static void mxf_write_index_table_segment(AVFormatContext *s) |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1031 { |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1032 MXFContext *mxf = s->priv_data; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1033 ByteIOContext *pb = s->pb; |
| 4408 | 1034 int i, j; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1035 int temporal_reordering = 0; |
|
4446
efe78f986bec
fix last keyframe index accross body partitions
bcoudurier
parents:
4445
diff
changeset
|
1036 int key_index = mxf->last_key_index; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1037 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1038 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1039 |
| 4473 | 1040 if (!mxf->edit_units_count && !mxf->edit_unit_byte_count) |
| 4440 | 1041 return; |
| 1042 | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1043 put_buffer(pb, index_table_segment_key, 16); |
| 4473 | 1044 |
| 1045 if (mxf->edit_unit_byte_count) { | |
| 4531 | 1046 klv_encode_ber_length(pb, 80); |
| 4473 | 1047 } else { |
| 1048 klv_encode_ber_length(pb, 85 + 12+(s->nb_streams+1)*6 + | |
| 1049 12+mxf->edit_units_count*(11+mxf->slice_count*4)); | |
| 1050 } | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1051 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1052 // instance id |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1053 mxf_write_local_tag(pb, 16, 0x3C0A); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1054 mxf_write_uuid(pb, IndexTableSegment, 0); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1055 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1056 // index edit rate |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1057 mxf_write_local_tag(pb, 8, 0x3F0B); |
| 4574 | 1058 put_be32(pb, mxf->time_base.den); |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1059 put_be32(pb, mxf->time_base.num); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1060 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1061 // index start position |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1062 mxf_write_local_tag(pb, 8, 0x3F0C); |
| 4440 | 1063 put_be64(pb, mxf->last_indexed_edit_unit); |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1064 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1065 // index duration |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1066 mxf_write_local_tag(pb, 8, 0x3F0D); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1067 put_be64(pb, mxf->edit_units_count); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1068 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1069 // edit unit byte count |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1070 mxf_write_local_tag(pb, 4, 0x3F05); |
| 4473 | 1071 put_be32(pb, mxf->edit_unit_byte_count); |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1072 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1073 // index sid |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1074 mxf_write_local_tag(pb, 4, 0x3F06); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1075 put_be32(pb, 2); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1076 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1077 // body sid |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1078 mxf_write_local_tag(pb, 4, 0x3F07); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1079 put_be32(pb, 1); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1080 |
| 4531 | 1081 if (!mxf->edit_unit_byte_count) { |
| 1082 // real slice count - 1 | |
| 1083 mxf_write_local_tag(pb, 1, 0x3F08); | |
| 1084 put_byte(pb, mxf->slice_count); | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1085 |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1086 // delta entry array |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1087 mxf_write_local_tag(pb, 8 + (s->nb_streams+1)*6, 0x3F09); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1088 put_be32(pb, s->nb_streams+1); // num of entries |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1089 put_be32(pb, 6); // size of one entry |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1090 // write system item delta entry |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1091 put_byte(pb, 0); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1092 put_byte(pb, 0); // slice entry |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1093 put_be32(pb, 0); // element delta |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1094 for (i = 0; i < s->nb_streams; i++) { |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1095 AVStream *st = s->streams[i]; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1096 MXFStreamContext *sc = st->priv_data; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1097 put_byte(pb, sc->temporal_reordering); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1098 if (sc->temporal_reordering) |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1099 temporal_reordering = 1; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1100 if (i == 0) { // video track |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1101 put_byte(pb, 0); // slice number |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1102 put_be32(pb, KAG_SIZE); // system item size including klv fill |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1103 } else { // audio track |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1104 unsigned audio_frame_size = sc->aic.samples[0]*sc->aic.sample_size; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1105 audio_frame_size += klv_fill_size(audio_frame_size); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1106 put_byte(pb, 1); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1107 put_be32(pb, (i-1)*audio_frame_size); // element delta |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1108 } |
|
4397
6d1626886974
only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents:
4396
diff
changeset
|
1109 } |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1110 |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1111 mxf_write_local_tag(pb, 8 + mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1112 put_be32(pb, mxf->edit_units_count); // num of entries |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1113 put_be32(pb, 11+mxf->slice_count*4); // size of one entry |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1114 for (i = 0; i < mxf->edit_units_count; i++) { |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1115 if (temporal_reordering) { |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1116 int temporal_offset = 0; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1117 for (j = i+1; j < mxf->edit_units_count; j++) { |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1118 temporal_offset++; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1119 if (mxf->index_entries[j].flags & 0x10) { // backward prediction |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1120 // next is not b, so is reordered |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1121 if (!(mxf->index_entries[i+1].flags & 0x10)) { |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1122 if ((mxf->index_entries[i].flags & 0x11) == 0) // i frame |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1123 temporal_offset = 0; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1124 else |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1125 temporal_offset = -temporal_offset; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1126 } |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1127 break; |
|
4344
582124bb2c15
fix temporal offet of ipbb sequences, simplification welcome
bcoudurier
parents:
4343
diff
changeset
|
1128 } |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1129 } |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1130 put_byte(pb, temporal_offset); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1131 } else |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1132 put_byte(pb, 0); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1133 if (!(mxf->index_entries[i].flags & 0x33)) { // I frame |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1134 mxf->last_key_index = key_index; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1135 key_index = i; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1136 } |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1137 if (mxf->index_entries[i].flags & 0x10 && // backward prediction |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1138 !(mxf->index_entries[key_index].flags & 0x80)) { // open gop |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1139 put_byte(pb, mxf->last_key_index - i); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1140 } else { |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1141 put_byte(pb, key_index - i); // key frame offset |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1142 if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1143 mxf->last_key_index = key_index; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1144 } |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1145 put_byte(pb, mxf->index_entries[i].flags); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1146 // stream offset |
|
4481
27fd3af46000
compute body offset and index entry offset correctly
bcoudurier
parents:
4478
diff
changeset
|
1147 put_be64(pb, mxf->index_entries[i].offset); |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1148 if (s->nb_streams > 1) |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1149 put_be32(pb, mxf->index_entries[i].slice_offset); |
| 4378 | 1150 } |
| 4440 | 1151 |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1152 mxf->last_key_index = key_index - mxf->edit_units_count; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1153 mxf->last_indexed_edit_unit += mxf->edit_units_count; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1154 mxf->edit_units_count = 0; |
| 4473 | 1155 } |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1156 } |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1157 |
|
4432
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1158 static void mxf_write_klv_fill(AVFormatContext *s) |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1159 { |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1160 unsigned pad = klv_fill_size(url_ftell(s->pb)); |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1161 if (pad) { |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1162 put_buffer(s->pb, klv_fill_key, 16); |
|
4469
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
1163 pad -= 16 + 4; |
|
49cf858ac430
encode klv fill item length in fixed ber 4 bytes
bcoudurier
parents:
4461
diff
changeset
|
1164 klv_encode_ber4_length(s->pb, pad); |
|
4432
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1165 for (; pad; pad--) |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1166 put_byte(s->pb, 0); |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1167 assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1168 } |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1169 } |
|
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1170 |
| 4370 | 1171 static void mxf_write_partition(AVFormatContext *s, int bodysid, |
|
4439
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1172 int indexsid, |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1173 const uint8_t *key, int write_metadata) |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1174 { |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1175 MXFContext *mxf = s->priv_data; |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1176 ByteIOContext *pb = s->pb; |
| 3843 | 1177 int64_t header_byte_count_offset; |
|
4439
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1178 unsigned index_byte_count = 0; |
|
4442
85f1c6887bef
fix partition offset when only one stream present
bcoudurier
parents:
4441
diff
changeset
|
1179 uint64_t partition_offset = url_ftell(pb); |
|
4439
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1180 |
| 4473 | 1181 if (!mxf->edit_unit_byte_count && mxf->edit_units_count) |
| 1182 index_byte_count = 85 + 12+(s->nb_streams+1)*6 + | |
| 1183 12+mxf->edit_units_count*(11+mxf->slice_count*4); | |
| 1184 else if (mxf->edit_unit_byte_count && indexsid) | |
| 4537 | 1185 index_byte_count = 80; |
| 4473 | 1186 |
| 1187 if (index_byte_count) { | |
|
4439
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1188 // add encoded ber length |
|
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1189 index_byte_count += 16 + klv_ber_length(index_byte_count); |
|
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1190 index_byte_count += klv_fill_size(index_byte_count); |
| 4440 | 1191 } |
| 1192 | |
| 1193 if (!memcmp(key, body_partition_key, 16)) { | |
| 1194 mxf->body_partition_offset = | |
| 1195 av_realloc(mxf->body_partition_offset, | |
| 1196 (mxf->body_partitions_count+1)* | |
| 1197 sizeof(*mxf->body_partition_offset)); | |
|
4442
85f1c6887bef
fix partition offset when only one stream present
bcoudurier
parents:
4441
diff
changeset
|
1198 mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset; |
|
4439
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1199 } |
|
3812
1db39c874eb7
cosmetics, remove useless braces, move comments where appropriate, remove whitespaces
bcoudurier
parents:
3811
diff
changeset
|
1200 |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1201 // write klv |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1202 put_buffer(pb, key, 16); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1203 klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count); |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1204 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1205 // write partition value |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1206 put_be16(pb, 1); // majorVersion |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1207 put_be16(pb, 2); // minorVersion |
| 4393 | 1208 put_be32(pb, KAG_SIZE); // KAGSize |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1209 |
|
4442
85f1c6887bef
fix partition offset when only one stream present
bcoudurier
parents:
4441
diff
changeset
|
1210 put_be64(pb, partition_offset); // ThisPartition |
| 4440 | 1211 |
| 1212 if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1) | |
| 1213 put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition | |
| 4460 | 1214 else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count) |
| 4440 | 1215 put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition |
| 1216 else | |
| 1217 put_be64(pb, 0); | |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1218 |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1219 put_be64(pb, mxf->footer_partition_offset); // footerPartition |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1220 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1221 // set offset |
| 3843 | 1222 header_byte_count_offset = url_ftell(pb); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1223 put_be64(pb, 0); // headerByteCount, update later |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1224 |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1225 // indexTable |
| 4370 | 1226 put_be64(pb, index_byte_count); // indexByteCount |
|
4439
4bc3b8687ec2
compute index byte count in mxf_write_partition
bcoudurier
parents:
4438
diff
changeset
|
1227 put_be32(pb, index_byte_count ? indexsid : 0); // indexSID |
| 4440 | 1228 |
| 1229 // BodyOffset | |
| 4473 | 1230 if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) { |
|
4481
27fd3af46000
compute body offset and index entry offset correctly
bcoudurier
parents:
4478
diff
changeset
|
1231 put_be64(pb, mxf->body_offset); |
| 4445 | 1232 } else |
| 1233 put_be64(pb, 0); | |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1234 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1235 put_be32(pb, bodysid); // bodySID |
| 4430 | 1236 |
| 1237 // operational pattern | |
|
4536
b94bedbb59d7
always use multi track since timecode track is present
bcoudurier
parents:
4535
diff
changeset
|
1238 put_buffer(pb, op1a_ul, 16); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1239 |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1240 // essence container |
| 3821 | 1241 mxf_write_essence_container_refs(s); |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1242 |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1243 if (write_metadata) { |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1244 // mark the start of the headermetadata and calculate metadata size |
| 4433 | 1245 int64_t pos, start; |
| 4393 | 1246 unsigned header_byte_count; |
| 1247 | |
|
4432
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1248 mxf_write_klv_fill(s); |
| 4433 | 1249 start = url_ftell(s->pb); |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1250 mxf_write_primer_pack(s); |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1251 mxf_write_header_metadata_sets(s); |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1252 pos = url_ftell(s->pb); |
|
4397
6d1626886974
only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents:
4396
diff
changeset
|
1253 header_byte_count = pos - start + klv_fill_size(pos); |
| 4393 | 1254 |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1255 // update header_byte_count |
| 3843 | 1256 url_fseek(pb, header_byte_count_offset, SEEK_SET); |
| 4393 | 1257 put_be64(pb, header_byte_count); |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1258 url_fseek(pb, pos, SEEK_SET); |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1259 } |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1260 |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1261 put_flush_packet(pb); |
|
3760
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1262 } |
|
fde28855a81e
Import more ok'ed chunks of the mxf muxer from the soc tree
vitor
parents:
3759
diff
changeset
|
1263 |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1264 static const UID mxf_mpeg2_codec_uls[] = { |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1265 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x10,0x00 }, // MP-ML I-Frame |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1266 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, // MP-ML Long GOP |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1267 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, // 422P-ML I-Frame |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1268 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, // 422P-ML Long GOP |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1269 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x02,0x00 }, // MP-HL I-Frame |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1270 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1271 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1272 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1273 }; |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1274 |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1275 static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx) |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1276 { |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1277 if (avctx->profile == 4) { // Main |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1278 if (avctx->level == 8) // Main |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1279 return avctx->gop_size ? |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1280 &mxf_mpeg2_codec_uls[1] : |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1281 &mxf_mpeg2_codec_uls[0]; |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1282 else if (avctx->level == 4) // High |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1283 return avctx->gop_size ? |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1284 &mxf_mpeg2_codec_uls[5] : |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1285 &mxf_mpeg2_codec_uls[4]; |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1286 } else if (avctx->profile == 0) { // 422 |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1287 if (avctx->level == 5) // Main |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1288 return avctx->gop_size ? |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1289 &mxf_mpeg2_codec_uls[3] : |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1290 &mxf_mpeg2_codec_uls[2]; |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1291 else if (avctx->level == 2) // High |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1292 return avctx->gop_size ? |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1293 &mxf_mpeg2_codec_uls[7] : |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1294 &mxf_mpeg2_codec_uls[6]; |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1295 } |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1296 return NULL; |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1297 } |
|
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1298 |
|
4437
9cb07916bf47
retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents:
4436
diff
changeset
|
1299 static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, int *flags) |
| 4313 | 1300 { |
| 1301 MXFStreamContext *sc = st->priv_data; | |
| 4449 | 1302 MXFContext *mxf = s->priv_data; |
| 4313 | 1303 uint32_t c = -1; |
| 1304 int i; | |
| 1305 | |
|
4437
9cb07916bf47
retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents:
4436
diff
changeset
|
1306 *flags = 0; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1307 |
| 4313 | 1308 for(i = 0; i < pkt->size - 4; i++) { |
| 1309 c = (c<<8) + pkt->data[i]; | |
| 1310 if (c == 0x1B5) { | |
| 1311 if (i + 2 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x10) { // seq ext | |
| 1312 st->codec->profile = pkt->data[i+1] & 0x07; | |
| 1313 st->codec->level = pkt->data[i+2] >> 4; | |
| 4314 | 1314 } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext |
| 1315 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame | |
| 4313 | 1316 break; |
| 1317 } | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1318 } else if (c == 0x1b8) { // gop |
| 4449 | 1319 if (i + 4 < pkt->size) { |
| 1320 if (pkt->data[i+4]>>6 & 0x01) // closed | |
| 1321 *flags |= 0x80; // random access | |
| 1322 if (!mxf->header_written) { | |
| 1323 unsigned hours = (pkt->data[i+1]>>2) & 0x1f; | |
| 1324 unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4); | |
| 1325 unsigned seconds = ((pkt->data[i+2] & 0x07) << 3) | (pkt->data[i+3]>>5); | |
| 1326 unsigned frames = ((pkt->data[i+3] & 0x1f) << 1) | (pkt->data[i+4]>>7); | |
| 1327 mxf->timecode_drop_frame = !!(pkt->data[i+1] & 0x80); | |
| 1328 mxf->timecode_start = (hours*3600 + minutes*60 + seconds) * | |
| 1329 mxf->timecode_base + frames; | |
| 1330 if (mxf->timecode_drop_frame) { | |
| 1331 unsigned tminutes = 60 * hours + minutes; | |
| 1332 mxf->timecode_start -= 2 * (tminutes - tminutes / 10); | |
| 1333 } | |
| 1334 av_log(s, AV_LOG_DEBUG, "frame %d %d:%d:%d%c%d\n", mxf->timecode_start, | |
| 1335 hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames); | |
| 1336 } | |
| 1337 } | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1338 } else if (c == 0x1b3) { // seq |
|
4437
9cb07916bf47
retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents:
4436
diff
changeset
|
1339 *flags |= 0x40; |
| 4505 | 1340 if (i + 4 < pkt->size) { |
| 1341 switch ((pkt->data[i+4]>>4) & 0xf) { | |
| 1342 case 2: sc->aspect_ratio = (AVRational){ 4, 3}; break; | |
| 1343 case 3: sc->aspect_ratio = (AVRational){ 16, 9}; break; | |
| 1344 case 4: sc->aspect_ratio = (AVRational){221,100}; break; | |
| 1345 default: | |
| 1346 av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, | |
| 1347 st->codec->width, st->codec->height, 1024*1024); | |
| 1348 } | |
| 1349 } | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1350 } else if (c == 0x100) { // pic |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1351 int pict_type = (pkt->data[i+2]>>3) & 0x07; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1352 if (pict_type == 2) { // P frame |
|
4437
9cb07916bf47
retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents:
4436
diff
changeset
|
1353 *flags |= 0x22; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1354 st->codec->gop_size = 1; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1355 } else if (pict_type == 3) { // B frame |
|
4437
9cb07916bf47
retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents:
4436
diff
changeset
|
1356 *flags |= 0x33; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1357 sc->temporal_reordering = -1; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1358 } else if (!pict_type) { |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1359 av_log(s, AV_LOG_ERROR, "error parsing mpeg2 frame\n"); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1360 return 0; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1361 } |
| 4313 | 1362 } |
| 1363 } | |
| 4473 | 1364 if (s->oformat != &mxf_d10_muxer) |
| 1365 sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec); | |
| 4313 | 1366 return !!sc->codec_ul; |
| 1367 } | |
| 1368 | |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1369 static uint64_t mxf_parse_timestamp(time_t timestamp) |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1370 { |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1371 struct tm *time = localtime(×tamp); |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1372 return (uint64_t)(time->tm_year+1900) << 48 | |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1373 (uint64_t)(time->tm_mon+1) << 40 | |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1374 (uint64_t) time->tm_mday << 32 | |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1375 time->tm_hour << 24 | |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1376 time->tm_min << 16 | |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1377 time->tm_sec << 8; |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1378 } |
|
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1379 |
| 4696 | 1380 static void mxf_gen_umid(AVFormatContext *s) |
| 1381 { | |
| 1382 MXFContext *mxf = s->priv_data; | |
| 1383 uint32_t seed = ff_random_get_seed(); | |
| 1384 uint64_t umid = seed + 0x5294713400000000LL; | |
| 1385 | |
| 1386 AV_WB64(mxf->umid , umid); | |
| 1387 AV_WB64(mxf->umid+8, umid>>8); | |
| 1388 | |
| 1389 mxf->instance_number = seed; | |
| 1390 } | |
| 1391 | |
| 3836 | 1392 static int mxf_write_header(AVFormatContext *s) |
| 3749 | 1393 { |
| 1394 MXFContext *mxf = s->priv_data; | |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
1395 int i; |
| 4001 | 1396 uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1397 const int *samples_per_frame = NULL; |
|
3816
50bdbde13ecf
move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents:
3815
diff
changeset
|
1398 |
| 4696 | 1399 if (!s->nb_streams) |
| 1400 return -1; | |
| 1401 | |
|
3816
50bdbde13ecf
move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents:
3815
diff
changeset
|
1402 for (i = 0; i < s->nb_streams; i++) { |
|
50bdbde13ecf
move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents:
3815
diff
changeset
|
1403 AVStream *st = s->streams[i]; |
| 3824 | 1404 MXFStreamContext *sc = av_mallocz(sizeof(*sc)); |
|
3816
50bdbde13ecf
move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents:
3815
diff
changeset
|
1405 if (!sc) |
|
50bdbde13ecf
move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents:
3815
diff
changeset
|
1406 return AVERROR(ENOMEM); |
|
50bdbde13ecf
move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents:
3815
diff
changeset
|
1407 st->priv_data = sc; |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1408 |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1409 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
| 4396 | 1410 if (i != 0) { |
| 1411 av_log(s, AV_LOG_ERROR, "video stream must be first track\n"); | |
| 1412 return -1; | |
| 1413 } | |
| 4363 | 1414 if (fabs(av_q2d(st->codec->time_base) - 1/25.0) < 0.0001) { |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1415 samples_per_frame = PAL_samples_per_frame; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1416 mxf->time_base = (AVRational){ 1, 25 }; |
| 4448 | 1417 mxf->timecode_base = 25; |
| 4363 | 1418 } else if (fabs(av_q2d(st->codec->time_base) - 1001/30000.0) < 0.0001) { |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1419 samples_per_frame = NTSC_samples_per_frame; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1420 mxf->time_base = (AVRational){ 1001, 30000 }; |
| 4448 | 1421 mxf->timecode_base = 30; |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1422 } else { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1423 av_log(s, AV_LOG_ERROR, "unsupported video frame rate\n"); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1424 return -1; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1425 } |
| 4374 | 1426 av_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den); |
| 4473 | 1427 if (s->oformat == &mxf_d10_muxer) { |
| 1428 if (st->codec->bit_rate == 50000000) | |
| 1429 if (mxf->time_base.den == 25) sc->index = 3; | |
| 1430 else sc->index = 5; | |
| 1431 else if (st->codec->bit_rate == 40000000) | |
| 1432 if (mxf->time_base.den == 25) sc->index = 7; | |
| 1433 else sc->index = 9; | |
| 1434 else if (st->codec->bit_rate == 30000000) | |
| 1435 if (mxf->time_base.den == 25) sc->index = 11; | |
| 1436 else sc->index = 13; | |
| 1437 else { | |
| 1438 av_log(s, AV_LOG_ERROR, "error MXF D-10 only support 30/40/50 mbit/s\n"); | |
| 1439 return -1; | |
| 1440 } | |
| 1441 | |
| 1442 mxf->edit_unit_byte_count = KAG_SIZE; // system element | |
| 1443 mxf->edit_unit_byte_count += 16 + 4 + (uint64_t)st->codec->bit_rate * | |
| 1444 mxf->time_base.num / (8*mxf->time_base.den); | |
| 1445 mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); | |
| 1446 mxf->edit_unit_byte_count += 16 + 4 + 4 + samples_per_frame[0]*8*4; | |
| 1447 mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); | |
| 1448 } | |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1449 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1450 if (st->codec->sample_rate != 48000) { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1451 av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n"); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1452 return -1; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1453 } |
| 4374 | 1454 av_set_pts_info(st, 64, 1, st->codec->sample_rate); |
| 4473 | 1455 if (s->oformat == &mxf_d10_muxer) { |
| 1456 if (st->index != 1) { | |
| 1457 av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n"); | |
| 1458 return -1; | |
| 1459 } | |
| 1460 if (st->codec->codec_id != CODEC_ID_PCM_S16LE && | |
| 1461 st->codec->codec_id != CODEC_ID_PCM_S24LE) { | |
| 1462 av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n"); | |
| 1463 } | |
| 1464 sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1; | |
| 1465 } else | |
|
4397
6d1626886974
only use 2 slices for index, one video(vbr) and one audio(cbr)
bcoudurier
parents:
4396
diff
changeset
|
1466 mxf->slice_count = 1; |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1467 } |
| 3834 | 1468 |
| 4473 | 1469 if (!sc->index) { |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1470 sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1471 if (sc->index == -1) { |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1472 av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, " |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1473 "codec not currently supported in container\n", i); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1474 return -1; |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1475 } |
| 4473 | 1476 } |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1477 |
| 4313 | 1478 sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul; |
|
3833
8b3fdbc81f3e
correctly write codec ul, mpeg-2 needs profile and level to be set
bcoudurier
parents:
3832
diff
changeset
|
1479 |
|
3846
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
1480 memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15); |
|
0ee95f0b4c00
store index in table in MXFStreamContext, simplify
bcoudurier
parents:
3845
diff
changeset
|
1481 sc->track_essence_element_key[15] = present[sc->index]; |
|
3826
da2d0c162cde
introduce MXFContainerEssencePair to associate essence element key and
bcoudurier
parents:
3825
diff
changeset
|
1482 PRINT_KEY(s, "track essence element key", sc->track_essence_element_key); |
| 4533 | 1483 |
| 1484 if (!present[sc->index]) | |
| 1485 mxf->essence_container_count++; | |
| 1486 present[sc->index]++; | |
|
3816
50bdbde13ecf
move per track code in mxf_write_header to be able to check for unsupported configuration
bcoudurier
parents:
3815
diff
changeset
|
1487 } |
| 3749 | 1488 |
| 4473 | 1489 if (s->oformat == &mxf_d10_muxer) { |
| 1490 mxf->essence_container_count = 1; | |
| 1491 } | |
| 1492 | |
| 4696 | 1493 if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) |
| 1494 mxf_gen_umid(s); | |
| 1495 | |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1496 for (i = 0; i < s->nb_streams; i++) { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1497 MXFStreamContext *sc = s->streams[i]->priv_data; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1498 // update element count |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1499 sc->track_essence_element_key[13] = present[sc->index]; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1500 sc->order = AV_RB32(sc->track_essence_element_key+12); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1501 } |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1502 |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1503 mxf->timestamp = mxf_parse_timestamp(s->timestamp); |
| 4448 | 1504 mxf->duration = -1; |
| 1505 | |
| 1506 mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track)); | |
| 1507 if (!mxf->timecode_track) | |
| 1508 return AVERROR(ENOMEM); | |
| 1509 mxf->timecode_track->priv_data = av_mallocz(sizeof(MXFStreamContext)); | |
| 1510 if (!mxf->timecode_track->priv_data) | |
| 1511 return AVERROR(ENOMEM); | |
|
4529
ade95792aa16
use index 0 for timecode track and write it in source package also
bcoudurier
parents:
4528
diff
changeset
|
1512 mxf->timecode_track->index = -1; |
|
4385
e8e064a00ea5
format timestamp correctly according to specs and set it
bcoudurier
parents:
4384
diff
changeset
|
1513 |
|
4327
60bad0ded22a
do not use PAL_samples_per_frame in init, to make init independant
bcoudurier
parents:
4326
diff
changeset
|
1514 if (!samples_per_frame) |
|
60bad0ded22a
do not use PAL_samples_per_frame in init, to make init independant
bcoudurier
parents:
4326
diff
changeset
|
1515 samples_per_frame = PAL_samples_per_frame; |
|
60bad0ded22a
do not use PAL_samples_per_frame in init, to make init independant
bcoudurier
parents:
4326
diff
changeset
|
1516 |
| 4374 | 1517 if (ff_audio_interleave_init(s, samples_per_frame, mxf->time_base) < 0) |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1518 return -1; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1519 |
| 3749 | 1520 return 0; |
| 1521 } | |
| 1522 | |
| 4395 | 1523 static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 }; |
| 1524 static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 }; | |
| 1525 | |
| 1526 static uint32_t ff_framenum_to_12m_time_code(unsigned frame, int drop, int fps) | |
| 1527 { | |
| 1528 return (0 << 31) | // color frame flag | |
| 1529 (0 << 30) | // drop frame flag | |
| 1530 ( ((frame % fps) / 10) << 28) | // tens of frames | |
| 1531 ( ((frame % fps) % 10) << 24) | // units of frames | |
| 1532 (0 << 23) | // field phase (NTSC), b0 (PAL) | |
| 1533 ((((frame / fps) % 60) / 10) << 20) | // tens of seconds | |
| 1534 ((((frame / fps) % 60) % 10) << 16) | // units of seconds | |
| 1535 (0 << 15) | // b0 (NTSC), b2 (PAL) | |
| 1536 ((((frame / (fps * 60)) % 60) / 10) << 12) | // tens of minutes | |
| 1537 ((((frame / (fps * 60)) % 60) % 10) << 8) | // units of minutes | |
| 1538 (0 << 7) | // b1 | |
| 1539 (0 << 6) | // b2 (NSC), field phase (PAL) | |
| 1540 ((((frame / (fps * 3600) % 24)) / 10) << 4) | // tens of hours | |
| 1541 ( (frame / (fps * 3600) % 24)) % 10; // units of hours | |
| 1542 } | |
| 1543 | |
| 1544 static void mxf_write_system_item(AVFormatContext *s) | |
| 1545 { | |
| 1546 MXFContext *mxf = s->priv_data; | |
| 1547 ByteIOContext *pb = s->pb; | |
| 4448 | 1548 unsigned frame; |
| 4395 | 1549 uint32_t time_code; |
| 1550 | |
| 4449 | 1551 frame = mxf->timecode_start + mxf->last_indexed_edit_unit + mxf->edit_units_count; |
| 4395 | 1552 |
| 1553 // write system metadata pack | |
| 1554 put_buffer(pb, system_metadata_pack_key, 16); | |
|
4470
1c6dd9d7a634
write essence elements klv packets with ber4 length, more interoperable
bcoudurier
parents:
4469
diff
changeset
|
1555 klv_encode_ber4_length(pb, 57); |
| 4395 | 1556 put_byte(pb, 0x5c); // UL, user date/time stamp, picture and sound item present |
| 1557 put_byte(pb, 0x04); // content package rate | |
| 1558 put_byte(pb, 0x00); // content package type | |
| 1559 put_be16(pb, 0x00); // channel handle | |
| 1560 put_be16(pb, frame); // continuity count | |
| 1561 if (mxf->essence_container_count > 1) | |
| 1562 put_buffer(pb, multiple_desc_ul, 16); | |
| 4475 | 1563 else { |
| 1564 MXFStreamContext *sc = s->streams[0]->priv_data; | |
| 1565 put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16); | |
| 1566 } | |
| 4395 | 1567 put_byte(pb, 0); |
| 1568 put_be64(pb, 0); | |
| 1569 put_be64(pb, 0); // creation date/time stamp | |
| 1570 | |
| 1571 put_byte(pb, 0x81); // SMPTE 12M time code | |
| 4448 | 1572 time_code = ff_framenum_to_12m_time_code(frame, mxf->timecode_drop_frame, mxf->timecode_base); |
| 4395 | 1573 put_be32(pb, time_code); |
| 1574 put_be32(pb, 0); // binary group data | |
| 1575 put_be64(pb, 0); | |
| 1576 | |
| 1577 // write system metadata package set | |
| 1578 put_buffer(pb, system_metadata_package_set_key, 16); | |
|
4470
1c6dd9d7a634
write essence elements klv packets with ber4 length, more interoperable
bcoudurier
parents:
4469
diff
changeset
|
1579 klv_encode_ber4_length(pb, 35); |
| 4395 | 1580 put_byte(pb, 0x83); // UMID |
| 1581 put_be16(pb, 0x20); | |
| 4696 | 1582 mxf_write_umid(s, 1); |
| 4395 | 1583 } |
| 1584 | |
| 4473 | 1585 static void mxf_write_d10_video_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) |
| 1586 { | |
| 1587 MXFContext *mxf = s->priv_data; | |
| 1588 ByteIOContext *pb = s->pb; | |
| 1589 int packet_size = (uint64_t)st->codec->bit_rate*mxf->time_base.num / | |
| 1590 (8*mxf->time_base.den); // frame size | |
| 1591 int pad; | |
| 1592 | |
| 1593 packet_size += 16 + 4; | |
| 1594 packet_size += klv_fill_size(packet_size); | |
| 1595 | |
| 1596 klv_encode_ber4_length(pb, pkt->size); | |
| 1597 put_buffer(pb, pkt->data, pkt->size); | |
| 1598 | |
| 1599 // ensure CBR muxing by padding to correct video frame size | |
| 1600 pad = packet_size - pkt->size - 16 - 4; | |
| 1601 if (pad > 20) { | |
| 1602 put_buffer(s->pb, klv_fill_key, 16); | |
| 1603 pad -= 16 + 4; | |
| 1604 klv_encode_ber4_length(s->pb, pad); | |
| 1605 for (; pad; pad--) | |
| 1606 put_byte(s->pb, 0); | |
| 1607 assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); | |
| 1608 } else { | |
| 1609 av_log(s, AV_LOG_WARNING, "cannot fill d-10 video packet\n"); | |
| 1610 for (; pad > 0; pad--) | |
| 1611 put_byte(s->pb, 0); | |
| 1612 } | |
| 1613 } | |
| 1614 | |
| 1615 static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
| 1616 { | |
| 1617 MXFContext *mxf = s->priv_data; | |
| 1618 ByteIOContext *pb = s->pb; | |
| 4573 | 1619 int frame_size = pkt->size / st->codec->block_align; |
| 4473 | 1620 uint8_t *samples = pkt->data; |
| 1621 uint8_t *end = pkt->data + pkt->size; | |
| 1622 int i; | |
| 1623 | |
| 1624 klv_encode_ber4_length(pb, 4 + frame_size*4*8); | |
| 1625 | |
| 1626 put_byte(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1)); | |
| 1627 put_le16(pb, frame_size); | |
| 1628 put_byte(pb, (1<<st->codec->channels)-1); | |
| 1629 | |
| 1630 while (samples < end) { | |
| 1631 for (i = 0; i < st->codec->channels; i++) { | |
| 1632 uint32_t sample; | |
| 1633 if (st->codec->codec_id == CODEC_ID_PCM_S24LE) { | |
|
4571
d870b1e4b731
do not set frame start bit since marked as not used and factorize
bcoudurier
parents:
4565
diff
changeset
|
1634 sample = AV_RL24(samples)<< 4; |
| 4473 | 1635 samples += 3; |
| 1636 } else { | |
|
4571
d870b1e4b731
do not set frame start bit since marked as not used and factorize
bcoudurier
parents:
4565
diff
changeset
|
1637 sample = AV_RL16(samples)<<12; |
| 4473 | 1638 samples += 2; |
| 1639 } | |
|
4571
d870b1e4b731
do not set frame start bit since marked as not used and factorize
bcoudurier
parents:
4565
diff
changeset
|
1640 put_le32(pb, sample | i); |
| 4473 | 1641 } |
| 1642 for (; i < 8; i++) | |
| 4572 | 1643 put_le32(pb, i); |
| 4473 | 1644 } |
| 1645 } | |
| 1646 | |
| 3836 | 1647 static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) |
| 3778 | 1648 { |
| 4313 | 1649 MXFContext *mxf = s->priv_data; |
| 3778 | 1650 ByteIOContext *pb = s->pb; |
| 1651 AVStream *st = s->streams[pkt->stream_index]; | |
| 1652 MXFStreamContext *sc = st->priv_data; | |
|
4437
9cb07916bf47
retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents:
4436
diff
changeset
|
1653 int flags = 0; |
| 3778 | 1654 |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1655 if (!mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) { |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1656 mxf->index_entries = av_realloc(mxf->index_entries, |
| 4440 | 1657 (mxf->edit_units_count + EDIT_UNITS_PER_BODY)*sizeof(*mxf->index_entries)); |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1658 if (!mxf->index_entries) { |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1659 av_log(s, AV_LOG_ERROR, "could not allocate index entries\n"); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1660 return -1; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1661 } |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1662 } |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1663 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1664 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) { |
|
4437
9cb07916bf47
retrieve flags from mxf_parse_mpeg2_frame using a param
bcoudurier
parents:
4436
diff
changeset
|
1665 if (!mxf_parse_mpeg2_frame(s, st, pkt, &flags)) { |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1666 av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n"); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1667 return -1; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1668 } |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1669 } |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1670 |
| 4313 | 1671 if (!mxf->header_written) { |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1672 if (mxf->edit_unit_byte_count) { |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1673 mxf_write_partition(s, 1, 2, header_open_partition_key, 1); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1674 mxf_write_klv_fill(s); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1675 mxf_write_index_table_segment(s); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1676 } else { |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1677 mxf_write_partition(s, 0, 0, header_open_partition_key, 1); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1678 } |
| 4313 | 1679 mxf->header_written = 1; |
| 1680 } | |
| 1681 | |
| 4396 | 1682 if (st->index == 0) { |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1683 if (!mxf->edit_unit_byte_count && |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1684 (!mxf->edit_units_count || mxf->edit_units_count > EDIT_UNITS_PER_BODY) && |
| 4440 | 1685 !(flags & 0x33)) { // I frame, Gop start |
| 1686 mxf_write_klv_fill(s); | |
| 1687 mxf_write_partition(s, 1, 2, body_partition_key, 0); | |
| 1688 | |
| 1689 mxf_write_klv_fill(s); | |
| 1690 mxf_write_index_table_segment(s); | |
| 1691 } | |
| 1692 | |
| 4436 | 1693 mxf_write_klv_fill(s); |
| 4395 | 1694 mxf_write_system_item(s); |
| 1695 | |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1696 if (!mxf->edit_unit_byte_count) { |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1697 mxf->index_entries[mxf->edit_units_count].offset = mxf->body_offset; |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1698 mxf->index_entries[mxf->edit_units_count].flags = flags; |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1699 mxf->body_offset += KAG_SIZE; // size of system element |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1700 } |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1701 mxf->edit_units_count++; |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1702 } else if (!mxf->edit_unit_byte_count && st->index == 1) { |
|
4481
27fd3af46000
compute body offset and index entry offset correctly
bcoudurier
parents:
4478
diff
changeset
|
1703 mxf->index_entries[mxf->edit_units_count-1].slice_offset = |
|
27fd3af46000
compute body offset and index entry offset correctly
bcoudurier
parents:
4478
diff
changeset
|
1704 mxf->body_offset - mxf->index_entries[mxf->edit_units_count-1].offset; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1705 } |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1706 |
|
4435
4f96c60c9561
cosmetics, associate mxf_write_klv_fill to aligned elements
bcoudurier
parents:
4434
diff
changeset
|
1707 mxf_write_klv_fill(s); |
| 3778 | 1708 put_buffer(pb, sc->track_essence_element_key, 16); // write key |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1709 if (s->oformat == &mxf_d10_muxer) { |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1710 if (st->codec->codec_type == CODEC_TYPE_VIDEO) |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1711 mxf_write_d10_video_packet(s, st, pkt); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1712 else |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1713 mxf_write_d10_audio_packet(s, st, pkt); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1714 } else { |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1715 klv_encode_ber4_length(pb, pkt->size); // write length |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1716 put_buffer(pb, pkt->data, pkt->size); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1717 mxf->body_offset += 16+4+pkt->size + klv_fill_size(16+4+pkt->size); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1718 } |
| 3778 | 1719 |
| 1720 put_flush_packet(pb); | |
|
4481
27fd3af46000
compute body offset and index entry offset correctly
bcoudurier
parents:
4478
diff
changeset
|
1721 |
| 3778 | 1722 return 0; |
| 1723 } | |
| 1724 | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1725 static void mxf_write_random_index_pack(AVFormatContext *s) |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1726 { |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1727 MXFContext *mxf = s->priv_data; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1728 ByteIOContext *pb = s->pb; |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1729 uint64_t pos = url_ftell(pb); |
| 4440 | 1730 int i; |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1731 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1732 put_buffer(pb, random_index_pack_key, 16); |
| 4440 | 1733 klv_encode_ber_length(pb, 28 + 12*mxf->body_partitions_count); |
| 1734 | |
| 4528 | 1735 if (mxf->edit_unit_byte_count) |
| 1736 put_be32(pb, 1); // BodySID of header partition | |
| 1737 else | |
| 4532 | 1738 put_be32(pb, 0); |
| 4440 | 1739 put_be64(pb, 0); // offset of header partition |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1740 |
| 4440 | 1741 for (i = 0; i < mxf->body_partitions_count; i++) { |
| 1742 put_be32(pb, 1); // BodySID | |
| 1743 put_be64(pb, mxf->body_partition_offset[i]); | |
| 1744 } | |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1745 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1746 put_be32(pb, 0); // BodySID of footer partition |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1747 put_be64(pb, mxf->footer_partition_offset); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1748 |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1749 put_be32(pb, url_ftell(pb) - pos + 4); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1750 } |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1751 |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1752 static int mxf_write_footer(AVFormatContext *s) |
| 3740 | 1753 { |
| 1754 MXFContext *mxf = s->priv_data; | |
| 1755 ByteIOContext *pb = s->pb; | |
| 4393 | 1756 |
| 4448 | 1757 mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count; |
| 1758 | |
| 4393 | 1759 mxf_write_klv_fill(s); |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1760 mxf->footer_partition_offset = url_ftell(pb); |
| 4473 | 1761 if (mxf->edit_unit_byte_count) { // no need to repeat index |
| 1762 mxf_write_partition(s, 0, 0, footer_partition_key, 0); | |
| 1763 } else { | |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1764 mxf_write_partition(s, 0, 2, footer_partition_key, 0); |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1765 |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1766 mxf_write_klv_fill(s); |
|
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1767 mxf_write_index_table_segment(s); |
| 4473 | 1768 } |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1769 |
|
4432
f8ba6cf226e7
move up mxf_write_klv_fill and align index, rip and primer pack
bcoudurier
parents:
4431
diff
changeset
|
1770 mxf_write_klv_fill(s); |
|
4341
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1771 mxf_write_random_index_pack(s); |
|
501d1dd19021
write index table and rip, muxer works pretty well now
bcoudurier
parents:
4340
diff
changeset
|
1772 |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1773 if (!url_is_streamed(s->pb)) { |
|
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1774 url_fseek(pb, 0, SEEK_SET); |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1775 if (mxf->edit_unit_byte_count) { |
| 4473 | 1776 mxf_write_partition(s, 1, 2, header_closed_partition_key, 1); |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1777 mxf_write_klv_fill(s); |
|
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1778 mxf_write_index_table_segment(s); |
| 4473 | 1779 } else { |
| 1780 mxf_write_partition(s, 0, 0, header_closed_partition_key, 1); | |
| 1781 } | |
|
3842
c4e0e02a4832
simplify and correctly rewrite metadata in header partition, mark it closed complete
bcoudurier
parents:
3841
diff
changeset
|
1782 } |
| 4330 | 1783 |
| 4530 | 1784 put_flush_packet(pb); |
| 1785 | |
| 4330 | 1786 ff_audio_interleave_close(s); |
| 1787 | |
| 4402 | 1788 av_freep(&mxf->index_entries); |
| 4440 | 1789 av_freep(&mxf->body_partition_offset); |
| 4448 | 1790 av_freep(&mxf->timecode_track->priv_data); |
| 1791 av_freep(&mxf->timecode_track); | |
| 4402 | 1792 |
| 3749 | 1793 mxf_free(s); |
|
4474
cfd03b6fab13
cosmetics, reindent, add/remove some empty lines, redundant comment
bcoudurier
parents:
4473
diff
changeset
|
1794 |
| 3740 | 1795 return 0; |
| 1796 } | |
| 3749 | 1797 |
|
4328
fb0fde31327a
change prototype of mxf_interleave_get_packet to make it compatible
bcoudurier
parents:
4327
diff
changeset
|
1798 static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1799 { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1800 AVPacketList *pktl; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1801 int stream_count = 0; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1802 int streams[MAX_STREAMS]; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1803 |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1804 memset(streams, 0, sizeof(streams)); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1805 pktl = s->packet_buffer; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1806 while (pktl) { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1807 //av_log(s, AV_LOG_DEBUG, "show st:%d dts:%lld\n", pktl->pkt.stream_index, pktl->pkt.dts); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1808 if (!streams[pktl->pkt.stream_index]) |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1809 stream_count++; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1810 streams[pktl->pkt.stream_index]++; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1811 pktl = pktl->next; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1812 } |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1813 |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1814 if (stream_count && (s->nb_streams == stream_count || flush)) { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1815 pktl = s->packet_buffer; |
| 4342 | 1816 if (s->nb_streams != stream_count) { |
| 4461 | 1817 AVPacketList *last = NULL; |
| 4500 | 1818 // find last packet in edit unit |
| 4342 | 1819 while (pktl) { |
| 4500 | 1820 if (!stream_count || pktl->pkt.stream_index == 0) |
| 4342 | 1821 break; |
| 4461 | 1822 last = pktl; |
| 4342 | 1823 pktl = pktl->next; |
| 4500 | 1824 stream_count--; |
| 4342 | 1825 } |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1826 // purge packet queue |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1827 while (pktl) { |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1828 AVPacketList *next = pktl->next; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1829 av_free_packet(&pktl->pkt); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1830 av_freep(&pktl); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1831 pktl = next; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1832 } |
| 4500 | 1833 if (last) |
| 1834 last->next = NULL; | |
| 1835 else { | |
| 1836 s->packet_buffer = NULL; | |
| 4342 | 1837 goto out; |
| 4500 | 1838 } |
| 1839 pktl = s->packet_buffer; | |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1840 } |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1841 |
| 4342 | 1842 *out = pktl->pkt; |
| 1843 //av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts); | |
| 1844 s->packet_buffer = pktl->next; | |
| 1845 av_freep(&pktl); | |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1846 return 1; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1847 } else { |
| 4342 | 1848 out: |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1849 av_init_packet(out); |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1850 return 0; |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1851 } |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1852 } |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1853 |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1854 static int mxf_compare_timestamps(AVFormatContext *s, AVPacket *next, AVPacket *pkt) |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1855 { |
| 4374 | 1856 MXFStreamContext *sc = s->streams[pkt ->stream_index]->priv_data; |
| 1857 MXFStreamContext *sc2 = s->streams[next->stream_index]->priv_data; | |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1858 |
| 4374 | 1859 return next->dts > pkt->dts || |
| 1860 (next->dts == pkt->dts && sc->order < sc2->order); | |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1861 } |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1862 |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1863 static int mxf_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1864 { |
|
4426
7854590fb1fd
rename ff_audio_interleave to ff_audio_rechunk_interleave
bcoudurier
parents:
4408
diff
changeset
|
1865 return ff_audio_rechunk_interleave(s, out, pkt, flush, |
|
4400
65adb9e5214f
extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
4397
diff
changeset
|
1866 mxf_interleave_get_packet, mxf_compare_timestamps); |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1867 } |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1868 |
| 3721 | 1869 AVOutputFormat mxf_muxer = { |
| 1870 "mxf", | |
| 1871 NULL_IF_CONFIG_SMALL("Material eXchange Format"), | |
| 4476 | 1872 "application/mxf", |
| 3721 | 1873 "mxf", |
| 1874 sizeof(MXFContext), | |
| 1875 CODEC_ID_PCM_S16LE, | |
| 1876 CODEC_ID_MPEG2VIDEO, | |
| 3836 | 1877 mxf_write_header, |
| 1878 mxf_write_packet, | |
| 1879 mxf_write_footer, | |
| 4350 | 1880 AVFMT_NOTIMESTAMPS, |
|
4312
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1881 NULL, |
|
385b2fdccbbb
correctly pack and interleave pcm samples in mxf
bcoudurier
parents:
4279
diff
changeset
|
1882 mxf_interleave, |
| 3721 | 1883 }; |
| 4473 | 1884 |
| 1885 AVOutputFormat mxf_d10_muxer = { | |
| 1886 "mxf_d10", | |
| 1887 NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"), | |
| 1888 "application/mxf", | |
| 1889 NULL, | |
| 1890 sizeof(MXFContext), | |
| 1891 CODEC_ID_PCM_S16LE, | |
| 1892 CODEC_ID_MPEG2VIDEO, | |
| 1893 mxf_write_header, | |
|
4504
c0803ee07a93
merge mxf_write_d10_packet into mxf_write_packet
bcoudurier
parents:
4500
diff
changeset
|
1894 mxf_write_packet, |
| 4473 | 1895 mxf_write_footer, |
| 1896 AVFMT_NOTIMESTAMPS, | |
| 1897 NULL, | |
| 1898 mxf_interleave, | |
| 1899 }; |
