1 /*
2 * MXF muxer
3 * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com>
4 * Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
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 #include <inttypes.h>
34 #include <math.h>
36
47 #include "config.h"
48
50
51 #define EDIT_UNITS_PER_BODY 250
53
58
65
69 int index;
///< index in mxf_essence_container_uls table
71 int order;
///< interleaving order if dts are equal
77 int closed_gop;
///< gop is closed, used in mpeg-2 frame parsing
79
86
87 static const struct {
97 };
98
104
106 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 },
107 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
108 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 },
110 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 },
111 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x03,0x00 },
112 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
114 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 },
115 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 },
116 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
118 // D-10 625/50 PAL 50mb/s
119 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,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,0x01 },
123 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,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 },
127 // D-10 525/60 NTSC 50mb/s
128 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,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,0x02 },
132 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,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 },
136 // D-10 625/50 PAL 40mb/s
137 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,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,0x03 },
141 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,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 },
145 // D-10 525/60 NTSC 40mb/s
146 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,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,0x04 },
150 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,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 },
154 // D-10 625/50 PAL 30mb/s
155 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,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,0x05 },
159 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,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 },
163 // D-10 525/60 NTSC 30mb/s
164 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 },
165 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
166 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 },
168 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 },
169 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
170 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
172 // DV Unknown
173 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x7F,0x01 },
174 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
175 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x00,0x00,0x00 },
177 // DV25 525/60
178 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x40,0x01 },
179 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
180 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x01,0x00 },
182 // DV25 625/50
183 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 },
184 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
185 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 },
187 // DV50 525/60
188 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x50,0x01 },
189 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
190 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x03,0x00 },
192 // DV50 625/50
193 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x51,0x01 },
194 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
195 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 },
197 // DV100 1080/60
198 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x60,0x01 },
199 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
200 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x05,0x00 },
202 // DV100 1080/50
203 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x61,0x01 },
204 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
205 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x06,0x00 },
207 // DV100 720/60
208 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x62,0x01 },
209 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
210 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x07,0x00 },
212 // DV100 720/50
213 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x63,0x01 },
214 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
215 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x08,0x00 },
217 // DNxHD 1080p 10bit high
218 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
219 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
220 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 },
222 // DNxHD 1080p 8bit medium
223 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
224 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
225 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x03,0x00,0x00 },
227 // DNxHD 1080p 8bit high
228 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
229 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
230 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x04,0x00,0x00 },
232 // DNxHD 1080i 10bit high
233 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
234 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
235 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x07,0x00,0x00 },
237 // DNxHD 1080i 8bit medium
238 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
239 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
240 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x08,0x00,0x00 },
242 // DNxHD 1080i 8bit high
243 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
244 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
245 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x09,0x00,0x00 },
247 // DNxHD 720p 10bit
248 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
249 { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
250 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x10,0x00,0x00 },
252 // DNxHD 720p 8bit high
253 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
254 { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
255 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x11,0x00,0x00 },
257 // DNxHD 720p 8bit medium
258 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
259 { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
260 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x12,0x00,0x00 },
262 // DNxHD 720p 8bit low
263 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
264 { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
265 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x13,0x00,0x00 },
267 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
268 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
269 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
270 NULL },
271 };
272
281 uint64_t
timestamp;
///< timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8)
296
297 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
298 static const uint8_t umid_ul[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13 };
299
300 /**
301 * complete key for operation pattern, partitions, and primer pack
302 */
303 static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x09,0x00 };
304 static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 };
// ClosedComplete
305 static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 };
306 static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 };
307 static const uint8_t random_index_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x11,0x01,0x00 };
308 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
309 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
310 static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };
311 static const uint8_t body_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 };
// ClosedComplete
312
313 /**
314 * partial key for header metadata
315 */
316 static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 };
317 static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 };
318
319 /**
320 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html
321 */
323 // preface set
324 { 0x3C0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x02,0x00,0x00,0x00,0x00}}, /* Instance UID */
325 { 0x3B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x04,0x00,0x00}}, /* Last Modified Date */
326 { 0x3B05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x05,0x00,0x00,0x00}}, /* Version */
327 { 0x3B06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x04,0x00,0x00}}, /* Identifications reference */
328 { 0x3B03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x01,0x00,0x00}}, /* Content Storage reference */
329 { 0x3B09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x03,0x00,0x00,0x00,0x00}}, /* Operational Pattern UL */
330 { 0x3B0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x01,0x00,0x00}}, /* Essence Containers UL batch */
331 { 0x3B0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x02,0x00,0x00}}, /* DM Schemes UL batch */
332 // Identification
333 { 0x3C09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x01,0x00,0x00,0x00}}, /* This Generation UID */
334 { 0x3C01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x02,0x01,0x00,0x00}}, /* Company Name */
335 { 0x3C02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x03,0x01,0x00,0x00}}, /* Product Name */
336 { 0x3C04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x05,0x01,0x00,0x00}}, /* Version String */
337 { 0x3C05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x07,0x00,0x00,0x00}}, /* Product ID */
338 { 0x3C06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x03,0x00,0x00}}, /* Modification Date */
339 // Content Storage
340 { 0x1901, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x01,0x00,0x00}}, /* Package strong reference batch */
341 { 0x1902, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x02,0x00,0x00}}, /* Package strong reference batch */
342 // Essence Container Data
343 { 0x2701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x06,0x01,0x00,0x00,0x00}}, /* Linked Package UID */
344 { 0x3F07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x04,0x00,0x00,0x00,0x00}}, /* BodySID */
345 // Package
346 { 0x4401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x10,0x00,0x00,0x00,0x00}}, /* Package UID */
347 { 0x4405, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x01,0x03,0x00,0x00}}, /* Package Creation Date */
348 { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */
349 { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */
350 { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */
351 // Track
352 { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */
353 { 0x4804, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x04,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Track Number */
354 { 0x4B01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x30,0x04,0x05,0x00,0x00,0x00,0x00}}, /* Edit Rate */
355 { 0x4B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x03,0x00,0x00}}, /* Origin */
356 { 0x4803, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x04,0x00,0x00}}, /* Sequence reference */
357 // Sequence
358 { 0x0201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x07,0x01,0x00,0x00,0x00,0x00,0x00}}, /* Data Definition UL */
359 { 0x0202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x02,0x01,0x01,0x03,0x00,0x00}}, /* Duration */
360 { 0x1001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x09,0x00,0x00}}, /* Structural Components reference array */
361 // Source Clip
362 { 0x1201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x04,0x00,0x00}}, /* Start position */
363 { 0x1101, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x01,0x00,0x00,0x00}}, /* SourcePackageID */
364 { 0x1102, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x02,0x00,0x00,0x00}}, /* SourceTrackID */
365 // Timecode Component
366 { 0x1501, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x05,0x00,0x00}}, /* Start Time Code */
367 { 0x1502, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x04,0x01,0x01,0x02,0x06,0x00,0x00}}, /* Rounded Time Code Base */
368 { 0x1503, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x04,0x01,0x01,0x05,0x00,0x00,0x00}}, /* Drop Frame */
369 // File Descriptor
370 { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */
371 { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */
372 { 0x3001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x00,0x00,0x00,0x00}}, /* SampleRate */
373 { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */
374 // Generic Picture Essence Descriptor
375 { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */
376 { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */
377 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */
378 { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */
379 { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */
380 { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */
381 { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */
382 { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */
383 { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */
384 // CDCI Picture Essence Descriptor
385 { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */
386 { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */
387 // Generic Sound Essence Descriptor
388 { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */
389 { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */
390 { 0x3D07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}}, /* ChannelCount */
391 { 0x3D01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}}, /* Quantization bits */
392 { 0x3D06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}}, /* Sound Essence Compression */
393 // Index Table Segment
394 { 0x3F0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x05,0x30,0x04,0x06,0x00,0x00,0x00,0x00}}, /* Index Edit Rate */
395 { 0x3F0C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x01,0x03,0x01,0x0A,0x00,0x00}}, /* Index Start Position */
396 { 0x3F0D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x02,0x01,0x01,0x02,0x00,0x00}}, /* Index Duration */
397 { 0x3F05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x06,0x02,0x01,0x00,0x00,0x00,0x00}}, /* Edit Unit Byte Count */
398 { 0x3F06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x05,0x00,0x00,0x00,0x00}}, /* IndexSID */
399 { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */
400 { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */
401 { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */
402 // MPEG video Descriptor
403 { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
404 { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
405 // Wave Audio Essence Descriptor
406 { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
407 { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
408 };
409
411 {
415 }
416
418 {
424 }
425
427 {
430 }
431
433 {
434 if (len < 128)
435 return 1;
436 else
437 return (
av_log2(len) >> 3) + 2;
438 }
439
441 {
442 // Determine the best BER size
444 if (len < 128) {
445 //short form
447 return 1;
448 }
449
450 size = (
av_log2(len) >> 3) + 1;
451
452 // long form
454 while(size) {
455 size--;
456 avio_w8(pb, len >> 8 * size & 0xff);
457 }
458 return 0;
459 }
460
462 {
465 }
466
467 /*
468 * Get essence container ul index
469 */
471 {
472 int i;
476 return -1;
477 }
478
480 {
482 int local_tag_number, i = 0;
483
485
488
489 avio_wb32(pb, local_tag_number);
// local_tag num
490 avio_wb32(pb, 18);
// item size, always 18 according to the specs
491
492 for (i = 0; i < local_tag_number; i++) {
493 avio_wb16(pb, mxf_local_tag_batch[i].local_tag);
494 avio_write(pb, mxf_local_tag_batch[i].uid, 16);
495 }
496 }
497
499 {
502 }
503
505 {
508 }
509
511 {
512 int i;
513
517 }
518 }
519
521 {
523 while (uls->
uid[0]) {
525 break;
526 uls++;
527 }
528 return uls;
529 }
530
531 //one EC -> one descriptor. N ECs -> MultipleDescriptor + N descriptors
532 #define DESCRIPTOR_COUNT(essence_container_count) \
533 (essence_container_count > 1 ? essence_container_count + 1 : essence_container_count)
534
536 {
539 int i;
540
546 }
547
550 }
551
553 {
556
560
561 // write preface set uid
565
566 // last modified date
569
570 // write version
573
574 // write identification_refs
578
579 // write content_storage_refs
582
583 // operational pattern
586
587 // write essence_container_refs
590
591 // write dm_scheme_refs
594 }
595
596 /*
597 * Write a local tag containing an ascii string as utf-16
598 */
600 {
601 int i,
size = strlen(value);
603 for (i = 0; i <
size; i++)
605 }
606
608 {
611 const char *company = "FFmpeg";
612 const char *product = "OP1a Muxer";
615
618
621 length = 84 + (strlen(company)+strlen(product)+strlen(version))*2; // utf-16
623
624 // write uid
628
629 // write generation uid
632
636
637 // write product uid
640
641 // modification date
644 }
645
647 {
649
653
654 // write uid
658
659 // write package reference
664
665 // write essence container data
669 }
670
672 {
676
680
681 // write track uid
685
686 // write track id
689
690 // write track number
693 avio_wb32(pb, 0);
// track number of material package is 0
694 else
696
700
701 // write origin
704
705 // write sequence refs
708 }
709
710 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 };
711
713 {
716
717 // find data define uls
721 else {
724 }
725
726 // write duration
729 }
730
732 {
736
740
743
746
747 // write structural component
752 else
757 }
758
760 {
763
766
767 // UID
771
773
774 // Start Time Code
777
778 // Rounded Time Code Base
781
782 // Drop Frame
785 }
786
788 {
790 int i;
791
795
796 // write uid
799
802
803 // write start_position
806
807 // write source package uid, end of the reference
810 for (i = 0; i < 4; i++)
812 } else
814
815 // write source track id
819 else
821 }
822
824 {
828 int i;
829
833
837
838 // write sample rate
842
843 // write essence container ul
847 else {
850 }
852
853 // write sub descriptor refs
858 }
859
861 {
865
868
871
874
878
881 }
882
883 static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
884 static const UID mxf_wav_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 };
885 static const UID mxf_aes3_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 };
886 static const UID mxf_cdci_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x28,0x00 };
887 static const UID mxf_generic_sound_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x42,0x00 };
888
890 {
894 int display_height;
895 int f1, f2;
896 unsigned desc_size = size+8+8+8+8+8+8+5+16+sc->
interlaced*4+12+20;
898 desc_size += 5;
899
901
904
907
910
912 display_height = 576;
914 display_height = 486;
915 else
917
920
921 // component depth
924
925 // horizontal subsampling
928
929 // frame layout
932
933 // video line map
936 case 608: f1 = 7; f2 = 320; break;
938 case 512: f1 = 7; f2 = 270; break;
939 case 720: f1 = 26; f2 = 0; break; // progressive
940 case 1080: f1 = 21; f2 = 584; break;
941 default: f1 = 0; f2 = 0; break;
942 }
943
945 f2 = 0;
946 f1 *= 2;
947 }
948
955
959
962
966 }
967
968 }
969
971 {
973 }
974
976 {
979
981
982 // bit rate
985
986 // profile and level
989 profile_and_level |= 0x80; // escape bit
990 avio_w8(pb, profile_and_level);
991 }
992
994 {
996
998
999 // audio locked
1002
1003 // write audio sampling rate
1007
1010
1013 }
1014
1016 {
1018
1020
1023
1024 // avg bytes per sec
1027 }
1028
1030 {
1032 }
1033
1035 {
1037 }
1038
1040 {
1042 }
1043
1045 {
1049
1054 } else {
1058 }
1059
1060 // write uid
1065
1066 // write package umid
1070
1071 // package creation date
1074
1075 // package modified date
1078
1079 // write track refs
1086
1087 // write multiple descriptor reference
1093 } else
1095 }
1096
1097 // write timecode track
1101
1107
1111 }
1112 }
1113 }
1114
1116 {
1118
1121
1124
1127
1130
1133
1134 return 0;
1135 }
1136
1138 {
1145 return 0;
1146 }
1147
1149 {
1151 if (pad < 20) // smallest fill item possible
1153 else
1154 return pad & (KAG_SIZE-1);
1155 }
1156
1158 {
1161 int i, j, temporal_reordering = 0;
1163
1165
1167 return;
1168
1170
1173 } else {
1176 }
1177
1178 // instance id
1181
1182 // index edit rate
1186
1187 // index start position
1190
1191 // index duration
1194 avio_wb64(pb, 0);
// index table covers whole container
1195 else
1197
1198 // edit unit byte count
1201
1202 // index sid
1205
1206 // body sid
1209
1211 // real slice count - 1
1214
1215 // delta entry array
1219 // write system item delta entry
1221 avio_w8(pb, 0);
// slice entry
1228 temporal_reordering = 1;
1229 if (i == 0) { // video track
1230 avio_w8(pb, 0);
// slice number
1232 } else { // audio track
1236 avio_wb32(pb, (i-1)*audio_frame_size);
// element delta
1237 }
1238 }
1239
1243
1245 int temporal_offset = 0;
1246
1249 key_index = i;
1250 }
1251
1252 if (temporal_reordering) {
1253 int pic_num_in_gop = i - key_index;
1257 break;
1258 }
1261 temporal_offset = j - key_index - pic_num_in_gop;
1262 }
1263 }
1265
1268 } else {
1269 avio_w8(pb, key_index - i);
// key frame offset
1272 }
1273
1278 // stream offset
1282 }
1283
1287 }
1288 }
1289
1291 {
1293 if (pad) {
1295 pad -= 16 + 4;
1297 for (; pad; pad--)
1300 }
1301 }
1302
1304 int indexsid,
1306 {
1309 int64_t header_byte_count_offset;
1310 unsigned index_byte_count = 0;
1311 uint64_t partition_offset =
avio_tell(pb);
1312
1314 index_byte_count = 85 + 12+(s->
nb_streams+1)*6 +
1317 index_byte_count = 80;
1318
1319 if (index_byte_count) {
1320 // add encoded ber length
1323 }
1324
1331 }
1332
1333 // write klv
1336
1337 // write partition value
1341
1342 avio_wb64(pb, partition_offset);
// ThisPartition
1343
1348 else
1350
1352
1353 // set offset
1354 header_byte_count_offset =
avio_tell(pb);
1355 avio_wb64(pb, 0);
// headerByteCount, update later
1356
1357 // indexTable
1358 avio_wb64(pb, index_byte_count);
// indexByteCount
1359 avio_wb32(pb, index_byte_count ? indexsid : 0);
// indexSID
1360
1361 // BodyOffset
1364 } else
1366
1368
1369 // operational pattern
1371
1372 // essence container
1374
1375 if (write_metadata) {
1376 // mark the start of the headermetadata and calculate metadata size
1378 unsigned header_byte_count;
1379
1386
1387 // update header_byte_count
1388 avio_seek(pb, header_byte_count_offset, SEEK_SET);
1391 }
1392
1394 }
1395
1398 {
1401 int i, cid;
1404
1406 return 1;
1407
1409 return -1;
1410
1411 header_cid = pkt->
data + 0x28;
1412 cid = header_cid[0] << 24 | header_cid[1] << 16 | header_cid[2] << 8 | header_cid[3];
1413
1415 return -1;
1416
1417 switch (cid) {
1418 case 1235:
1421 break;
1422 case 1237:
1424 break;
1425 case 1238:
1427 break;
1428 case 1241:
1431 break;
1432 case 1242:
1434 break;
1435 case 1243:
1437 break;
1438 case 1250:
1441 break;
1442 case 1251:
1444 break;
1445 case 1252:
1447 break;
1448 case 1253:
1450 break;
1451 default:
1452 return -1;
1453 }
1454
1457
1468 }
1469 }
1470
1471 return 1;
1472 }
1473
1475 {
1480
1482 return 1;
1483
1484 // Check for minimal frame size
1485 if (pkt->
size < 120000)
1486 return -1;
1487
1488 vs_pack = pkt->
data + 80*5 + 48;
1489 vsc_pack = pkt->
data + 80*5 + 53;
1490 stype = vs_pack[3] & 0x1f;
1491 pal = (vs_pack[3] >> 5) & 0x1;
1492
1493 if ((vs_pack[2] & 0x07) == 0x02)
1495 else
1497
1499 // TODO: fix dv encoder to set proper FF/FS value in VSC pack
1500 // and set field dominance accordingly
1501 // av_log(s, AV_LOG_DEBUG, "DV vsc pack ff/ss = %x\n", vsc_pack[2] >> 6);
1502
1503 switch (stype) {
1504 case 0x18: // DV100 720p
1505 ul_index = 6 + pal;
1506 frame_size = pal ? 288000 : 240000;
1508 av_log(s,
AV_LOG_ERROR,
"source marked as interlaced but codec profile is progressive\n");
1510 }
1511 break;
1512 case 0x14: // DV100 1080i
1513 ul_index = 4 + pal;
1514 frame_size = pal ? 576000 : 480000;
1515 break;
1516 case 0x04: // DV50
1517 ul_index = 2 + pal;
1518 frame_size = pal ? 288000 : 240000;
1519 break;
1520 default: // DV25
1521 ul_index = 0 + pal;
1522 frame_size = pal ? 144000 : 120000;
1523 }
1524
1525 sc->
index = ul_index + 16;
1527
1538 }
1539 }
1540
1541 return 1;
1542 }
1543
1545 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x10,0x00 }, // MP-ML I-Frame
1546 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, // MP-ML Long GOP
1547 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, // 422P-ML I-Frame
1548 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, // 422P-ML Long GOP
1549 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x02,0x00 }, // MP-HL I-Frame
1550 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP
1551 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame
1552 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP
1553 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame
1554 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP
1555 };
1556
1558 {
1560
1561 if (avctx->
profile == 4) {
// Main
1562 if (avctx->
level == 8)
// Main
1564 else if (avctx->
level == 4)
// High
1566 else if (avctx->
level == 6)
// High 14
1568 }
else if (avctx->
profile == 0) {
// 422
1569 if (avctx->
level == 5)
// Main
1571 else if (avctx->
level == 2)
// High
1573 }
1574 return NULL;
1575 }
1576
1579 {
1582 int i;
1583
1584 for(i = 0; i < pkt->
size - 4; i++) {
1585 c = (c<<8) + pkt->
data[i];
1587 if ((pkt->
data[i+1] & 0xf0) == 0x10) {
// seq ext
1590 }
else if (i + 5 < pkt->
size && (pkt->
data[i+1] & 0xf0) == 0x80) {
// pict coding ext
1594 break;
1595 }
1596 } else if (c == 0x1b8) { // gop
1597 if (pkt->
data[i+4]>>6 & 0x01) {
// closed
1599 if (e->
flags & 0x40)
// sequence header present
1600 e->
flags |= 0x80;
// random access
1601 }
1602 } else if (c == 0x1b3) { // seq
1604 switch ((pkt->
data[i+4]>>4) & 0xf) {
1608 default:
1611 }
1612 } else if (c == 0x100) { // pic
1613 int pict_type = (pkt->
data[i+2]>>3) & 0x07;
1615 if (pict_type == 2) { // P frame
1617 sc->
closed_gop = 0;
// reset closed gop, don't matter anymore
1618 } else if (pict_type == 3) { // B frame
1620 e->
flags |= 0x13;
// only backward prediction
1621 else
1624 } else if (!pict_type) {
1626 return 0;
1627 }
1628 }
1629 }
1630 if (s->
oformat != &ff_mxf_d10_muxer)
1633 }
1634
1636 {
1637 struct tm *time = gmtime(×tamp);
1638 if (!time)
1639 return 0;
1640 return (uint64_t)(time->tm_year+1900) << 48 |
1641 (uint64_t)(time->tm_mon+1) << 40 |
1642 (uint64_t) time->tm_mday << 32 |
1643 time->tm_hour << 24 |
1644 time->tm_min << 16 |
1645 time->tm_sec << 8;
1646 }
1647
1649 {
1652 uint64_t umid = seed + 0x5294713400000000LL;
1653
1656
1658 }
1659
1661 {
1667 int64_t timestamp = 0;
1669
1671 return -1;
1672
1676 if (!sc)
1679
1681 av_log(s,
AV_LOG_ERROR,
"there must be exactly one video stream and it must be the first one\n");
1682 return -1;
1683 }
1684
1687 // Default component depth to 8
1691 if (!spf) {
1695 }
1699 if (!tcr)
1701 if (tcr)
1703 else
1705 if (ret < 0)
1707 if (s->
oformat == &ff_mxf_d10_muxer) {
1716 else sc->
index = 13;
1717 } else {
1719 return -1;
1720 }
1721
1728 }
1732 return -1;
1733 }
1735 if (s->
oformat == &ff_mxf_d10_muxer) {
1736 if (st->
index != 1) {
1738 return -1;
1739 }
1743 }
1745 } else
1747 }
1748
1751 if (sc->
index == -1) {
1753 "codec not currently supported in container\n", i);
1754 return -1;
1755 }
1756 }
1757
1759
1763
1764 if (!present[sc->
index])
1766 present[sc->
index]++;
1767 }
1768
1769 if (s->
oformat == &ff_mxf_d10_muxer) {
1771 }
1772
1775
1778 // update element count
1782 else
1784 }
1785
1788 if (timestamp)
1791
1799
1800 if (!spf)
1802
1804 return -1;
1805
1806 return 0;
1807 }
1808
1809 static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 };
1810 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 };
1811
1813 {
1817 uint32_t time_code;
1818
1820
1821 // write system metadata pack
1824 avio_w8(pb, 0x5c);
// UL, user date/time stamp, picture and sound item present
1825 avio_w8(pb, 0x04);
// content package rate
1826 avio_w8(pb, 0x00);
// content package type
1828 avio_wb16(pb, (mxf->
tc.
start + frame) & 0xFFFF);
// continuity count, supposed to overflow
1831 else {
1834 }
1837 avio_wb64(pb, 0);
// creation date/time stamp
1838
1839 avio_w8(pb, 0x81);
// SMPTE 12M time code
1844
1845 // write system metadata package set
1851 }
1852
1854 {
1859 int pad;
1860
1861 packet_size += 16 + 4;
1863
1866
1867 // ensure CBR muxing by padding to correct video frame size
1868 pad = packet_size - pkt->
size - 16 - 4;
1869 if (pad > 20) {
1871 pad -= 16 + 4;
1873 for (; pad; pad--)
1876 } else {
1878 for (; pad > 0; pad--)
1880 }
1881 }
1882
1884 {
1890 int i;
1891
1893
1897
1898 while (samples < end) {
1902 sample =
AV_RL24(samples)<< 4;
1903 samples += 3;
1904 } else {
1905 sample =
AV_RL16(samples)<<12;
1906 samples += 2;
1907 }
1909 }
1910 for (; i < 8; i++)
1912 }
1913 }
1914
1916 {
1922
1928 return -1;
1929 }
1930 }
1931
1935 return -1;
1936 }
1940 return -1;
1941 }
1945 return -1;
1946 }
1947 }
1948
1954 } else {
1956 }
1958 }
1959
1960 if (st->
index == 0) {
1963 !(ie.
flags & 0x33)) {
// I frame, Gop start
1966
1969 }
1970
1973
1979 }
1984 }
1985
1988 if (s->
oformat == &ff_mxf_d10_muxer) {
1991 else
1993 } else {
1997 }
1998
2000
2001 return 0;
2002 }
2003
2005 {
2009 int i;
2010
2013
2015 avio_wb32(pb, 1);
// BodySID of header partition
2016 else
2018 avio_wb64(pb, 0);
// offset of header partition
2019
2023 }
2024
2025 avio_wb32(pb, 0);
// BodySID of footer partition
2027
2029 }
2030
2032 {
2035
2037
2042 } else {
2044
2047 }
2048
2051
2058 } else {
2060 }
2061 }
2062
2064
2069
2071
2072 return 0;
2073 }
2074
2076 {
2077 int i, stream_count = 0;
2078
2081
2082 if (stream_count && (s->
nb_streams == stream_count || flush)) {
2086 // find last packet in edit unit
2087 while (pktl) {
2089 break;
2090 last = pktl;
2092 stream_count--;
2093 }
2094 // purge packet queue
2095 while (pktl) {
2097
2102 pktl = next;
2103 }
2104 if (last)
2106 else {
2110 }
2112 }
2113
2115 av_dlog(s,
"out st:%d dts:%"PRId64
"\n", (*out).stream_index, (*out).dts);
2122 return 1;
2123 } else {
2124 out:
2126 return 0;
2127 }
2128 }
2129
2131 {
2134
2135 return next->
dts > pkt->
dts ||
2137 }
2138
2140 {
2143 }
2144
2148 .mime_type = "application/mxf",
2149 .extensions = "mxf",
2158 };
2159
2163 .mime_type = "application/mxf",
2172 };