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