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