FFmpeg
Loading...
Searching...
No Matches
mxfenc.c
Go to the documentation of this file.
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 * signal_standard, color_siting, store_user_comments, sample rate and klv_fill_key version
25 * fixes sponsored by NOA GmbH
26 */
27
28/*
29 * References
30 * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
31 * SMPTE 377M MXF File Format Specifications
32 * SMPTE 379M MXF Generic Container
33 * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
34 * SMPTE 422M Mapping JPEG 2000 Codestreams into the MXF Generic Container
35 * SMPTE ST2019-4 (2009 or later) Mapping VC-3 Coding Units into the MXF Generic Container
36 * SMPTE RP210: SMPTE Metadata Dictionary
37 * SMPTE RP224: Registry of SMPTE Universal Labels
38 */
39
40#include <inttypes.h>
41#include <time.h>
42
45#include "libavutil/mem.h"
46#include "libavutil/opt.h"
48#include "libavutil/timecode.h"
49#include "libavutil/avassert.h"
51#include "libavutil/pixdesc.h"
53#include "libavcodec/defs.h"
55#include "libavcodec/golomb.h"
56#include "libavcodec/h264.h"
57#include "libavcodec/jpeg2000.h"
58#include "packet_internal.h"
61#include "avformat.h"
62#include "avio_internal.h"
63#include "internal.h"
64#include "avc.h"
65#include "nal.h"
66#include "mux.h"
67#include "mxf.h"
68#include "config.h"
69#include "version.h"
70
73
74#define IS_D10(s) ((s)->oformat == &ff_mxf_d10_muxer.p)
75#define IS_OPATOM(s) ((s)->oformat == &ff_mxf_opatom_muxer.p)
76
77#define EDIT_UNITS_PER_BODY 250
78#define KAG_SIZE 512
79
80typedef struct MXFIndexEntry {
81 uint64_t offset;
82 unsigned slice_offset; ///< offset of audio slice
83 uint16_t temporal_ref;
84 uint8_t flags;
86
87typedef struct j2k_info_t {
88 uint16_t j2k_cap; ///< j2k required decoder capabilities
89 uint16_t j2k_rsiz; ///< j2k required decoder capabilities (Rsiz)
90 uint32_t j2k_xsiz; ///< j2k width of the reference grid (Xsiz)
91 uint32_t j2k_ysiz; ///< j2k height of the reference grid (Ysiz)
92 uint32_t j2k_x0siz; ///< j2k horizontal offset from the origin of the reference grid to the left side of the image (X0siz)
93 uint32_t j2k_y0siz; ///< j2k vertical offset from the origin of the reference grid to the left side of the image (Y0siz)
94 uint32_t j2k_xtsiz; ///< j2k width of one reference tile with respect to the reference grid (XTsiz)
95 uint32_t j2k_ytsiz; ///< j2k height of one reference tile with respect to the reference grid (YTsiz)
96 uint32_t j2k_xt0siz; ///< j2k horizontal offset from the origin of the reference grid to the left side of the first tile (XT0siz)
97 uint32_t j2k_yt0siz; ///< j2k vertical offset from the origin of the reference grid to the left side of the first tile (YT0siz)
98 uint8_t j2k_comp_desc[12]; ///< j2k components descriptor (Ssiz(i), XRsiz(i), YRsiz(i))
100
101typedef struct MXFStreamContext {
102 int64_t pkt_cnt; ///< pkt counter for muxed packets
104 int index; ///< index in mxf_essence_container_uls table
105 const UID *codec_ul;
107 int order; ///< interleaving order if dts are equal
108 int interlaced; ///< whether picture is interlaced
109 int field_dominance; ///< tff=1, bff=2
112 AVRational aspect_ratio; ///< display aspect ratio
113 int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing
116 int frame_size; ///< frame size in bytes
117 int seq_closed_gop; ///< all gops in sequence are closed, used in mpeg-2 descriptor
118 int max_gop; ///< maximum gop size, used by mpeg-2 descriptor
119 int b_picture_count; ///< maximum number of consecutive b pictures, used in mpeg-2 descriptor
120 int low_delay; ///< low delay, used in mpeg-2 descriptor
121 int version; ///< format version, used in ffv1 descriptor
122 int micro_version; ///< format micro_version, used in ffv1 descriptor
126 int cid; ///< compression id, used by dnxhd
128
135
136typedef struct MXFPackage {
137 char *name;
141} MXFPackage;
142
157
158static const struct {
173
179
182
184
186
188 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 },
189 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
190 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 },
192 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 },
193 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x03,0x00 },
194 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
196 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 },
197 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 },
198 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
200 // D-10 Video
201 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
202 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
203 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 },
205 // D-10 Audio
206 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
207 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
208 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
210 // DV
211 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x7F,0x01 },
212 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
213 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x00,0x00,0x00 },
215 // DNxHD
216 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
217 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x0C,0x00 },
218 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 },
220 // JPEG2000
221 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c,0x01,0x00 },
222 { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x08,0x00 },
223 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 },
225 // H.264
226 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x10,0x60,0x01 },
227 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
228 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 },
230 // S436M ANC
231 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x0e,0x00,0x00 },
232 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x17,0x01,0x02,0x00 },
233 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x01,0x5C,0x00 },
235 // ProRes
236 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x1c,0x01,0x00 },
237 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x17,0x00 },
238 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x03,0x00 },
240 // FFV1
241 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x23,0x01,0x00 },
242 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x1d,0x00 },
243 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x09,0x00,0x00 },
245 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
246 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
247 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
248 NULL },
249};
250
251static const UID mxf_d10_codec_uls[] = {
252 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, // D-10 625/50 PAL 50mb/s
253 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x02 }, // D-10 525/50 NTSC 50mb/s
254 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x03 }, // D-10 625/50 PAL 40mb/s
255 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x04 }, // D-10 525/50 NTSC 40mb/s
256 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, // D-10 625/50 PAL 30mb/s
257 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 }, // D-10 525/50 NTSC 30mb/s
258};
259
260static const UID mxf_d10_container_uls[] = {
261 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, // D-10 625/50 PAL 50mb/s
262 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 }, // D-10 525/50 NTSC 50mb/s
263 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, // D-10 625/50 PAL 40mb/s
264 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, // D-10 525/50 NTSC 40mb/s
265 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, // D-10 625/50 PAL 30mb/s
266 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 }, // D-10 525/50 NTSC 30mb/s
267};
268
269
270static const UID mxf_ffv1_codec_uls[] = {
271 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x01,0x00 }, // FFV1 version 0
272 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x02,0x00 }, // FFV1 version 1
273 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x03,0x00 }, // FFV1 version 2 (was only experimental)
274 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x04,0x00 }, // FFV1 version 3
275 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x05,0x00 }, // FFV1 version 4
276};
277
278static const uint8_t product_uid[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd,0x00,0x0c,0x00,0x02};
279static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff };
280static const uint8_t umid_ul[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13 };
281
282/**
283 * complete key for operation pattern, partitions, and primer pack
284 */
285static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x09,0x00 };
286static const uint8_t opatom_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x02,0x01,0x10,0x03,0x00,0x00 };
287static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete
288static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 };
289static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 };
290static const uint8_t header_open_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }; // OpenIncomplete
291static const uint8_t header_closed_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }; // ClosedComplete
292static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };
293static const uint8_t body_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }; // ClosedComplete
294
295static const UID mxf_rgba_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x29,0x00 };
296
297/**
298 * partial key for header metadata
299 */
300static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 };
301static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 };
302
303/**
304 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html
305 * https://smpte-ra.org/sites/default/files/Labels.xml
306 */
308 // preface set
309 { 0x3C0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x02,0x00,0x00,0x00,0x00}}, /* Instance UID */
310 { 0x3B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x04,0x00,0x00}}, /* Last Modified Date */
311 { 0x3B05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x05,0x00,0x00,0x00}}, /* Version */
312 { 0x3B07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x04,0x00,0x00,0x00}}, /* Object Model Version */
313 { 0x3B06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x04,0x00,0x00}}, /* Identifications reference */
314 { 0x3B03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x01,0x00,0x00}}, /* Content Storage reference */
315 { 0x3B09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x03,0x00,0x00,0x00,0x00}}, /* Operational Pattern UL */
316 { 0x3B0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x01,0x00,0x00}}, /* Essence Containers UL batch */
317 { 0x3B0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x02,0x00,0x00}}, /* DM Schemes UL batch */
318 // Identification
319 { 0x3C09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x01,0x00,0x00,0x00}}, /* This Generation UID */
320 { 0x3C01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x02,0x01,0x00,0x00}}, /* Company Name */
321 { 0x3C02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x03,0x01,0x00,0x00}}, /* Product Name */
322 { 0x3C03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x04,0x00,0x00,0x00}}, /* Product Version */
323 { 0x3C04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x05,0x01,0x00,0x00}}, /* Version String */
324 { 0x3C05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x07,0x00,0x00,0x00}}, /* Product ID */
325 { 0x3C06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x03,0x00,0x00}}, /* Modification Date */
326 { 0x3C07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x0A,0x00,0x00,0x00}}, /* Toolkit Version */
327 { 0x3C08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x06,0x01,0x00,0x00}}, /* Platform */
328 // Content Storage
329 { 0x1901, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x01,0x00,0x00}}, /* Package strong reference batch */
330 { 0x1902, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x02,0x00,0x00}}, /* Package strong reference batch */
331 // Essence Container Data
332 { 0x2701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x06,0x01,0x00,0x00,0x00}}, /* Linked Package UID */
333 { 0x3F07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x04,0x00,0x00,0x00,0x00}}, /* BodySID */
334 // Package
335 { 0x4401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x10,0x00,0x00,0x00,0x00}}, /* Package UID */
336 { 0x4405, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x01,0x03,0x00,0x00}}, /* Package Creation Date */
337 { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */
338 { 0x4402, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x03,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Package Name */
339 { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */
340 { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */
341 // Track
342 { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */
343 { 0x4804, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x04,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Track Number */
344 { 0x4B01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x30,0x04,0x05,0x00,0x00,0x00,0x00}}, /* Edit Rate */
345 { 0x4B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x03,0x00,0x00}}, /* Origin */
346 { 0x4803, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x04,0x00,0x00}}, /* Sequence reference */
347 // Sequence
348 { 0x0201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x07,0x01,0x00,0x00,0x00,0x00,0x00}}, /* Data Definition UL */
349 { 0x0202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x02,0x01,0x01,0x03,0x00,0x00}}, /* Duration */
350 { 0x1001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x09,0x00,0x00}}, /* Structural Components reference array */
351 // Source Clip
352 { 0x1201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x04,0x00,0x00}}, /* Start position */
353 { 0x1101, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x01,0x00,0x00,0x00}}, /* SourcePackageID */
354 { 0x1102, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x02,0x00,0x00,0x00}}, /* SourceTrackID */
355 // Timecode Component
356 { 0x1501, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x05,0x00,0x00}}, /* Start Time Code */
357 { 0x1502, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x04,0x01,0x01,0x02,0x06,0x00,0x00}}, /* Rounded Time Code Base */
358 { 0x1503, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x04,0x01,0x01,0x05,0x00,0x00,0x00}}, /* Drop Frame */
359 // File Descriptor
360 { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */
361 { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */
362 { 0x3001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x00,0x00,0x00,0x00}}, /* SampleRate */
363 { 0x3002, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x02,0x00,0x00,0x00,0x00}}, /* ContainerDuration */
364 { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */
365 // Generic Picture Essence Descriptor
366 { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */
367 { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */
368 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */
369 { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */
370 { 0x3216, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x08,0x00,0x00,0x00}}, /* Stored F2 Offset */
371 { 0x3205, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x08,0x00,0x00,0x00}}, /* Sampled Width */
372 { 0x3204, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x07,0x00,0x00,0x00}}, /* Sampled Height */
373 { 0x3206, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x09,0x00,0x00,0x00}}, /* Sampled X Offset */
374 { 0x3207, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0A,0x00,0x00,0x00}}, /* Sampled Y Offset */
375 { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */
376 { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */
377 { 0x320A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0D,0x00,0x00,0x00}}, /* Display X offset */
378 { 0x320B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0E,0x00,0x00,0x00}}, /* Presentation Y offset */
379 { 0x3217, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x07,0x00,0x00,0x00}}, /* Display F2 offset */
380 { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */
381 { 0x3210, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x01,0x02,0x00}}, /* Transfer characteristic */
382 { 0x321A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x03,0x01,0x00}}, /* Coding Equations (color space) */
383 { 0x3219, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x04,0x01,0x02,0x01,0x01,0x06,0x01,0x00}}, /* Color Primaries */
384 { 0x3213, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x02,0x00,0x00,0x00,0x00}}, /* Image Start Offset */
385 { 0x3214, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Image End Offset */
386 { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */
387 { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */
388 { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard */
389 // CDCI Picture Essence Descriptor
390 { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */
391 { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */
392 { 0x3308, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x01,0x10,0x00,0x00,0x00}}, /* Vertical Subsampling */
393 { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */
394 { 0x3307, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x04,0x00,0x00,0x00,0x00}}, /* Padding Bits */
395 { 0x3304, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x03,0x00,0x00,0x00}}, /* Black Ref level */
396 { 0x3305, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x04,0x00,0x00,0x00}}, /* White Ref level */
397 { 0x3306, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x05,0x00,0x00,0x00}}, /* Color Range */
398 // RGBA Picture Essence Descriptor
399 { 0x3401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x05,0x03,0x06,0x00,0x00,0x00}}, /* Pixel Layout */
400 { 0x3406, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x05,0x03,0x0B,0x00,0x00,0x00}}, /* Component Max Ref */
401 { 0x3407, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x05,0x03,0x0C,0x00,0x00,0x00}}, /* Component Min Ref */
402 // Generic Sound Essence Descriptor
403 { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */
404 { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */
405 { 0x3D04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x02,0x01,0x01,0x03,0x00,0x00,0x00}}, /* Audio Ref Level */
406 { 0x3D07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}}, /* ChannelCount */
407 { 0x3D01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}}, /* Quantization bits */
408 { 0x3D06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}}, /* Sound Essence Compression */
409 // Index Table Segment
410 { 0x3F0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x05,0x30,0x04,0x06,0x00,0x00,0x00,0x00}}, /* Index Edit Rate */
411 { 0x3F0C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x01,0x03,0x01,0x0A,0x00,0x00}}, /* Index Start Position */
412 { 0x3F0D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x02,0x01,0x01,0x02,0x00,0x00}}, /* Index Duration */
413 { 0x3F05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x06,0x02,0x01,0x00,0x00,0x00,0x00}}, /* Edit Unit Byte Count */
414 { 0x3F06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x05,0x00,0x00,0x00,0x00}}, /* IndexSID */
415 { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */
416 { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */
417 { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */
418 // MPEG video Descriptor
419 { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
420 { 0x8003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x05,0x00,0x00}}, /* LowDelay */
421 { 0x8004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x06,0x00,0x00}}, /* ClosedGOP */
422 { 0x8006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x08,0x00,0x00}}, /* MaxGOP */
423 { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
424 { 0x8008, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x09,0x00,0x00}}, /* BPictureCount */
425 // Wave Audio Essence Descriptor
426 { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
427 { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
428 // mxf_user_comments_local_tag
429 { 0x4406, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0C,0x00,0x00,0x00}}, /* User Comments */
430 { 0x5001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x09,0x01,0x00,0x00}}, /* Name */
431 { 0x5003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0A,0x01,0x00,0x00}}, /* Value */
432 // sub descriptor used AVC, JPEG2000 and FFV1
433 { 0x8100, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00}}, /* SubDescriptors */
434 // mxf_avc_subdescriptor_local_tags
435 { 0x8200, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0E,0x00,0x00}}, /* AVC Decoding Delay */
436 { 0x8201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0A,0x00,0x00}}, /* AVC Profile */
437 { 0x8202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0D,0x00,0x00}}, /* AVC Level */
438 // ff_mxf_mastering_display_local_tags
443 // FFV1
444 { 0xDFD9, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x06,0x00,0x00,0x00}}, /* FFV1 Micro-version */
445 { 0xDFDA, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x05,0x00,0x00,0x00}}, /* FFV1 Version */
446 { 0xDFDB, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x01,0x00,0x00,0x00}}, /* FFV1 Initialization Metadata */
447 // ff_mxf_jpeg2000_local_tags
448 { 0x8401, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00}}, /* Rsiz: An enumerated value that defines the decoder capabilities */
449 { 0x8402, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x02,0x00,0x00,0x00}}, /* Xsiz: Width of the reference grid */
450 { 0x8403, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x03,0x00,0x00,0x00}}, /* Ysiz: Height of the reference grid */
451 { 0x8404, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x04,0x00,0x00,0x00}}, /* X0siz: Horizontal offset from the origin of the reference grid to the left side of the image area */
452 { 0x8405, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x05,0x00,0x00,0x00}}, /* Y0siz: Vertical offset from the origin of the reference grid to the left side of the image area */
453 { 0x8406, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x06,0x00,0x00,0x00}}, /* XTsiz: Width of one reference tile with respect to the reference grid */
454 { 0x8407, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x07,0x00,0x00,0x00}}, /* YTsiz: Height of one reference tile with respect to the reference grid */
455 { 0x8408, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x08,0x00,0x00,0x00}}, /* XT0siz: Horizontal offset from the origin of the reference grid to the left side of the first tile */
456 { 0x8409, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x09,0x00,0x00,0x00}}, /* YT0siz: Vertical offset from the origin of the reference grid to the left side of the first tile */
457 { 0x840A, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x0A,0x00,0x00,0x00}}, /* Csiz: The number of components in the picture */
458 { 0x840B, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x0B,0x00,0x00,0x00}}, /* Ssizi, XRSizi, YRSizi: Array of picture components where each component comprises 3 bytes named Ssizi, XRSizi, YRSizi. The array of 3-byte groups is preceded by the array header comprising a 4-byte value of the number of components followed by a 4-byte value of 3. */
459 { 0x840C, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x0E,0x00,0x00,0x00}}, /* The nature and order of the image components in the compressed domain as carried in the J2C codestream. */
460};
461
462#define MXF_NUM_TAGS FF_ARRAY_ELEMS(mxf_local_tag_batch)
463
464typedef struct MXFContext {
472 uint64_t timestamp; ///< timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8)
473 uint8_t slice_count; ///< index slice count minus 1 (1 if no audio, 0 otherwise)
477 int last_key_index; ///< index of last key frame
478 uint64_t duration;
479 AVTimecode tc; ///< timecode context
481 int timecode_base; ///< rounded time code base (25 or 30)
482 int edit_unit_byte_count; ///< fixed edit unit byte count
483 int content_package_rate; ///< content package rate in system element, see SMPTE 326M
484 uint64_t body_offset;
486 uint8_t umid[16]; ///< unique material identifier
492 int track_instance_count; // used to generate MXFTrack uuids
493 int cbr_index; ///< use a constant bitrate index
494 uint8_t unused_tags[MXF_NUM_TAGS]; ///< local tags that we know will not be used
496} MXFContext;
497
499{
500 avio_write(pb, uuid_base, 10);
501 avio_wb16(pb, type);
502 avio_wb32(pb, value);
503}
504
506{
507 MXFContext *mxf = s->priv_data;
508 avio_write(s->pb, umid_ul, 13);
509 avio_wb24(s->pb, mxf->instance_number);
510 avio_write(s->pb, mxf->umid, 15);
511 avio_w8(s->pb, type);
512}
513
514static void mxf_write_refs_count(AVIOContext *pb, int ref_count)
515{
516 avio_wb32(pb, ref_count);
517 avio_wb32(pb, 16);
518}
519
520static int klv_ber_length(uint64_t len)
521{
522 if (len < 128)
523 return 1;
524 else
525 return (av_log2(len) >> 3) + 2;
526}
527
528static int klv_encode_ber_length(AVIOContext *pb, uint64_t len)
529{
530 // Determine the best BER size
531 int size = klv_ber_length(len);
532 if (size == 1) {
533 //short form
534 avio_w8(pb, len);
535 return 1;
536 }
537
538 size --;
539 // long form
540 avio_w8(pb, 0x80 + size);
541 while(size) {
542 size--;
543 avio_w8(pb, len >> 8 * size & 0xff);
544 }
545 return 0;
546}
547
549{
550 avio_w8(pb, 0x80 + 3);
551 avio_wb24(pb, len);
552}
553
554static void klv_encode_ber9_length(AVIOContext *pb, uint64_t len)
555{
556 avio_w8(pb, 0x80 + 8);
557 avio_wb64(pb, len);
558}
559
560/*
561 * Get essence container ul index
562 */
564{
565 int i;
566 for (i = 0; mxf_essence_mappings[i].id; i++)
567 if (mxf_essence_mappings[i].id == id)
568 return mxf_essence_mappings[i].index;
569 return -1;
570}
571
573{
574 for (int i = 0; i < MXF_NUM_TAGS; i++) {
575 if (mxf_local_tag_batch[i].local_tag == tag) {
576 return &mxf_local_tag_batch[i];
577 }
578 }
579
580 // this assert can only be hit during development
581 av_assert0(0 && "you forgot to add your new tag to mxf_local_tag_batch");
582 return NULL;
583}
584
585static void mxf_mark_tag_unused(MXFContext *mxf, int tag)
586{
588 mxf->unused_tags[pair - mxf_local_tag_batch] = 1;
589}
590
592{
593 MXFContext *mxf = s->priv_data;
594 AVIOContext *pb = s->pb;
595 int local_tag_number = MXF_NUM_TAGS, i;
596 int will_have_avc_tags = 0, will_have_mastering_tags = 0, will_have_ffv1_tags = 0, will_have_jpeg2000_tags = 0;
597 int will_have_sub_descriptor = 0, will_have_rgba_descriptor = 0;
598
599 for (i = 0; i < s->nb_streams; i++) {
600 AVStream *st = s->streams[i];
601 MXFStreamContext *sc = st->priv_data;
603 will_have_avc_tags = 1;
604 }
608 will_have_mastering_tags = 1;
609 }
610 if (st->codecpar->codec_id == AV_CODEC_ID_FFV1) {
611 will_have_ffv1_tags = 1;
612 }
614 will_have_jpeg2000_tags = 1;
615 }
616 if (sc->sub_descriptor) {
617 will_have_sub_descriptor = 1;
618 }
620 will_have_rgba_descriptor = 1;
621 }
622 }
623
624 if (!mxf->store_user_comments) {
625 mxf_mark_tag_unused(mxf, 0x4406);
626 mxf_mark_tag_unused(mxf, 0x5001);
627 mxf_mark_tag_unused(mxf, 0x5003);
628 }
629
630 if (!will_have_sub_descriptor) {
631 mxf_mark_tag_unused(mxf, 0x8100);
632 }
633
634 if (!will_have_rgba_descriptor) {
635 mxf_mark_tag_unused(mxf, 0x3401);
636 mxf_mark_tag_unused(mxf, 0x3406);
637 mxf_mark_tag_unused(mxf, 0x3407);
638 }
639
640 if (!will_have_avc_tags) {
641 mxf_mark_tag_unused(mxf, 0x8200);
642 mxf_mark_tag_unused(mxf, 0x8201);
643 mxf_mark_tag_unused(mxf, 0x8202);
644 }
645
646 if (!will_have_mastering_tags) {
647 mxf_mark_tag_unused(mxf, 0x8301);
648 mxf_mark_tag_unused(mxf, 0x8302);
649 mxf_mark_tag_unused(mxf, 0x8303);
650 mxf_mark_tag_unused(mxf, 0x8304);
651 }
652
653 if (!will_have_ffv1_tags) {
654 mxf_mark_tag_unused(mxf, 0xDFD9);
655 mxf_mark_tag_unused(mxf, 0xDFDA);
656 mxf_mark_tag_unused(mxf, 0xDFDB);
657 }
658
659 if (!will_have_jpeg2000_tags) {
660 mxf_mark_tag_unused(mxf, 0x8401);
661 mxf_mark_tag_unused(mxf, 0x8402);
662 mxf_mark_tag_unused(mxf, 0x8403);
663 mxf_mark_tag_unused(mxf, 0x8404);
664 mxf_mark_tag_unused(mxf, 0x8405);
665 mxf_mark_tag_unused(mxf, 0x8406);
666 mxf_mark_tag_unused(mxf, 0x8407);
667 mxf_mark_tag_unused(mxf, 0x8408);
668 mxf_mark_tag_unused(mxf, 0x8409);
669 mxf_mark_tag_unused(mxf, 0x840A);
670 mxf_mark_tag_unused(mxf, 0x840B);
671 mxf_mark_tag_unused(mxf, 0x840C);
672 }
673
674 for (i = 0; i < MXF_NUM_TAGS; i++) {
675 if (mxf->unused_tags[i]) {
676 local_tag_number--;
677 }
678 }
679
681 klv_encode_ber_length(pb, local_tag_number * 18 + 8);
682
683 avio_wb32(pb, local_tag_number); // local_tag num
684 avio_wb32(pb, 18); // item size, always 18 according to the specs
685
686 for (i = 0; i < MXF_NUM_TAGS; i++) {
687 if (mxf->unused_tags[i] == 0) {
688 avio_wb16(pb, mxf_local_tag_batch[i].local_tag);
690 }
691 }
692}
693
695{
696 MXFContext *mxf = s->priv_data;
697 AVIOContext *pb = s->pb;
699
700 // make sure the tag was not declared unnecessary upfront
701 av_assert0(mxf->unused_tags[pair - mxf_local_tag_batch] == 0);
702
703 avio_wb16(pb, tag);
704 avio_wb16(pb, size);
705}
706
707static void mxf_write_metadata_key(AVIOContext *pb, unsigned int value)
708{
710 avio_wb24(pb, value);
711}
712
713static const MXFCodecUL *mxf_get_codec_ul_by_id(const MXFCodecUL *uls, int id)
714{
715 while (uls->uid[0]) {
716 if (id == uls->id)
717 break;
718 uls++;
719 }
720 return uls;
721}
722
723//one EC -> one descriptor. N ECs -> MultipleDescriptor + N descriptors
724#define DESCRIPTOR_COUNT(essence_container_count) \
725 (essence_container_count > 1 ? essence_container_count + 1 : essence_container_count)
726
728{
729 MXFContext *c = s->priv_data;
730 AVIOContext *pb = s->pb;
731 int i;
732
733 mxf_write_refs_count(pb, DESCRIPTOR_COUNT(c->essence_container_count));
734 av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count);
735 for (i = 0; i < s->nb_streams; i++) {
736 MXFStreamContext *sc = s->streams[i]->priv_data;
737 // check first track of essence container type and only write it once
738 if (sc->track_essence_element_key[15] != 0)
739 continue;
740 avio_write(pb, *sc->container_ul, 16);
741 if (c->essence_container_count == 1)
742 break;
743 }
744
745 if (c->essence_container_count > 1)
747}
748
750{
751 MXFContext *mxf = s->priv_data;
752 AVIOContext *pb = s->pb;
753
754 mxf_write_metadata_key(pb, 0x012f00);
755 PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
757
758 // write preface set uid
759 mxf_write_local_tag(s, 16, 0x3C0A);
760 mxf_write_uuid(pb, Preface, 0);
761 PRINT_KEY(s, "preface uid", pb->buf_ptr - 16);
762
763 // last modified date
764 mxf_write_local_tag(s, 8, 0x3B02);
765 avio_wb64(pb, mxf->timestamp);
766
767 // write version
768 mxf_write_local_tag(s, 2, 0x3B05);
769 avio_wb16(pb, 259); // v1.3
770
771 // Object Model Version
772 mxf_write_local_tag(s, 4, 0x3B07);
773 avio_wb32(pb, 1);
774
775 // write identification_refs
776 mxf_write_local_tag(s, 16 + 8, 0x3B06);
779
780 // write content_storage_refs
781 mxf_write_local_tag(s, 16, 0x3B03);
783
784 // operational pattern
785 mxf_write_local_tag(s, 16, 0x3B09);
786 if (IS_OPATOM(s))
787 avio_write(pb, opatom_ul, 16);
788 else
789 avio_write(pb, op1a_ul, 16);
790
791 // write essence_container_refs
794
795 // write dm_scheme_refs
796 mxf_write_local_tag(s, 8, 0x3B0B);
797 avio_wb64(pb, 0);
798}
799
800/*
801 * Returns the length of the UTF-16 string, in 16-bit characters, that would result
802 * from decoding the utf-8 string.
803 */
804static uint64_t mxf_utf16len(const char *utf8_str)
805{
806 const uint8_t *q = utf8_str;
807 uint64_t size = 0;
808 while (*q) {
809 uint32_t ch;
810 GET_UTF8(ch, *q++, goto invalid;)
811 if (ch < 0x10000)
812 size++;
813 else
814 size += 2;
815 continue;
816invalid:
817 av_log(NULL, AV_LOG_ERROR, "Invalid UTF8 sequence in mxf_utf16len\n\n");
818 }
819 size += 1;
820 return size;
821}
822
823/*
824 * Returns the calculated length a local tag containing an utf-8 string as utf-16
825 */
826static int mxf_utf16_local_tag_length(const char *utf8_str)
827{
828 uint64_t size;
829
830 if (!utf8_str)
831 return 0;
832
833 size = mxf_utf16len(utf8_str);
834 if (size >= UINT16_MAX/2) {
835 av_log(NULL, AV_LOG_ERROR, "utf16 local tag size %"PRIx64" invalid (too large), ignoring\n", size);
836 return 0;
837 }
838
839 return 4 + size * 2;
840}
841
842/*
843 * Write a local tag containing an utf-8 string as utf-16
844 */
845static void mxf_write_local_tag_utf16(AVFormatContext *s, int tag, const char *value)
846{
847 AVIOContext *pb = s->pb;
848 uint64_t size = mxf_utf16len(value);
849
850 if (size >= UINT16_MAX/2) {
851 av_log(NULL, AV_LOG_ERROR, "utf16 local tag size %"PRIx64" invalid (too large), ignoring\n", size);
852 return;
853 }
854
857}
858
860 AVIOContext *pb = s->pb;
861
862 if (s->flags & AVFMT_FLAG_BITEXACT) {
863 avio_wb16(pb, 0); // major
864 avio_wb16(pb, 0); // minor
865 avio_wb16(pb, 0); // tertiary
866 } else {
869 avio_wb16(pb, LIBAVFORMAT_VERSION_MICRO); // tertiary
870 }
871 avio_wb16(pb, 0); // patch
872 avio_wb16(pb, 0); // release
873}
874
875#define PLATFORM_IDENT "Lavf " AV_STRINGIFY((OS_NAME))
877{
878 MXFContext *mxf = s->priv_data;
879 AVIOContext *pb = s->pb;
880 AVDictionaryEntry *com_entry = av_dict_get(s->metadata, "company_name", NULL, 0);
881 AVDictionaryEntry *product_entry = av_dict_get(s->metadata, "product_name", NULL, 0);
882 AVDictionaryEntry *version_entry = av_dict_get(s->metadata, "product_version", NULL, 0);
883 const char *company = com_entry ? com_entry->value : "FFmpeg";
884 const char *product = product_entry ? product_entry->value : !IS_OPATOM(s) ? "OP1a Muxer" : "OPAtom Muxer";
885 const char *platform = s->flags & AVFMT_FLAG_BITEXACT ? "Lavf" : PLATFORM_IDENT;
886 const char *version = version_entry ? version_entry->value :
887 s->flags & AVFMT_FLAG_BITEXACT ? "0.0.0" :
889 int length;
890
891 mxf_write_metadata_key(pb, 0x013000);
892 PRINT_KEY(s, "identification key", pb->buf_ptr - 16);
893
894 length = 100 +mxf_utf16_local_tag_length(company) +
898 klv_encode_ber_length(pb, length);
899
900 // write uid
901 mxf_write_local_tag(s, 16, 0x3C0A);
903 PRINT_KEY(s, "identification uid", pb->buf_ptr - 16);
904
905 // write generation uid
906 mxf_write_local_tag(s, 16, 0x3C09);
908 mxf_write_local_tag_utf16(s, 0x3C01, company); // Company Name
909 mxf_write_local_tag_utf16(s, 0x3C02, product); // Product Name
910
911 mxf_write_local_tag(s, 10, 0x3C03); // Product Version
913
914 mxf_write_local_tag_utf16(s, 0x3C04, version); // Version String
915 mxf_write_local_tag_utf16(s, 0x3C08, platform); // Platform
916
917 // write product uid
918 mxf_write_local_tag(s, 16, 0x3C05);
919 avio_write(pb, product_uid, 16);
920
921 // modification date
922 mxf_write_local_tag(s, 8, 0x3C06);
923 avio_wb64(pb, mxf->timestamp);
924
925 mxf_write_local_tag(s, 10, 0x3C07); // Toolkit Version
927}
928
929static void mxf_write_content_storage(AVFormatContext *s, MXFPackage *packages, int package_count)
930{
931 AVIOContext *pb = s->pb;
932 int i;
933
934 mxf_write_metadata_key(pb, 0x011800);
935 PRINT_KEY(s, "content storage key", pb->buf_ptr - 16);
936 klv_encode_ber_length(pb, 60 + (16 * package_count));
937
938 // write uid
939 mxf_write_local_tag(s, 16, 0x3C0A);
941 PRINT_KEY(s, "content storage uid", pb->buf_ptr - 16);
942
943 // write package reference
944 mxf_write_local_tag(s, 16 * package_count + 8, 0x1901);
945 mxf_write_refs_count(pb, package_count);
946 for (i = 0; i < package_count; i++) {
947 mxf_write_uuid(pb, packages[i].type, packages[i].instance);
948 }
949
950 // write essence container data
951 mxf_write_local_tag(s, 8 + 16, 0x1902);
954}
955
957{
958 MXFContext *mxf = s->priv_data;
959 AVIOContext *pb = s->pb;
960 MXFStreamContext *sc = st->priv_data;
961
962 mxf_write_metadata_key(pb, 0x013b00);
963 PRINT_KEY(s, "track key", pb->buf_ptr - 16);
964 klv_encode_ber_length(pb, 80);
965
966 // write track uid
967 mxf_write_local_tag(s, 16, 0x3C0A);
969 PRINT_KEY(s, "track uid", pb->buf_ptr - 16);
970
971 // write track id
972 mxf_write_local_tag(s, 4, 0x4801);
973 avio_wb32(pb, st->index+2);
974
975 // write track number
976 mxf_write_local_tag(s, 4, 0x4804);
977 if (package->type == MaterialPackage)
978 avio_wb32(pb, 0); // track number of material package is 0
979 else
980 avio_write(pb, sc->track_essence_element_key + 12, 4);
981
982 // write edit rate
983 mxf_write_local_tag(s, 8, 0x4B01);
984
985 if (st == mxf->timecode_track && IS_OPATOM(s)) {
986 avio_wb32(pb, mxf->tc.rate.num);
987 avio_wb32(pb, mxf->tc.rate.den);
988 } else {
989 avio_wb32(pb, mxf->time_base.den);
990 avio_wb32(pb, mxf->time_base.num);
991 }
992
993 // write origin
994 mxf_write_local_tag(s, 8, 0x4B02);
995 avio_wb64(pb, 0);
996
997 // write sequence refs
998 mxf_write_local_tag(s, 16, 0x4803);
1000}
1001
1002static 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 };
1003
1005{
1006 MXFContext *mxf = s->priv_data;
1007 AVIOContext *pb = s->pb;
1008
1009 // find data define uls
1010 mxf_write_local_tag(s, 16, 0x0201);
1011 if (st == mxf->timecode_track)
1013 else {
1014 const MXFCodecUL* data_def_ul = mxf_get_codec_ul_by_id(
1017 avio_write(pb, data_def_ul->uid, 16);
1018 }
1019
1020 // write duration
1021 mxf_write_local_tag(s, 8, 0x0202);
1022
1023 if (st != mxf->timecode_track && IS_OPATOM(s) && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
1025 } else {
1026 avio_wb64(pb, mxf->duration);
1027 }
1028}
1029
1031{
1032 MXFContext *mxf = s->priv_data;
1033 AVIOContext *pb = s->pb;
1034 enum MXFMetadataSetType component;
1035
1036 mxf_write_metadata_key(pb, 0x010f00);
1037 PRINT_KEY(s, "sequence key", pb->buf_ptr - 16);
1038 klv_encode_ber_length(pb, 80);
1039
1040 mxf_write_local_tag(s, 16, 0x3C0A);
1042
1043 PRINT_KEY(s, "sequence uid", pb->buf_ptr - 16);
1045
1046 // write structural component
1047 mxf_write_local_tag(s, 16 + 8, 0x1001);
1048 mxf_write_refs_count(pb, 1);
1049 if (st == mxf->timecode_track)
1050 component = TimecodeComponent;
1051 else
1052 component = SourceClip;
1053
1054 mxf_write_uuid(pb, component, mxf->track_instance_count);
1055}
1056
1058{
1059 MXFContext *mxf = s->priv_data;
1060 AVIOContext *pb = s->pb;
1061
1062 mxf_write_metadata_key(pb, 0x011400);
1063 klv_encode_ber_length(pb, 75);
1064
1065 // UID
1066 mxf_write_local_tag(s, 16, 0x3C0A);
1068
1070
1071 // Start Time Code
1072 mxf_write_local_tag(s, 8, 0x1501);
1073 avio_wb64(pb, mxf->tc.start);
1074
1075 // Rounded Time Code Base
1076 mxf_write_local_tag(s, 2, 0x1502);
1077 avio_wb16(pb, mxf->timecode_base);
1078
1079 // Drop Frame
1080 mxf_write_local_tag(s, 1, 0x1503);
1082}
1083
1085{
1086 MXFContext *mxf = s->priv_data;
1087 AVIOContext *pb = s->pb;
1088
1089 mxf_write_metadata_key(pb, 0x011100);
1090 PRINT_KEY(s, "structural component key", pb->buf_ptr - 16);
1091 klv_encode_ber_length(pb, 108);
1092
1093 // write uid
1094 mxf_write_local_tag(s, 16, 0x3C0A);
1096
1097 PRINT_KEY(s, "structural component uid", pb->buf_ptr - 16);
1099
1100 // write start_position
1101 mxf_write_local_tag(s, 8, 0x1201);
1102 avio_wb64(pb, 0);
1103
1104 // write source package uid, end of the reference
1105 mxf_write_local_tag(s, 32, 0x1101);
1106 if (!package->ref) {
1107 ffio_fill(pb, 0, 32);
1108 } else
1109 mxf_write_umid(s, package->ref->instance);
1110
1111 // write source track id
1112 mxf_write_local_tag(s, 4, 0x1102);
1113 if (package->type == SourcePackage && !package->ref)
1114 avio_wb32(pb, 0);
1115 else
1116 avio_wb32(pb, st->index+2);
1117}
1118
1120{
1121 AVIOContext *pb = s->pb;
1122
1123 mxf_write_metadata_key(pb, 0x012e00);
1124 PRINT_KEY(s, "tape descriptor key", pb->buf_ptr - 16);
1125 klv_encode_ber_length(pb, 20);
1126 mxf_write_local_tag(s, 16, 0x3C0A);
1128 PRINT_KEY(s, "tape_desc uid", pb->buf_ptr - 16);
1129}
1130
1131
1133{
1134 MXFContext *mxf = s->priv_data;
1135 AVIOContext *pb = s->pb;
1136 const uint8_t *ul;
1137 int i;
1138
1139 mxf_write_metadata_key(pb, 0x014400);
1140 PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16);
1141 klv_encode_ber_length(pb, 64 + 16LL * s->nb_streams);
1142
1143 mxf_write_local_tag(s, 16, 0x3C0A);
1145 PRINT_KEY(s, "multi_desc uid", pb->buf_ptr - 16);
1146
1147 // write sample rate
1148 mxf_write_local_tag(s, 8, 0x3001);
1149 avio_wb32(pb, mxf->time_base.den);
1150 avio_wb32(pb, mxf->time_base.num);
1151
1152 // write essence container ul
1153 mxf_write_local_tag(s, 16, 0x3004);
1154 if (mxf->essence_container_count > 1)
1155 ul = multiple_desc_ul;
1156 else {
1157 MXFStreamContext *sc = s->streams[0]->priv_data;
1158 ul = *sc->container_ul;
1159 }
1160 avio_write(pb, ul, 16);
1161
1162 // write sub descriptor refs
1163 mxf_write_local_tag(s, s->nb_streams * 16 + 8, 0x3F01);
1164 mxf_write_refs_count(pb, s->nb_streams);
1165 for (i = 0; i < s->nb_streams; i++)
1167}
1168
1170{
1171 MXFContext *mxf = s->priv_data;
1172 MXFStreamContext *sc = st->priv_data;
1173 AVIOContext *pb = s->pb;
1174 int64_t pos;
1175
1176 avio_write(pb, key, 16);
1178 pos = avio_tell(pb);
1179
1180 mxf_write_local_tag(s, 16, 0x3C0A);
1182
1183 mxf_write_local_tag(s, 4, 0x3006);
1184 avio_wb32(pb, st->index+2);
1185
1186 mxf_write_local_tag(s, 8, 0x3001);
1187 if (IS_D10(s)) {
1188 avio_wb32(pb, mxf->time_base.den);
1189 avio_wb32(pb, mxf->time_base.num);
1190 } else {
1193 avio_wb32(pb, st->codecpar->sample_rate);
1194 avio_wb32(pb, 1);
1195 } else {
1196 avio_wb32(pb, mxf->time_base.den);
1197 avio_wb32(pb, mxf->time_base.num);
1198 }
1199 }
1200
1201 mxf_write_local_tag(s, 16, 0x3004);
1202 avio_write(pb, *sc->container_ul, 16);
1203
1204 return pos;
1205}
1206
1207static const UID mxf_s436m_anc_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 };
1208static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
1209static const UID mxf_wav_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 };
1210static const UID mxf_aes3_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 };
1211static const UID mxf_cdci_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x28,0x00 };
1212static const UID mxf_generic_sound_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x42,0x00 };
1213
1214static const UID mxf_avc_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x6E,0x00 };
1215static const UID mxf_ffv1_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x81,0x03 };
1216static const UID mxf_jpeg2000_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x5A,0x00};
1217
1218static inline uint16_t rescale_mastering_chroma(AVRational q)
1219{
1221}
1222
1223static inline uint32_t rescale_mastering_luma(AVRational q)
1224{
1226}
1227
1229{
1230 MXFStreamContext *sc = st->priv_data;
1231 AVIOContext *pb = s->pb;
1232 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
1233 int stored_width = st->codecpar->width;
1234 int stored_height = st->codecpar->height;
1235 int display_width;
1236 int display_height;
1237 int f1, f2;
1238 const MXFCodecUL *color_primaries_ul;
1239 const MXFCodecUL *color_trc_ul;
1240 const MXFCodecUL *color_space_ul;
1242 const AVPacketSideData *side_data;
1243 int component_depth = pix_desc->comp[0].depth;
1244
1248
1250 if (st->codecpar->height == 1080)
1251 stored_width = 1920;
1252 else if (st->codecpar->height == 720)
1253 stored_width = 1280;
1254 }
1255 display_width = stored_width;
1256
1257 switch (st->codecpar->codec_id) {
1258 case AV_CODEC_ID_DNXHD:
1259 if (sc->cid < 1270) // DNxHD
1260 break;
1261 // fall for DNxHR RI rasters
1264 case AV_CODEC_ID_H264:
1265 //Based on 16x16 macroblocks
1266 stored_width = (stored_width+15)/16*16;
1267 stored_height = (stored_height+15)/16*16;
1268 break;
1269 default:
1270 break;
1271 }
1272
1273 //Stored width
1274 mxf_write_local_tag(s, 4, 0x3203);
1275 avio_wb32(pb, stored_width);
1276
1277 //Stored height
1278 mxf_write_local_tag(s, 4, 0x3202);
1279 avio_wb32(pb, stored_height>>sc->interlaced);
1280
1281 if (IS_D10(s)) {
1282 //Stored F2 Offset
1283 mxf_write_local_tag(s, 4, 0x3216);
1284 avio_wb32(pb, 0);
1285
1286 //Image Start Offset
1287 mxf_write_local_tag(s, 4, 0x3213);
1288 avio_wb32(pb, 0);
1289
1290 //Image End Offset
1291 mxf_write_local_tag(s, 4, 0x3214);
1292 avio_wb32(pb, 0);
1293 }
1294
1295 //Sampled width
1296 mxf_write_local_tag(s, 4, 0x3205);
1297 avio_wb32(pb, display_width);
1298
1299 //Samples height
1300 mxf_write_local_tag(s, 4, 0x3204);
1301 avio_wb32(pb, st->codecpar->height>>sc->interlaced);
1302
1303 //Sampled X Offset
1304 mxf_write_local_tag(s, 4, 0x3206);
1305 avio_wb32(pb, 0);
1306
1307 //Sampled Y Offset
1308 mxf_write_local_tag(s, 4, 0x3207);
1309 avio_wb32(pb, 0);
1310
1311 //Display width
1312 mxf_write_local_tag(s, 4, 0x3209);
1313 avio_wb32(pb, display_width);
1314
1315 if (st->codecpar->height == 608) // PAL + VBI
1316 display_height = 576;
1317 else if (st->codecpar->height == 512) // NTSC + VBI
1318 display_height = 486;
1319 else
1320 display_height = st->codecpar->height;
1321
1322 //Display height
1323 mxf_write_local_tag(s, 4, 0x3208);
1324 avio_wb32(pb, display_height>>sc->interlaced);
1325
1326 // display X offset
1327 mxf_write_local_tag(s, 4, 0x320A);
1328 avio_wb32(pb, 0);
1329
1330 // display Y offset
1331 mxf_write_local_tag(s, 4, 0x320B);
1332 avio_wb32(pb, (st->codecpar->height - display_height)>>sc->interlaced);
1333
1334 if (sc->interlaced) {
1335 //Display F2 Offset
1336 mxf_write_local_tag(s, 4, 0x3217);
1337 avio_wb32(pb, -((st->codecpar->height - display_height)&1));
1338 }
1339
1341 uint8_t rgb_layout[16] = {
1342 'R', component_depth,
1343 'G', component_depth,
1344 'B', component_depth,
1345 };
1346
1347 // pixel layout
1348 mxf_write_local_tag(s, 16, 0x3401);
1349 avio_write(pb, rgb_layout, 16);
1350
1351 // component max ref
1352 mxf_write_local_tag(s, 4, 0x3406);
1353 avio_wb32(pb, (1<<component_depth) - 1);
1354
1355 // component min ref
1356 mxf_write_local_tag(s, 4, 0x3407);
1357 avio_wb32(pb, 0);
1358 } else {
1359 int h_chroma_sub_sample = 1 << pix_desc->log2_chroma_w;
1360 int v_chroma_sub_sample = 1 << pix_desc->log2_chroma_h;
1361 int color_siting;
1362
1363 // component depth
1364 mxf_write_local_tag(s, 4, 0x3301);
1365 avio_wb32(pb, component_depth);
1366
1367 // horizontal subsampling
1368 mxf_write_local_tag(s, 4, 0x3302);
1369 avio_wb32(pb, h_chroma_sub_sample);
1370
1371 // vertical subsampling
1372 mxf_write_local_tag(s, 4, 0x3308);
1373 avio_wb32(pb, v_chroma_sub_sample);
1374
1375 switch (choose_chroma_location(s, st)) {
1376 case AVCHROMA_LOC_TOPLEFT: color_siting = 0; break;
1377 case AVCHROMA_LOC_LEFT: color_siting = 6; break;
1378 case AVCHROMA_LOC_TOP: color_siting = 1; break;
1379 case AVCHROMA_LOC_CENTER: color_siting = 3; break;
1380 default: color_siting = 0xff;
1381 }
1382
1383 if (IS_D10(s))
1384 color_siting = 0; // color siting is specified to be 0 in d-10 specs
1385
1386 // color siting
1387 mxf_write_local_tag(s, 1, 0x3303);
1388 avio_w8(pb, color_siting);
1389
1390 // Padding Bits
1391 mxf_write_local_tag(s, 2, 0x3307);
1392 avio_wb16(pb, 0);
1393
1395 int black = 0,
1396 white = (1<<component_depth) - 1,
1397 color = (1<<component_depth);
1399 black = 1 << (component_depth - 4);
1400 white = 235 << (component_depth - 8);
1401 color = (14 << (component_depth - 4)) + 1;
1402 }
1403 mxf_write_local_tag(s, 4, 0x3304);
1404 avio_wb32(pb, black);
1405 mxf_write_local_tag(s, 4, 0x3305);
1406 avio_wb32(pb, white);
1407 mxf_write_local_tag(s, 4, 0x3306);
1408 avio_wb32(pb, color);
1409 }
1410 }
1411
1412 if (sc->signal_standard) {
1413 mxf_write_local_tag(s, 1, 0x3215);
1414 avio_w8(pb, sc->signal_standard);
1415 }
1416
1417 // frame layout
1418 mxf_write_local_tag(s, 1, 0x320C);
1419 avio_w8(pb, sc->interlaced);
1420
1421 // video line map
1422 switch (st->codecpar->height) {
1423 case 576: f1 = 23; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 335 : 336; break;
1424 case 608: f1 = 7; f2 = 320; break;
1425 case 480: f1 = 20; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 285 : 283; break;
1426 case 512: f1 = 7; f2 = 270; break;
1427 case 720: f1 = 26; f2 = 0; break; // progressive
1428 case 1080: f1 = 21; f2 = 584; break;
1429 default: f1 = 0; f2 = 0; break;
1430 }
1431
1432 if (!sc->interlaced && f2) {
1433 f2 = 0;
1434 f1 *= 2;
1435 }
1436
1437 mxf_write_local_tag(s, 16, 0x320D);
1438 avio_wb32(pb, 2);
1439 avio_wb32(pb, 4);
1440 avio_wb32(pb, f1);
1441 avio_wb32(pb, f2);
1442
1443 mxf_write_local_tag(s, 8, 0x320E);
1444 avio_wb32(pb, sc->aspect_ratio.num);
1445 avio_wb32(pb, sc->aspect_ratio.den);
1446
1447 if (color_primaries_ul->uid[0]) {
1448 mxf_write_local_tag(s, 16, 0x3219);
1449 avio_write(pb, color_primaries_ul->uid, 16);
1450 };
1451
1452 if (color_trc_ul->uid[0]) {
1453 mxf_write_local_tag(s, 16, 0x3210);
1454 avio_write(pb, color_trc_ul->uid, 16);
1455 };
1456
1457 if (color_space_ul->uid[0]) {
1458 mxf_write_local_tag(s, 16, 0x321A);
1459 avio_write(pb, color_space_ul->uid, 16);
1460 };
1461
1462 mxf_write_local_tag(s, 16, 0x3201);
1463 avio_write(pb, *sc->codec_ul, 16);
1464
1465 // Mastering Display metadata
1469 if (side_data) {
1471 if (metadata->has_primaries) {
1472 mxf_write_local_tag(s, 12, 0x8301);
1473 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[0][0]));
1474 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[0][1]));
1475 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[1][0]));
1476 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[1][1]));
1477 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[2][0]));
1478 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[2][1]));
1479 mxf_write_local_tag(s, 4, 0x8302);
1480 avio_wb16(pb, rescale_mastering_chroma(metadata->white_point[0]));
1481 avio_wb16(pb, rescale_mastering_chroma(metadata->white_point[1]));
1482 } else {
1483 av_log(NULL, AV_LOG_VERBOSE, "Not writing mastering display primaries. Missing data.\n");
1484 }
1485 if (metadata->has_luminance) {
1486 mxf_write_local_tag(s, 4, 0x8303);
1487 avio_wb32(pb, rescale_mastering_luma(metadata->max_luminance));
1488 mxf_write_local_tag(s, 4, 0x8304);
1489 avio_wb32(pb, rescale_mastering_luma(metadata->min_luminance));
1490 } else {
1491 av_log(NULL, AV_LOG_VERBOSE, "Not writing mastering display luminances. Missing data.\n");
1492 }
1493 }
1494
1495 if (sc->interlaced && sc->field_dominance) {
1496 mxf_write_local_tag(s, 1, 0x3212);
1497 avio_w8(pb, sc->field_dominance);
1498 }
1499
1500 if (sc->sub_descriptor) {
1501 mxf_write_local_tag(s, 8 + 16, 0x8100);
1502 mxf_write_refs_count(pb, 1);
1503 mxf_write_uuid(pb, sc->sub_descriptor, 0);
1504 }
1505
1508
1509 return pos;
1510}
1511
1513{
1514 int64_t cur_pos = avio_tell(pb);
1515 int size = cur_pos - pos;
1516 avio_seek(pb, pos - 4, SEEK_SET);
1518 avio_seek(pb, cur_pos, SEEK_SET);
1519}
1520
1522{
1523 AVIOContext *pb = s->pb;
1524 int64_t pos;
1525
1528 pos = avio_tell(pb);
1529
1530 mxf_write_local_tag(s, 16, 0x3C0A);
1532
1533 mxf_write_local_tag(s, 1, 0x8200);
1534 avio_w8(pb, 0xFF); // AVC Decoding Delay, unknown
1535
1536 mxf_write_local_tag(s, 1, 0x8201);
1537 avio_w8(pb, st->codecpar->profile); // AVC Profile
1538
1539 mxf_write_local_tag(s, 1, 0x8202);
1540 avio_w8(pb, st->codecpar->level); // AVC Level
1541
1543}
1544
1546{
1547 MXFStreamContext *sc = st->priv_data;
1548 AVIOContext *pb = s->pb;
1549 int64_t pos;
1550 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
1551
1552 /* JPEG2000 subdescriptor key */
1555 pos = avio_tell(pb);
1556
1557 mxf_write_local_tag(s, 16, 0x3C0A);
1559
1560 /* Value defining the decoder capabilities (rsiz) */
1561 mxf_write_local_tag(s, 2, 0x8401);
1562 avio_wb16(pb, sc->j2k_info.j2k_rsiz);
1563 /* Width of the JPEG2000 reference grid (Xsiz) */
1564 mxf_write_local_tag(s, 4, 0x8402);
1565 avio_wb32(pb, st->codecpar->width);
1566 /* Height of the JPEG2000 reference grid (Ysiz) */
1567 mxf_write_local_tag(s, 4, 0x8403);
1568 avio_wb32(pb, st->codecpar->height);
1569 /* Horizontal offset from the reference grid origin to the left side of the image area (X0siz) */
1570 mxf_write_local_tag(s, 4, 0x8404);
1571 avio_wb32(pb, sc->j2k_info.j2k_x0siz);
1572 /* Vertical offset from the reference grid origin to the left side of the image area (Y0siz) */
1573 mxf_write_local_tag(s, 4, 0x8405);
1574 avio_wb32(pb, sc->j2k_info.j2k_y0siz);
1575 /* Width of one reference tile with respect to the reference grid (XTsiz) */
1576 mxf_write_local_tag(s, 4, 0x8406);
1577 avio_wb32(pb, sc->j2k_info.j2k_xtsiz);
1578 /* Height of one reference tile with respect to the reference grid (YTsiz) */
1579 mxf_write_local_tag(s, 4, 0x8407);
1580 avio_wb32(pb, sc->j2k_info.j2k_ytsiz);
1581 /* Horizontal offset from the origin of the reference grid to the left side of the first tile (XT0siz) */
1582 mxf_write_local_tag(s, 4, 0x8408);
1583 avio_wb32(pb, sc->j2k_info.j2k_xt0siz);
1584 /* Vertical offset from the origin of the reference grid to the left side of the first tile (YT0siz) */
1585 mxf_write_local_tag(s, 4, 0x8409);
1586 avio_wb32(pb, sc->j2k_info.j2k_yt0siz);
1587 /* Image components number (Csiz) */
1588 mxf_write_local_tag(s, 2, 0x840A);
1589 avio_wb16(pb, pix_desc->nb_components);
1590 /* Array of picture components where each component comprises 3 bytes named Ssiz(i) (Pixel bitdepth - 1),
1591 XRSiz(i) (Horizontal sampling), YRSiz(i) (Vertical sampling). The array of 3-byte groups is preceded
1592 by the array header comprising a 4-byte value of the number of components followed by a 4-byte
1593 value of 3. */
1594 mxf_write_local_tag(s, 8 + 3*pix_desc->nb_components, 0x840B);
1595 avio_wb32(pb, pix_desc->nb_components);
1596 avio_wb32(pb, 3);
1597 avio_write(pb, sc->j2k_info.j2k_comp_desc, 3*pix_desc->nb_components);
1598
1600 return 0;
1601}
1602
1604{
1605 MXFStreamContext *sc = st->priv_data;
1608
1609 switch (sc->sub_descriptor) {
1610 case AVCSubDescriptor: mxf_write_avc_subdesc(s, st); break;
1612 case FFV1SubDescriptor: mxf_write_ffv1_subdesc(s, st); break;
1613 }
1614
1615 return 0;
1616}
1617
1619{
1620 AVIOContext *pb = s->pb;
1621 MXFStreamContext *sc = st->priv_data;
1622 int64_t pos;
1623
1626 pos = avio_tell(pb);
1627
1628 mxf_write_local_tag(s, 16, 0x3C0A);
1630
1631 if (st->codecpar->extradata_size) {
1633 avio_write(pb, st->codecpar->extradata, st->codecpar->extradata_size); // FFV1InitializationMetadata
1634 }
1635
1636 mxf_write_local_tag(s, 2, 0xDFDA);
1637 avio_wb16(pb, sc->version); // FFV1Version
1638
1639 if (st->codecpar->extradata_size) {
1640 mxf_write_local_tag(s, 2, 0xDFD9);
1641 avio_wb16(pb, sc->micro_version); // FFV1MicroVersion
1642 }
1643
1645}
1646
1653
1655{
1656 AVIOContext *pb = s->pb;
1657 MXFStreamContext *sc = st->priv_data;
1658 int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level;
1659
1660 // bit rate
1661 mxf_write_local_tag(s, 4, 0x8000);
1662 avio_wb32(pb, sc->video_bit_rate);
1663
1664 // profile and level
1665 mxf_write_local_tag(s, 1, 0x8007);
1666 if (!st->codecpar->profile)
1667 profile_and_level |= 0x80; // escape bit
1668 avio_w8(pb, profile_and_level);
1669
1670 // low delay
1671 mxf_write_local_tag(s, 1, 0x8003);
1672 avio_w8(pb, sc->low_delay);
1673
1674 // closed gop
1675 mxf_write_local_tag(s, 1, 0x8004);
1676 avio_w8(pb, sc->seq_closed_gop);
1677
1678 // max gop
1679 mxf_write_local_tag(s, 2, 0x8006);
1680 avio_wb16(pb, sc->max_gop);
1681
1682 // b picture count
1683 mxf_write_local_tag(s, 2, 0x8008);
1684 avio_wb16(pb, sc->b_picture_count);
1685
1686 return 0;
1687}
1688
1690{
1691 AVIOContext *pb = s->pb;
1692 MXFContext *mxf = s->priv_data;
1693 int show_warnings = !mxf->footer_partition_offset;
1695
1696 if (IS_OPATOM(s)) {
1697 mxf_write_local_tag(s, 8, 0x3002);
1699 }
1700
1701 // audio locked
1702 mxf_write_local_tag(s, 1, 0x3D02);
1703 avio_w8(pb, 1);
1704
1705 // write audio sampling rate
1706 mxf_write_local_tag(s, 8, 0x3D03);
1707 avio_wb32(pb, st->codecpar->sample_rate);
1708 avio_wb32(pb, 1);
1709
1710 if (IS_D10(s)) {
1711 mxf_write_local_tag(s, 1, 0x3D04);
1712 avio_w8(pb, 0);
1713 }
1714
1715 mxf_write_local_tag(s, 4, 0x3D07);
1716 if (mxf->channel_count == -1) {
1717 if (show_warnings && IS_D10(s) &&
1718 (st->codecpar->ch_layout.nb_channels != 4) &&
1719 (st->codecpar->ch_layout.nb_channels != 8))
1720 av_log(s, AV_LOG_WARNING, "the number of audio channels shall be 4 or 8 : the output will not comply to MXF D-10 specs, use -d10_channelcount to fix this\n");
1722 } else if (IS_D10(s)) {
1723 if (show_warnings && (mxf->channel_count < st->codecpar->ch_layout.nb_channels))
1724 av_log(s, AV_LOG_WARNING, "d10_channelcount < actual number of audio channels : some channels will be discarded\n");
1725 if (show_warnings && (mxf->channel_count != 4) && (mxf->channel_count != 8))
1726 av_log(s, AV_LOG_WARNING, "d10_channelcount shall be set to 4 or 8 : the output will not comply to MXF D-10 specs\n");
1727 avio_wb32(pb, mxf->channel_count);
1728 } else {
1730 }
1731
1732 mxf_write_local_tag(s, 4, 0x3D01);
1734
1735 return pos;
1736}
1737
1739{
1740 AVIOContext *pb = s->pb;
1742
1743 mxf_write_local_tag(s, 2, 0x3D0A);
1744 avio_wb16(pb, st->codecpar->block_align);
1745
1746 // avg bytes per sec
1747 mxf_write_local_tag(s, 4, 0x3D09);
1749
1750 return pos;
1751}
1752
1754{
1757 return 0;
1758}
1759
1766
1773
1774static const uint8_t mxf_indirect_value_utf16le[] = { 0x4c,0x00,0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 };
1775
1776static int mxf_write_tagged_value(AVFormatContext *s, const char* name, const char* value)
1777{
1778 MXFContext *mxf = s->priv_data;
1779 AVIOContext *pb = s->pb;
1780 int name_size = mxf_utf16_local_tag_length(name);
1781 int indirect_value_size = 13 + mxf_utf16_local_tag_length(value);
1782
1783 if (!name_size || indirect_value_size == 13)
1784 return 1;
1785
1786 mxf_write_metadata_key(pb, 0x013f00);
1787 klv_encode_ber_length(pb, 24 + name_size + indirect_value_size);
1788
1789 // write instance UID
1790 mxf_write_local_tag(s, 16, 0x3C0A);
1792
1793 // write name
1794 mxf_write_local_tag_utf16(s, 0x5001, name); // Name
1795
1796 // write indirect value
1797 mxf_write_local_tag(s, indirect_value_size, 0x5003);
1800
1801 mxf->tagged_value_count++;
1802 return 0;
1803}
1804
1806{
1807 MXFContext *mxf = s->priv_data;
1809 int count = 0;
1810
1811 while ((t = av_dict_get(m, "comment_", t, AV_DICT_IGNORE_SUFFIX))) {
1812 if (mxf->tagged_value_count >= UINT16_MAX) {
1813 av_log(s, AV_LOG_ERROR, "too many tagged values, ignoring remaining\n");
1814 return count;
1815 }
1816
1817 if (mxf_write_tagged_value(s, t->key + 8, t->value) == 0)
1818 count++;
1819 }
1820 return count;
1821}
1822
1824{
1825 MXFContext *mxf = s->priv_data;
1826 AVIOContext *pb = s->pb;
1827 int i, track_count = s->nb_streams+1;
1828 int name_size = mxf_utf16_local_tag_length(package->name);
1829 int user_comment_count = 0;
1830
1831 if (package->type == MaterialPackage) {
1832 if (mxf->store_user_comments)
1833 user_comment_count = mxf_write_user_comments(s, s->metadata);
1834 mxf_write_metadata_key(pb, 0x013600);
1835 PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
1836 klv_encode_ber_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12LL*mxf->store_user_comments);
1837 } else {
1838 mxf_write_metadata_key(pb, 0x013700);
1839 PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
1840 klv_encode_ber_length(pb, 112 + name_size + (16*track_count) + 12LL*mxf->store_user_comments); // 20 bytes length for descriptor reference
1841 }
1842
1843 // write uid
1844 mxf_write_local_tag(s, 16, 0x3C0A);
1845 mxf_write_uuid(pb, package->type, package->instance);
1846 av_log(s, AV_LOG_DEBUG, "package type:%d\n", package->type);
1847 PRINT_KEY(s, "package uid", pb->buf_ptr - 16);
1848
1849 // write package umid
1850 mxf_write_local_tag(s, 32, 0x4401);
1851 mxf_write_umid(s, package->instance);
1852 PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16);
1853
1854 // package name
1855 if (name_size)
1856 mxf_write_local_tag_utf16(s, 0x4402, package->name);
1857
1858 // package creation date
1859 mxf_write_local_tag(s, 8, 0x4405);
1860 avio_wb64(pb, mxf->timestamp);
1861
1862 // package modified date
1863 mxf_write_local_tag(s, 8, 0x4404);
1864 avio_wb64(pb, mxf->timestamp);
1865
1866 // write track refs
1867 mxf_write_local_tag(s, track_count*16 + 8, 0x4403);
1868 mxf_write_refs_count(pb, track_count);
1869 // these are the uuids of the tracks the will be written in mxf_write_track
1870 for (i = 0; i < track_count; i++)
1872
1873 // write user comment refs
1874 if (mxf->store_user_comments) {
1875 mxf_write_local_tag(s, user_comment_count*16 + 8, 0x4406);
1876 mxf_write_refs_count(pb, user_comment_count);
1877 for (i = 0; i < user_comment_count; i++)
1878 mxf_write_uuid(pb, TaggedValue, mxf->tagged_value_count - user_comment_count + i);
1879 }
1880
1881 // write multiple descriptor reference
1882 if (package->type == SourcePackage && package->instance == 1) {
1883 mxf_write_local_tag(s, 16, 0x4701);
1884 if (s->nb_streams > 1) {
1887 } else
1889 } else if (package->type == SourcePackage && package->instance == 2) {
1890 mxf_write_local_tag(s, 16, 0x4701);
1893 }
1894
1895 /*
1896 * for every 1 track in a package there is 1 sequence and 1 component.
1897 * all 3 of these elements share the same instance number for generating
1898 * there instance uuids. mxf->track_instance_count stores this value.
1899 * mxf->track_instance_count is incremented after a group of all 3 of
1900 * these elements are written.
1901 */
1902
1903 // write timecode track
1904 mxf_write_track(s, mxf->timecode_track, package);
1905 mxf_write_sequence(s, mxf->timecode_track, package);
1907 mxf->track_instance_count++;
1908
1909 for (i = 0; i < s->nb_streams; i++) {
1910 AVStream *st = s->streams[i];
1911 mxf_write_track(s, st, package);
1912 mxf_write_sequence(s, st, package);
1913 mxf_write_structural_component(s, st, package);
1914 mxf->track_instance_count++;
1915
1916 if (package->type == SourcePackage && package->instance == 1) {
1917 MXFStreamContext *sc = st->priv_data;
1918 int ret = mxf_essence_container_uls[sc->index].write_desc(s, st);
1919 if (ret < 0)
1920 return ret;
1921 }
1922 }
1923
1924 return 0;
1925}
1926
1928{
1929 AVIOContext *pb = s->pb;
1930
1931 mxf_write_metadata_key(pb, 0x012300);
1932 klv_encode_ber_length(pb, 72);
1933
1934 mxf_write_local_tag(s, 16, 0x3C0A); // Instance UID
1936
1937 mxf_write_local_tag(s, 32, 0x2701); // Linked Package UID
1938 mxf_write_umid(s, 1);
1939
1940 mxf_write_local_tag(s, 4, 0x3F07); // BodySID
1941 avio_wb32(pb, 1);
1942
1943 mxf_write_local_tag(s, 4, 0x3F06); // IndexSID
1944 avio_wb32(pb, 2);
1945
1946 return 0;
1947}
1948
1950{
1951 MXFContext *mxf = s->priv_data;
1953 AVStream *st = NULL;
1954 int i;
1955 MXFPackage packages[3] = {{0}};
1956 int package_count = 2;
1957 packages[0].type = MaterialPackage;
1958 packages[1].type = SourcePackage;
1959 packages[1].instance = 1;
1960 packages[0].ref = &packages[1];
1961
1962
1963 if (entry = av_dict_get(s->metadata, "material_package_name", NULL, 0))
1964 packages[0].name = entry->value;
1965
1966 if (entry = av_dict_get(s->metadata, "file_package_name", NULL, 0)) {
1967 packages[1].name = entry->value;
1968 } else {
1969 /* check if any of the streams contain a file_package_name */
1970 for (i = 0; i < s->nb_streams; i++) {
1971 st = s->streams[i];
1972 if (entry = av_dict_get(st->metadata, "file_package_name", NULL, 0)) {
1973 packages[1].name = entry->value;
1974 break;
1975 }
1976 }
1977 }
1978
1979 entry = av_dict_get(s->metadata, "reel_name", NULL, 0);
1980 if (entry) {
1981 packages[2].name = entry->value;
1982 packages[2].type = SourcePackage;
1983 packages[2].instance = 2;
1984 packages[1].ref = &packages[2];
1985 package_count = 3;
1986 }
1987
1990 mxf_write_content_storage(s, packages, package_count);
1991 mxf->track_instance_count = 0;
1992 for (i = 0; i < package_count; i++) {
1993 int ret = mxf_write_package(s, &packages[i]);
1994 if (ret < 0)
1995 return ret;
1996 }
1998 return 0;
1999}
2000
2001static unsigned klv_fill_size(uint64_t size)
2002{
2003 unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
2004 if (pad < 20) // smallest fill item possible
2005 return pad + KAG_SIZE;
2006 else
2007 return pad & (KAG_SIZE-1);
2008}
2009
2011{
2012 if (offset >= INT8_MIN && offset <= INT8_MAX)
2013 return 0;
2014
2015 av_log(s, AV_LOG_ERROR, "Current implementation requires frame offset (%d) "
2016 "to be within the range of [%d,%d]. Please reduce encoder GOP size, "
2017 "or add support for wider frame offset ranges.\n",
2018 offset, INT8_MIN, INT8_MAX);
2019 return AVERROR_PATCHWELCOME;
2020}
2021
2023{
2024 MXFContext *mxf = s->priv_data;
2025 AVIOContext *pb = s->pb;
2026 int i, j, temporal_reordering = 0;
2027 int key_index = mxf->last_key_index;
2028 int prev_non_b_picture = 0;
2029 int audio_frame_size = 0;
2030 int64_t pos;
2031 int err;
2032
2033 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
2034
2035 if (!mxf->edit_units_count && !mxf->edit_unit_byte_count)
2036 return 0;
2037
2039
2041 pos = avio_tell(pb);
2042
2043 // instance id
2044 mxf_write_local_tag(s, 16, 0x3C0A);
2046
2047 // index edit rate
2048 mxf_write_local_tag(s, 8, 0x3F0B);
2049 avio_wb32(pb, mxf->time_base.den);
2050 avio_wb32(pb, mxf->time_base.num);
2051
2052 // index start position
2053 mxf_write_local_tag(s, 8, 0x3F0C);
2055
2056 // index duration
2057 mxf_write_local_tag(s, 8, 0x3F0D);
2058 if (mxf->edit_unit_byte_count)
2059 avio_wb64(pb, 0); // index table covers whole container
2060 else
2061 avio_wb64(pb, mxf->edit_units_count);
2062
2063 // edit unit byte count
2064 mxf_write_local_tag(s, 4, 0x3F05);
2066
2067 // index sid
2068 mxf_write_local_tag(s, 4, 0x3F06);
2069 avio_wb32(pb, 2);
2070
2071 // body sid
2072 mxf_write_local_tag(s, 4, 0x3F07);
2073 avio_wb32(pb, 1);
2074
2075 // real slice count - 1
2076 mxf_write_local_tag(s, 1, 0x3F08);
2077 avio_w8(pb, !mxf->edit_unit_byte_count); // only one slice for CBR
2078
2079 // delta entry array
2080 mxf_write_local_tag(s, 8 + (s->nb_streams+1)*6, 0x3F09);
2081 avio_wb32(pb, s->nb_streams+1); // num of entries
2082 avio_wb32(pb, 6); // size of one entry
2083 // write system item delta entry
2084 avio_w8(pb, 0);
2085 avio_w8(pb, 0); // slice entry
2086 avio_wb32(pb, 0); // element delta
2087 // write each stream delta entry
2088 for (i = 0; i < s->nb_streams; i++) {
2089 AVStream *st = s->streams[i];
2090 MXFStreamContext *sc = st->priv_data;
2092 if (sc->temporal_reordering)
2093 temporal_reordering = 1;
2094 if (mxf->edit_unit_byte_count) {
2095 avio_w8(pb, 0); // slice number
2096 avio_wb32(pb, sc->slice_offset);
2097 } else if (i == 0) { // video track
2098 avio_w8(pb, 0); // slice number
2099 avio_wb32(pb, KAG_SIZE); // system item size including klv fill
2100 } else { // audio or data track
2101 if (!audio_frame_size) {
2102 audio_frame_size = sc->frame_size;
2103 audio_frame_size += klv_fill_size(audio_frame_size);
2104 }
2105 avio_w8(pb, 1);
2106 avio_wb32(pb, (i-1)*audio_frame_size); // element delta
2107 }
2108 }
2109
2110 if (!mxf->edit_unit_byte_count) {
2111 MXFStreamContext *sc = s->streams[0]->priv_data;
2112 mxf_write_local_tag(s, 8 + mxf->edit_units_count*15, 0x3F0A);
2113 avio_wb32(pb, mxf->edit_units_count); // num of entries
2114 avio_wb32(pb, 15); // size of one entry
2115
2116 for (i = 0; i < mxf->edit_units_count; i++) {
2117 int temporal_offset = 0;
2118
2119 if (!(mxf->index_entries[i].flags & 0x33)) { // I-frame
2120 sc->max_gop = FFMAX(sc->max_gop, i - mxf->last_key_index);
2121 mxf->last_key_index = key_index;
2122 key_index = i;
2123 }
2124
2125 if (temporal_reordering) {
2126 int pic_num_in_gop = i - key_index;
2127 if (pic_num_in_gop != mxf->index_entries[i].temporal_ref) {
2128 for (j = key_index; j < mxf->edit_units_count; j++) {
2129 if (pic_num_in_gop == mxf->index_entries[j].temporal_ref)
2130 break;
2131 }
2132 if (j == mxf->edit_units_count)
2133 av_log(s, AV_LOG_WARNING, "missing frames\n");
2134 temporal_offset = j - key_index - pic_num_in_gop;
2135 err = mxf_check_frame_offset(s, temporal_offset);
2136 if (err < 0)
2137 return err;
2138 }
2139 }
2140 avio_w8(pb, temporal_offset);
2141
2142 if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction
2143 int offset = mxf->last_key_index - i;
2145 if (err < 0)
2146 return err;
2147 sc->b_picture_count = FFMAX(sc->b_picture_count, i - prev_non_b_picture);
2148 avio_w8(pb, offset);
2149 } else {
2150 int offset = key_index - i;
2152 if (err < 0)
2153 return err;
2154 avio_w8(pb, offset); // key frame offset
2155 if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward
2156 mxf->last_key_index = key_index;
2157 prev_non_b_picture = i;
2158 }
2159
2160 if (!(mxf->index_entries[i].flags & 0x33) && // I-frame
2161 mxf->index_entries[i].flags & 0x40 && !temporal_offset)
2162 mxf->index_entries[i].flags |= 0x80; // random access
2163 avio_w8(pb, mxf->index_entries[i].flags);
2164 // stream offset
2165 avio_wb64(pb, mxf->index_entries[i].offset);
2166 if (s->nb_streams > 1)
2168 else
2169 avio_wb32(pb, 0);
2170 }
2171
2172 mxf->last_key_index = key_index - mxf->edit_units_count;
2174 mxf->edit_units_count = 0;
2175 }
2176
2178
2179 return 0;
2180}
2181
2183{
2184 unsigned pad = klv_fill_size(avio_tell(s->pb));
2185 if (pad) {
2186 avio_write(s->pb, klv_fill_key, 16);
2187 pad -= 16 + 4;
2188 klv_encode_ber4_length(s->pb, pad);
2189 ffio_fill(s->pb, 0, pad);
2190 av_assert1(!(avio_tell(s->pb) & (KAG_SIZE-1)));
2191 }
2192}
2193
2194static int mxf_write_partition(AVFormatContext *s, int bodysid,
2195 int indexsid,
2196 const uint8_t *key, int write_metadata)
2197{
2198 MXFContext *mxf = s->priv_data;
2199 AVIOContext *pb = s->pb;
2200 int64_t header_byte_count_offset;
2201 unsigned index_byte_count = 0;
2202 uint64_t partition_offset = avio_tell(pb);
2203 int err;
2204
2205 if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
2206 index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
2207 12+mxf->edit_units_count*15;
2208 else if (mxf->edit_unit_byte_count && indexsid)
2209 index_byte_count = 80;
2210
2211 if (index_byte_count) {
2212 index_byte_count += 16 + 4; // add encoded ber4 length
2213 index_byte_count += klv_fill_size(index_byte_count);
2214 }
2215
2216 if (key && !memcmp(key, body_partition_key, 16)) {
2218 sizeof(*mxf->body_partition_offset))) < 0) {
2219 mxf->body_partitions_count = 0;
2220 return err;
2221 }
2222 mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
2223 }
2224
2225 // write klv
2226 if (key)
2227 avio_write(pb, key, 16);
2228 else
2230
2232
2233 // write partition value
2234 avio_wb16(pb, 1); // majorVersion
2235 avio_wb16(pb, 3); // minorVersion
2236 avio_wb32(pb, KAG_SIZE); // KAGSize
2237
2238 avio_wb64(pb, partition_offset); // ThisPartition
2239
2240 if (key && !memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)
2241 avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition
2242 else if (key && !memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)
2243 avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition
2244 else
2245 avio_wb64(pb, 0);
2246
2247 avio_wb64(pb, mxf->footer_partition_offset); // footerPartition
2248
2249 // set offset
2250 header_byte_count_offset = avio_tell(pb);
2251 avio_wb64(pb, 0); // headerByteCount, update later
2252
2253 // indexTable
2254 avio_wb64(pb, index_byte_count); // indexByteCount
2255 avio_wb32(pb, index_byte_count ? indexsid : 0); // indexSID
2256
2257 // BodyOffset
2258 if (bodysid && mxf->edit_units_count && mxf->body_partitions_count && !IS_OPATOM(s))
2259 avio_wb64(pb, mxf->body_offset);
2260 else
2261 avio_wb64(pb, 0);
2262
2263 avio_wb32(pb, bodysid); // bodySID
2264
2265 // operational pattern
2266 if (IS_OPATOM(s))
2267 avio_write(pb, opatom_ul, 16);
2268 else
2269 avio_write(pb, op1a_ul, 16);
2270
2271 // essence container
2273
2274 if (write_metadata) {
2275 // mark the start of the headermetadata and calculate metadata size
2276 int64_t pos, start;
2277 unsigned header_byte_count;
2278
2280 start = avio_tell(s->pb);
2284 pos = avio_tell(s->pb);
2285 header_byte_count = pos - start + klv_fill_size(pos);
2286
2287 // update header_byte_count
2288 avio_seek(pb, header_byte_count_offset, SEEK_SET);
2289 avio_wb64(pb, header_byte_count);
2290 avio_seek(pb, pos, SEEK_SET);
2291 }
2292
2293 if(key)
2295
2296 return 0;
2297}
2298
2299static const struct {
2303 { AV_PROFILE_PRORES_PROXY, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x01,0x00 } },
2304 { AV_PROFILE_PRORES_LT, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x02,0x00 } },
2305 { AV_PROFILE_PRORES_STANDARD, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x03,0x00 } },
2306 { AV_PROFILE_PRORES_HQ, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x04,0x00 } },
2307 { AV_PROFILE_PRORES_4444, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x05,0x00 } },
2308 { AV_PROFILE_PRORES_XQ, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x06,0x00 } },
2310
2312{
2313 MXFContext *mxf = s->priv_data;
2314 MXFStreamContext *sc = st->priv_data;
2315 int i, profile;
2316
2317 if (mxf->header_written)
2318 return 1;
2319
2320 profile = st->codecpar->profile;
2321 for (i = 0; i < FF_ARRAY_ELEMS(mxf_prores_codec_uls); i++) {
2323 sc->codec_ul = &mxf_prores_codec_uls[i].codec_ul;
2324 break;
2325 }
2326 }
2328 return 0;
2329
2330 sc->frame_size = pkt->size;
2331
2332 return 1;
2333}
2334
2335static const struct {
2336 uint16_t cid;
2337 uint8_t interlaced;
2338 UID codec_ul;
2339} mxf_dnxhd_codec_uls[] = {
2340 { 1235, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 } }, // 1080p 10bit HIGH
2341 { 1237, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x03,0x00,0x00 } }, // 1080p 8bit MED
2342 { 1238, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x04,0x00,0x00 } }, // 1080p 8bit HIGH
2343 { 1241, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x07,0x00,0x00 } }, // 1080i 10bit HIGH
2344 { 1242, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x08,0x00,0x00 } }, // 1080i 8bit MED
2345 { 1243, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x09,0x00,0x00 } }, // 1080i 8bit HIGH
2346 { 1244, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x0a,0x00,0x00 } }, // 1080i 8bit TR
2347 { 1250, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x10,0x00,0x00 } }, // 720p 10bit
2348 { 1251, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x11,0x00,0x00 } }, // 720p 8bit HIGH
2349 { 1252, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x12,0x00,0x00 } }, // 720p 8bit MED
2350 { 1253, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x13,0x00,0x00 } }, // 720p 8bit LOW
2351 { 1256, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x16,0x00,0x00 } }, // 1080p 10bit 444
2352 { 1258, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x18,0x00,0x00 } }, // 720p 8bit TR
2353 { 1259, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x19,0x00,0x00 } }, // 1080p 8bit TR
2354 { 1260, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x1a,0x00,0x00 } }, // 1080i 8bit TR MBAFF
2355 { 1270, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x24,0x00,0x00 } }, // DNXHR 444
2356 { 1271, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x25,0x00,0x00 } }, // DNXHR HQX
2357 { 1272, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x26,0x00,0x00 } }, // DNXHR HQ
2358 { 1273, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x27,0x00,0x00 } }, // DNXHR SQ
2359 { 1274, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x28,0x00,0x00 } }, // DNXHR LB
2361
2363{
2364 MXFContext *mxf = s->priv_data;
2365 MXFStreamContext *sc = st->priv_data;
2366 int i;
2367
2368 if (mxf->header_written)
2369 return 1;
2370
2371 if (pkt->size < 43)
2372 return 0;
2373
2374 sc->cid = AV_RB32(pkt->data + 0x28);
2375 for (i = 0; i < FF_ARRAY_ELEMS(mxf_dnxhd_codec_uls); i++) {
2376 if (sc->cid == mxf_dnxhd_codec_uls[i].cid) {
2377 sc->codec_ul = &mxf_dnxhd_codec_uls[i].codec_ul;
2378 sc->interlaced = mxf_dnxhd_codec_uls[i].interlaced;
2379 break;
2380 }
2381 }
2383 return 0;
2384
2385 if (sc->cid >= 1270) { // RI raster
2387 st->codecpar->width, st->codecpar->height,
2388 INT_MAX);
2389 } else {
2390 sc->aspect_ratio = (AVRational){ 16, 9 };
2391 }
2392
2393 sc->frame_size = pkt->size;
2394
2395 if (sc->cid == 1270 || sc->cid == 1256)
2397
2398 return 1;
2399}
2400
2401static const struct {
2403 const UID codec_ul;
2404} mxf_dv_uls[] = {
2405 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x01,0x01 }, // IEC DV25 525/60
2406 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x01,0x00 } },
2407 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x02,0x01 }, // IEC DV25 626/50
2408 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 } },
2409 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x40,0x01 }, // DV25 525/60
2410 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x01,0x00 }, },
2411 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, // DV25 625/50
2412 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 }, },
2413 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x50,0x01 }, // DV50 525/60
2414 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x03,0x00 }, },
2415 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x51,0x01 }, // DV50 625/50
2416 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 }, },
2417 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x60,0x01 }, // DV100 1080/60
2418 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x05,0x00 }, },
2419 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x61,0x01 }, // DV100 1080/50
2420 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x06,0x00 }, },
2421 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x62,0x01 }, // DV100 720/60
2422 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x07,0x00 }, },
2423 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x63,0x01 }, // DV100 720/50
2424 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x08,0x00 }, },
2426
2428{
2429 MXFContext *mxf = s->priv_data;
2430 MXFStreamContext *sc = st->priv_data;
2431 const uint8_t *vs_pack, *vsc_pack;
2432 int apt, ul_index, stype, pal;
2433
2434 if (mxf->header_written)
2435 return 1;
2436
2437 // Check for minimal frame size
2438 if (pkt->size < 120000)
2439 return -1;
2440
2441 apt = pkt->data[4] & 0x7;
2442 vs_pack = pkt->data + 80*5 + 48;
2443 vsc_pack = pkt->data + 80*5 + 53;
2444 stype = vs_pack[3] & 0x1f;
2445 pal = (vs_pack[3] >> 5) & 0x1;
2446
2447 if ((vsc_pack[2] & 0x07) == 0x02) {
2448 sc->aspect_ratio = (AVRational){ 16, 9 };
2449 } else {
2450 sc->aspect_ratio = (AVRational){ 4, 3 };
2451 }
2452
2453 sc->interlaced = (vsc_pack[3] >> 4) & 0x01;
2454 // TODO: fix dv encoder to set proper FF/FS value in VSC pack
2455 // and set field dominance accordingly
2456 // av_log(s, AV_LOG_DEBUG, "DV vsc pack ff/ss = %x\n", vsc_pack[2] >> 6);
2457
2458 switch (stype) {
2459 case 0x18: // DV100 720p
2460 ul_index = 8+pal;
2461 if (sc->interlaced) {
2462 av_log(s, AV_LOG_ERROR, "source marked as interlaced but codec profile is progressive\n");
2463 sc->interlaced = 0;
2464 }
2465 break;
2466 case 0x14: // DV100 1080i
2467 ul_index = 6+pal;
2468 break;
2469 case 0x04: // DV50
2470 ul_index = 4+pal;
2471 break;
2472 default: // DV25
2473 if (!apt) { // IEC
2474 ul_index = 0+pal;
2475 } else {
2476 ul_index = 2+pal;
2477 }
2478 }
2479
2480 sc->container_ul = &mxf_dv_uls[ul_index].container_ul;
2481 sc->codec_ul = &mxf_dv_uls[ul_index].codec_ul;
2482
2483 sc->frame_size = pkt->size;
2484
2485 return 1;
2486}
2487
2488static const struct {
2491 uint8_t profile;
2492 uint8_t interlaced;
2493 int8_t intra_only; // 1 or 0 when there are separate UIDs for Long GOP and Intra, -1 when Intra/LGOP detection can be ignored
2494} mxf_h264_codec_uls[] = {
2495 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 0, 66, 0, -1 }, // AVC Baseline
2496 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x20,0x01 }, 0, 77, 0, -1 }, // AVC Main
2497 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x30,0x01 }, 0, 88, 0, -1 }, // AVC Extended
2498 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x40,0x01 }, 0, 100, 0, -1 }, // AVC High
2499 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x50,0x01 }, 0, 110, 0, 0 }, // AVC High 10
2500 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x60,0x01 }, 0, 122, 0, 0 }, // AVC High 422
2501 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x70,0x01 }, 0, 244, 0, 0 }, // AVC High 444
2502 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x20,0x01 }, 0, 110, 0, 1 }, // AVC High 10 Intra
2503 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x01 }, 232960, 110, 1, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/59.94i
2504 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x02 }, 281088, 110, 1, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/50i
2505 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x03 }, 232960, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/29.97p
2506 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x04 }, 281088, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 1080/25p
2507 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x08 }, 116736, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 720/59.94p
2508 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x09 }, 140800, 110, 0, 1 }, // AVC High 10 Intra RP2027 Class 50 720/50p
2509 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x30,0x01 }, 0, 122, 0, 1 }, // AVC High 422 Intra
2510 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x01 }, 472576, 122, 1, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/59.94i
2511 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x02 }, 568832, 122, 1, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/50i
2512 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x03 }, 472576, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/29.97p
2513 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x04 }, 568832, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 1080/25p
2514 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x08 }, 236544, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 720/59.94p
2515 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x09 }, 284672, 122, 0, 1 }, // AVC High 422 Intra RP2027 Class 100 720/50p
2516 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x01,0x32,0x40,0x01 }, 0, 244, 0, 1 }, // AVC High 444 Intra
2517 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x01,0x32,0x50,0x01 }, 0, 44, 0, -1 }, // AVC CAVLC 444
2519
2522{
2523 MXFContext *mxf = s->priv_data;
2524 MXFStreamContext *sc = st->priv_data;
2525 H264SPS seq, *const sps = &seq;
2526 GetBitContext gb;
2527 const uint8_t *buf = pkt->data;
2528 const uint8_t *buf_end = pkt->data + pkt->size;
2529 const uint8_t *nal_end;
2530 const UID *codec_ul = NULL;
2531 uint32_t state = -1;
2532 int extra_size = 512; // support AVC Intra files without SPS/PPS header
2533 int i, frame_size, slice_type, has_sps = 0, intra_only = 0, avc_intra = 0, ret;
2534
2535 for (;;) {
2536 buf = avpriv_find_start_code(buf, buf_end, &state);
2537 if (buf >= buf_end)
2538 break;
2539
2540 switch (state & 0x1f) {
2541 case H264_NAL_SPS:
2542 e->flags |= 0x40;
2543
2544 if (mxf->header_written)
2545 break;
2546
2547 nal_end = ff_nal_find_startcode(buf, buf_end);
2548 ret = ff_avc_decode_sps(sps, buf, nal_end - buf);
2549 if (ret < 0) {
2550 av_log(s, AV_LOG_ERROR, "error parsing sps\n");
2551 return 0;
2552 }
2553 has_sps = 1;
2554
2555 sc->aspect_ratio.num = st->codecpar->width * sps->sar.num;
2556 sc->aspect_ratio.den = st->codecpar->height * sps->sar.den;
2558 sc->aspect_ratio.num, sc->aspect_ratio.den, 1024*1024);
2559 intra_only = (sps->constraint_set_flags >> 3) & 1;
2560 sc->interlaced = !sps->frame_mbs_only_flag;
2561
2562 buf = nal_end;
2563 break;
2564 case H264_NAL_PPS:
2565 if (e->flags & 0x40) { // sequence header present
2566 e->flags |= 0x80; // random access
2567 extra_size = 0;
2568 }
2569 break;
2570 case H264_NAL_IDR_SLICE:
2571 e->flags |= 0x04; // IDR Picture
2572 buf = buf_end;
2573 break;
2574 case H264_NAL_SLICE:
2575 init_get_bits8(&gb, buf, buf_end - buf);
2576 get_ue_golomb_long(&gb); // skip first_mb_in_slice
2577 slice_type = get_ue_golomb_31(&gb);
2578 switch (slice_type % 5) {
2579 case 0:
2580 e->flags |= 0x20; // P Picture
2581 e->flags |= 0x06; // P Picture
2582 break;
2583 case 1:
2584 e->flags |= 0x30; // B Picture
2585 e->flags |= 0x03; // non-referenced B Picture
2586 break;
2587 }
2588 buf = buf_end;
2589 break;
2590 default:
2591 break;
2592 }
2593 }
2594
2595 if (mxf->header_written)
2596 return 1;
2597
2598 if (!has_sps)
2600 frame_size = pkt->size + extra_size;
2601
2602 for (i = 0; i < FF_ARRAY_ELEMS(mxf_h264_codec_uls); i++) {
2605 sc->aspect_ratio = (AVRational){ 16, 9 }; // 16:9 is mandatory for broadcast HD
2606 st->codecpar->profile = mxf_h264_codec_uls[i].profile;
2607 avc_intra = 1;
2608 mxf->cbr_index = 1;
2609 sc->frame_size = pkt->size;
2610 if (sc->interlaced)
2611 sc->field_dominance = 1; // top field first is mandatory for AVC Intra
2612 break;
2613 } else if (has_sps && mxf_h264_codec_uls[i].frame_size == 0 &&
2614 mxf_h264_codec_uls[i].profile == sps->profile_idc &&
2615 (mxf_h264_codec_uls[i].intra_only < 0 ||
2616 mxf_h264_codec_uls[i].intra_only == intra_only)) {
2618 st->codecpar->profile = sps->profile_idc;
2619 st->codecpar->level = sps->level_idc;
2620 // continue to check for avc intra
2621 }
2622 }
2623
2624 if (!codec_ul) {
2625 av_log(s, AV_LOG_ERROR, "h264 profile not supported\n");
2626 return 0;
2627 }
2628
2629 sc->codec_ul = codec_ul;
2630
2631 if (avc_intra)
2633 else
2635
2636 return 1;
2637}
2638
2639static inline int get_ffv1_unsigned_symbol(RangeCoder *c, uint8_t *state) {
2640 if(get_rac(c, state+0))
2641 return 0;
2642 else{
2643 int i, e;
2644 unsigned a;
2645 e= 0;
2646 while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10
2647 e++;
2648 if (e > 31)
2649 return AVERROR_INVALIDDATA;
2650 }
2651
2652 a= 1;
2653 for(i=e-1; i>=0; i--){
2654 a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31
2655 }
2656
2657 return a;
2658 }
2659}
2660#define FFV1_CONTEXT_SIZE 32
2662{
2663 MXFContext *mxf = s->priv_data;
2664 MXFStreamContext *sc = st->priv_data;
2665 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
2666 uint8_t state[FFV1_CONTEXT_SIZE];
2667 RangeCoder c;
2668 unsigned v;
2669
2670 sc->frame_size = pkt->size;
2671
2672 if (mxf->header_written)
2673 return 1;
2674
2675 memset(state, 128, sizeof(state));
2676 if (st->codecpar->extradata) {
2678 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
2680 if (v < 2 || v > 4) {
2681 av_log(s, AV_LOG_ERROR, "unsupported ffv1 version %d\n", v);
2682 return 0;
2683 }
2685 } else {
2686 uint8_t keystate = 128;
2687 ff_init_range_decoder(&c, pkt->data, pkt->size);
2688 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
2689 get_rac(&c, &keystate); // keyframe
2691 if (v >= 2)
2692 return 0;
2693 }
2694 sc->version = v;
2695 sc->codec_ul = &mxf_ffv1_codec_uls[v];
2697
2699 sc->interlaced = 1;
2701 }
2705 sc->aspect_ratio.num, sc->aspect_ratio.den, INT_MAX);
2706
2707 if (pix_desc->flags & AV_PIX_FMT_FLAG_RGB)
2709
2710 return 1;
2711}
2712
2714{
2715 MXFContext *mxf = s->priv_data;
2716 MXFStreamContext *sc = st->priv_data;
2717 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
2719 uint32_t j2k_ncomponents;
2720
2721 if (mxf->header_written)
2722 return 1;
2723
2724 bytestream2_init(&g,pkt->data,pkt->size);
2725
2726 while (bytestream2_get_bytes_left(&g) >= 3 && bytestream2_peek_be16(&g) != JPEG2000_SOC)
2727 bytestream2_skip(&g, 1);
2728
2729 if (bytestream2_get_be16u(&g) != JPEG2000_SOC) {
2730 av_log(s, AV_LOG_ERROR, "Mandatory SOC marker is not present\n");
2731 return AVERROR_INVALIDDATA;
2732 }
2733
2734 /* Extract useful size information from the SIZ marker */
2735 if (bytestream2_get_be16u(&g) != JPEG2000_SIZ) {
2736 av_log(s, AV_LOG_ERROR, "Mandatory SIZ marker is not present\n");
2737 return AVERROR_INVALIDDATA;
2738 }
2739 bytestream2_skip(&g, 2); // Skip Lsiz
2740 sc->j2k_info.j2k_cap = bytestream2_get_be16u(&g);
2741 sc->j2k_info.j2k_xsiz = bytestream2_get_be32u(&g);
2742 sc->j2k_info.j2k_ysiz = bytestream2_get_be32u(&g);
2743 sc->j2k_info.j2k_x0siz = bytestream2_get_be32u(&g);
2744 sc->j2k_info.j2k_y0siz = bytestream2_get_be32u(&g);
2745 sc->j2k_info.j2k_xtsiz = bytestream2_get_be32u(&g);
2746 sc->j2k_info.j2k_ytsiz = bytestream2_get_be32u(&g);
2747 sc->j2k_info.j2k_xt0siz = bytestream2_get_be32u(&g);
2748 sc->j2k_info.j2k_yt0siz = bytestream2_get_be32u(&g);
2749 j2k_ncomponents = bytestream2_get_be16u(&g);
2750 if (j2k_ncomponents != pix_desc->nb_components) {
2751 av_log(s, AV_LOG_ERROR, "Incoherence about components image number.\n");
2752 return AVERROR_INVALIDDATA;
2753 }
2754 bytestream2_get_bufferu(&g, sc->j2k_info.j2k_comp_desc, 3 * j2k_ncomponents);
2755
2756 sc->frame_size = pkt->size;
2758
2759 return 1;
2760}
2761
2762static const UID mxf_mpeg2_codec_uls[] = {
2763 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x10,0x00 }, // MP-ML I-Frame
2764 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, // MP-ML Long GOP
2765 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, // 422P-ML I-Frame
2766 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, // 422P-ML Long GOP
2767 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x02,0x00 }, // MP-HL I-Frame
2768 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP
2769 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame
2770 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP
2771 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame
2772 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP
2773};
2774
2776{
2777 int long_gop = 1;
2778
2779 if (par->profile == 4) { // Main
2780 if (par->level == 8) // Main
2781 return &mxf_mpeg2_codec_uls[0+long_gop];
2782 else if (par->level == 4) // High
2783 return &mxf_mpeg2_codec_uls[4+long_gop];
2784 else if (par->level == 6) // High 14
2785 return &mxf_mpeg2_codec_uls[8+long_gop];
2786 } else if (par->profile == 0) { // 422
2787 if (par->level == 5) // Main
2788 return &mxf_mpeg2_codec_uls[2+long_gop];
2789 else if (par->level == 2) // High
2790 return &mxf_mpeg2_codec_uls[6+long_gop];
2791 }
2792 return NULL;
2793}
2794
2797{
2798 MXFStreamContext *sc = st->priv_data;
2799 uint32_t c = -1;
2800 int i;
2801
2802 for(i = 0; i < pkt->size - 4; i++) {
2803 c = (c<<8) + pkt->data[i];
2804 if (c == 0x1b5) {
2805 if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext
2806 st->codecpar->profile = pkt->data[i+1] & 0x07;
2807 st->codecpar->level = pkt->data[i+2] >> 4;
2808 sc->low_delay = pkt->data[i+6] >> 7;
2809 } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
2810 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame
2811 if (sc->interlaced)
2812 sc->field_dominance = 1 + !(pkt->data[i+4] & 0x80); // top field first
2813 break;
2814 }
2815 } else if (c == 0x1b8) { // gop
2816 if (pkt->data[i+4]>>6 & 0x01) { // closed
2817 if (sc->seq_closed_gop == -1)
2818 sc->seq_closed_gop = 1;
2819 sc->closed_gop = 1;
2820 if (e->flags & 0x40) // sequence header present
2821 e->flags |= 0x80; // random access
2822 } else {
2823 sc->seq_closed_gop = 0;
2824 sc->closed_gop = 0;
2825 }
2826 } else if (c == 0x1b3) { // seq
2827 e->flags |= 0x40;
2828 switch ((pkt->data[i+4]>>4) & 0xf) {
2829 case 2: sc->aspect_ratio = (AVRational){ 4, 3}; break;
2830 case 3: sc->aspect_ratio = (AVRational){ 16, 9}; break;
2831 case 4: sc->aspect_ratio = (AVRational){221,100}; break;
2832 default:
2834 st->codecpar->width, st->codecpar->height, 1024*1024);
2835 }
2836 } else if (c == 0x100) { // pic
2837 int pict_type = (pkt->data[i+2]>>3) & 0x07;
2838 e->temporal_ref = (pkt->data[i+1]<<2) | (pkt->data[i+2]>>6);
2839 if (pict_type == 2) { // P-frame
2840 e->flags |= 0x22;
2841 sc->closed_gop = 0; // reset closed GOP, don't matter anymore
2842 } else if (pict_type == 3) { // B-frame
2843 if (sc->closed_gop)
2844 e->flags |= 0x13; // only backward prediction
2845 else
2846 e->flags |= 0x33;
2847 sc->temporal_reordering = -1;
2848 } else if (!pict_type) {
2849 av_log(s, AV_LOG_ERROR, "error parsing mpeg2 frame\n");
2850 return 0;
2851 }
2852 }
2853 }
2854 if (!IS_D10(s)) {
2856 if (!codec_ul)
2857 return 0;
2858 sc->codec_ul = codec_ul;
2860 }
2861 return 1;
2862}
2863
2864static uint64_t mxf_parse_timestamp(int64_t timestamp64)
2865{
2866 time_t timestamp = timestamp64 / 1000000;
2867 struct tm tmbuf;
2868 struct tm *time = gmtime_r(&timestamp, &tmbuf);
2869 if (!time)
2870 return 0;
2871 return (uint64_t)(time->tm_year+1900) << 48 |
2872 (uint64_t)(time->tm_mon+1) << 40 |
2873 (uint64_t) time->tm_mday << 32 |
2874 time->tm_hour << 24 |
2875 time->tm_min << 16 |
2876 time->tm_sec << 8 |
2877 (timestamp64 % 1000000) / 4000;
2878}
2879
2881{
2882 MXFContext *mxf = s->priv_data;
2883 uint32_t seed = av_get_random_seed();
2884 uint64_t umid = seed + 0x5294713400000000LL;
2885
2886 AV_WB64(mxf->umid , umid);
2887 AV_WB64(mxf->umid+8, umid>>8);
2888
2889 mxf->instance_number = seed & 0xFFFFFF;
2890}
2891
2893{
2894 MXFContext *mxf = s->priv_data;
2895 AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
2896
2898 if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
2899 av_log(s, AV_LOG_ERROR, "Unsupported frame rate %d/%d. Set -strict option to 'unofficial' or lower in order to allow it!\n", tbc.den, tbc.num);
2900 return AVERROR(EINVAL);
2901 } else {
2902 av_log(s, AV_LOG_WARNING, "Unofficial frame rate %d/%d.\n", tbc.den, tbc.num);
2903 }
2904 }
2905
2906 mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
2907 if (!tcr)
2908 tcr = av_dict_get(st->metadata, "timecode", NULL, 0);
2909
2910 if (tcr)
2911 return av_timecode_init_from_string(&mxf->tc, av_inv_q(tbc), tcr->value, s);
2912 else
2913 return av_timecode_init(&mxf->tc, av_inv_q(tbc), 0, 0, s);
2914}
2915
2917{
2918 AVCodecParameters *par = st->codecpar;
2919 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(par->format);
2920
2922 return par->chroma_location;
2923
2924 if (pix_desc->log2_chroma_h == 0) {
2925 return AVCHROMA_LOC_TOPLEFT;
2926 } else if (pix_desc->log2_chroma_w == 1 && pix_desc->log2_chroma_h == 1) {
2928 switch (par->codec_id) {
2929 case AV_CODEC_ID_MJPEG:
2931 }
2932 }
2934 switch (par->codec_id) {
2936 }
2937 }
2938 }
2939
2941}
2942
2944{
2945 MXFContext *mxf = s->priv_data;
2946 int i, ret;
2947 uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
2948 int64_t timestamp = 0;
2949
2950 if (IS_OPATOM(s) && s->nb_streams != 1) {
2951 av_log(s, AV_LOG_ERROR, "there must be exactly one stream for mxf opatom\n");
2952 return -1;
2953 }
2954
2955 if (!av_dict_get(s->metadata, "comment_", NULL, AV_DICT_IGNORE_SUFFIX))
2956 mxf->store_user_comments = 0;
2957
2958 for (i = 0; i < s->nb_streams; i++) {
2959 AVStream *st = s->streams[i];
2960 MXFStreamContext *sc = av_mallocz(sizeof(*sc));
2961 if (!sc)
2962 return AVERROR(ENOMEM);
2963 st->priv_data = sc;
2964 sc->index = -1;
2965
2966 if (((i == 0) ^ (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) && !IS_OPATOM(s)) {
2967 av_log(s, AV_LOG_ERROR, "there must be exactly one video stream and it must be the first one\n");
2968 return -1;
2969 }
2970
2972 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
2973 AVRational tbc = (AVRational){ 0, 0 };
2974
2975 if (!pix_desc) {
2976 av_log(s, AV_LOG_ERROR, "video stream require the codec pixel format to be set\n");
2977 return -1;
2978 }
2979
2980 if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0)
2981 tbc = av_inv_q(st->avg_frame_rate);
2982 else if (st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0)
2983 tbc = av_inv_q(st->r_frame_rate);
2984
2987 av_make_q(st->codecpar->width, st->codecpar->height));
2988 }
2989
2991 mxf->time_base = tbc;
2992 avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
2993 if((ret = mxf_init_timecode(s, st, tbc)) < 0)
2994 return ret;
2995
2997 sc->seq_closed_gop = -1; // unknown yet
2998 }
2999
3001 sc->video_bit_rate = st->codecpar->bit_rate;
3002
3003 if (IS_D10(s) ||
3006 mxf->cbr_index = 1;
3007
3008 if (IS_D10(s)) {
3009 int ntsc = mxf->time_base.den != 25;
3010 int ul_index;
3011
3013 av_log(s, AV_LOG_ERROR, "error MXF D-10 only support MPEG-2 Video\n");
3014 return AVERROR(EINVAL);
3015 }
3016 if ((sc->video_bit_rate == 50000000) && (mxf->time_base.den == 25)) {
3017 ul_index = 0;
3018 } else if ((sc->video_bit_rate == 49999840 || sc->video_bit_rate == 50000000) && ntsc) {
3019 ul_index = 1;
3020 } else if (sc->video_bit_rate == 40000000) {
3021 ul_index = 2+ntsc;
3022 } else if (sc->video_bit_rate == 30000000) {
3023 ul_index = 4+ntsc;
3024 } else {
3025 av_log(s, AV_LOG_ERROR, "error MXF D-10 only support 30/40/50 mbit/s\n");
3026 return -1;
3027 }
3028
3029 sc->codec_ul = &mxf_d10_codec_uls[ul_index];
3030 sc->container_ul = &mxf_d10_container_uls[ul_index];
3031 sc->index = INDEX_D10_VIDEO;
3032 sc->signal_standard = 1;
3033 sc->frame_size = (int64_t)sc->video_bit_rate *
3034 mxf->time_base.num / (8*mxf->time_base.den);
3035 }
3036 if (mxf->signal_standard >= 0)
3038 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
3039 char bsf_arg[32];
3040 if (st->codecpar->sample_rate != 48000) {
3041 av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n");
3042 return -1;
3043 }
3044 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
3045 if (IS_D10(s)) {
3046 if (st->index != 1) {
3047 av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n");
3048 return -1;
3049 }
3052 av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
3053 return AVERROR_PATCHWELCOME;
3054 }
3055 if (st->codecpar->ch_layout.nb_channels > 8) {
3056 av_log(s, AV_LOG_ERROR, "MXF D-10 supports at most 8 audio channels\n");
3057 return AVERROR(EINVAL);
3058 }
3059 sc->index = INDEX_D10_AUDIO;
3060 sc->container_ul = ((MXFStreamContext*)s->streams[0]->priv_data)->container_ul;
3061 sc->frame_size = 4 + 8 * av_rescale_rnd(st->codecpar->sample_rate, mxf->time_base.num, mxf->time_base.den, AV_ROUND_UP) * 4;
3062 } else if (IS_OPATOM(s)) {
3064
3067 av_log(s, AV_LOG_ERROR, "Only pcm_s16le and pcm_s24le audio codecs are implemented\n");
3068 return AVERROR_PATCHWELCOME;
3069 }
3070 if (st->codecpar->ch_layout.nb_channels != 1) {
3071 av_log(s, AV_LOG_ERROR, "MXF OPAtom only supports single channel audio\n");
3072 return AVERROR(EINVAL);
3073 }
3074
3075 mxf->time_base = st->time_base;
3076 if((ret = mxf_init_timecode(s, st, tbc)) < 0)
3077 return ret;
3078
3080 sc->index = INDEX_WAV;
3081 } else {
3082 mxf->slice_count = 1;
3086 }
3087 snprintf(bsf_arg, sizeof(bsf_arg), "r=%d/%d", mxf->tc.rate.num, mxf->tc.rate.den);
3088 ret = ff_stream_add_bitstream_filter(st, "pcm_rechunk", bsf_arg);
3089 if (ret < 0)
3090 return ret;
3092 AVDictionaryEntry* e = av_dict_get(st->metadata, "data_type", NULL, 0);
3093 if ((e && !strcmp(e->value, "vbi_vanc_smpte_436M")) ||
3096 sc->index = INDEX_S436M;
3097 } else {
3098 av_log(s, AV_LOG_ERROR, "track %d: unsupported data type\n", i);
3099 return -1;
3100 }
3101 if (st->index != s->nb_streams - 1) {
3102 av_log(s, AV_LOG_ERROR, "data track must be placed last\n");
3103 return -1;
3104 }
3106 char bsf_arg[64] = "";
3107 if (mxf->time_base.num != 0 && mxf->time_base.den != 0) {
3108 // frame rate is reciprocal of time base
3109 snprintf(bsf_arg, sizeof(bsf_arg), "cdp_frame_rate=%d/%d", mxf->time_base.den, mxf->time_base.num);
3110 }
3111 ret = ff_stream_add_bitstream_filter(st, "eia608_to_smpte436m", bsf_arg);
3112 if (ret < 0)
3113 return ret;
3114 }
3115 }
3116
3117 if (sc->index == -1) {
3119 if (sc->index == -1) {
3120 av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
3121 "codec not currently supported in container\n", i);
3122 return -1;
3123 }
3124 }
3125
3126 if (!sc->codec_ul)
3127 sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
3128 if (!sc->container_ul)
3129 sc->container_ul = &mxf_essence_container_uls[sc->index].container_ul;
3130
3131 memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
3132 sc->track_essence_element_key[15] = present[sc->index];
3133 if (IS_OPATOM(s) && st->codecpar->codec_id == AV_CODEC_ID_DNXHD) {
3134 // clip-wrapping requires 0x0D per ST2019-4:2009 or 0x06 per previous version ST2019-4:2008
3135 // we choose to use 0x06 instead 0x0D to be compatible with AVID systems
3136 // and produce mxf files with the most relevant flavour for opatom
3137 sc->track_essence_element_key[14] = 0x06;
3138 }
3139 PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
3140
3141 if (!present[sc->index])
3143 present[sc->index]++;
3144 }
3145
3146 if (IS_D10(s) || IS_OPATOM(s)) {
3147 mxf->essence_container_count = 1;
3148 }
3149
3150 if (!(s->flags & AVFMT_FLAG_BITEXACT))
3151 mxf_gen_umid(s);
3152
3153 for (i = 0; i < s->nb_streams; i++) {
3154 MXFStreamContext *sc = s->streams[i]->priv_data;
3155 // update element count
3156 sc->track_essence_element_key[13] = present[sc->index];
3157 if (!memcmp(sc->track_essence_element_key, mxf_essence_container_uls[INDEX_DV].element_ul, 13)) // DV
3158 sc->order = (0x15 << 24) | AV_RB32(sc->track_essence_element_key+13);
3159 else
3161 }
3162
3163 if (ff_parse_creation_time_metadata(s, &timestamp, 0) > 0)
3164 mxf->timestamp = mxf_parse_timestamp(timestamp);
3165 mxf->duration = -1;
3166
3167 mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
3168 if (!mxf->timecode_track)
3169 return AVERROR(ENOMEM);
3171 mxf->timecode_track->index = -1;
3172
3173 return 0;
3174}
3175
3176static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 };
3177static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 };
3178
3180{
3181 MXFContext *mxf = s->priv_data;
3182 AVIOContext *pb = s->pb;
3183 unsigned frame;
3184 uint32_t time_code;
3185 int i, system_item_bitmap = 0x58; // UL, user date/time stamp, picture present
3186
3188
3189 // write system metadata pack
3191 klv_encode_ber4_length(pb, 57);
3192
3193 for (i = 0; i < s->nb_streams; i++) {
3194 if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
3195 system_item_bitmap |= 0x4;
3196 else if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_DATA ||
3197 s->streams[i]->codecpar->codec_id == AV_CODEC_ID_EIA_608)
3198 system_item_bitmap |= 0x2;
3199 }
3200 avio_w8(pb, system_item_bitmap);
3201 avio_w8(pb, mxf->content_package_rate); // content package rate
3202 avio_w8(pb, 0x00); // content package type
3203 avio_wb16(pb, 0x00); // channel handle
3204 avio_wb16(pb, frame & 0xFFFF); // continuity count, supposed to overflow
3205 if (mxf->essence_container_count > 1)
3207 else {
3208 MXFStreamContext *sc = s->streams[0]->priv_data;
3209 avio_write(pb, *sc->container_ul, 16);
3210 }
3211 avio_w8(pb, 0);
3212 avio_wb64(pb, 0);
3213 avio_wb64(pb, 0); // creation date/time stamp
3214
3215 avio_w8(pb, 0x81); // SMPTE 12M time code
3216 time_code = av_timecode_get_smpte_from_framenum(&mxf->tc, frame);
3217 avio_wb32(pb, time_code);
3218 avio_wb32(pb, 0); // binary group data
3219 avio_wb64(pb, 0);
3220
3221 // write system metadata package set
3223 klv_encode_ber4_length(pb, 35);
3224 avio_w8(pb, 0x83); // UMID
3225 avio_wb16(pb, 0x20);
3226 mxf_write_umid(s, 1);
3227}
3228
3230{
3231 MXFContext *mxf = s->priv_data;
3232 AVIOContext *pb = s->pb;
3233 int frame_size = pkt->size / st->codecpar->block_align;
3234 const uint8_t *samples = pkt->data;
3235 const uint8_t *const end = pkt->data + pkt->size;
3236 int i;
3237
3239
3240 avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
3241 avio_wl16(pb, frame_size);
3242 avio_w8(pb, (1 << st->codecpar->ch_layout.nb_channels)-1);
3243
3244 while (samples < end) {
3245 for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) {
3246 uint32_t sample;
3248 sample = AV_RL24(samples)<< 4;
3249 samples += 3;
3250 } else {
3251 sample = AV_RL16(samples)<<12;
3252 samples += 2;
3253 }
3254 avio_wl32(pb, sample | i);
3255 }
3256 for (; i < 8; i++)
3257 avio_wl32(pb, i);
3258 }
3259}
3260
3262{
3263 MXFContext *mxf = s->priv_data;
3264 AVIOContext *pb = s->pb;
3265 AVStream *st = s->streams[0];
3266 MXFStreamContext *sc = st->priv_data;
3267 const uint8_t *key = NULL;
3268
3269 int err;
3270
3271 if (!mxf->header_written)
3273
3274 if ((err = mxf_write_partition(s, 1, 0, key, 0)) < 0)
3275 return err;
3279 return 0;
3280}
3281
3283{
3284 MXFContext *mxf = s->priv_data;
3285 AVIOContext *pb = s->pb;
3286
3287 int err;
3288
3289 if (!mxf->header_written) {
3290 if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)
3291 return err;
3293
3294 if ((err = mxf_write_opatom_body_partition(s)) < 0)
3295 return err;
3296 mxf->header_written = 1;
3297 }
3298
3299 if (!mxf->edit_unit_byte_count) {
3301 mxf->index_entries[mxf->edit_units_count].flags = ie->flags;
3303 }
3304 mxf->edit_units_count++;
3305 avio_write(pb, pkt->data, pkt->size);
3306 mxf->body_offset += pkt->size;
3307
3308 return 0;
3309}
3310
3312{
3313 MXFContext *mxf = s->priv_data;
3314 int i;
3315
3316 if (IS_OPATOM(s)) {
3317 MXFStreamContext *sc = s->streams[0]->priv_data;
3319 return;
3320 }
3321
3322 mxf->edit_unit_byte_count = KAG_SIZE; // system element
3323 for (i = 0; i < s->nb_streams; i++) {
3324 AVStream *st = s->streams[i];
3325 MXFStreamContext *sc = st->priv_data;
3327 mxf->edit_unit_byte_count += 16 + 4 + sc->frame_size;
3329 }
3330}
3331
3333{
3334 MXFContext *mxf = s->priv_data;
3335 AVIOContext *pb = s->pb;
3336 AVStream *st = s->streams[pkt->stream_index];
3337 MXFStreamContext *sc = st->priv_data;
3338 MXFIndexEntry ie = {0};
3339 int err;
3340
3341 if (!mxf->header_written && pkt->stream_index != 0 &&
3342 !IS_OPATOM(s)) {
3343 av_log(s, AV_LOG_ERROR, "Received non-video packet before "
3344 "header has been written\n");
3345 return AVERROR_INVALIDDATA;
3346 }
3347
3348 if (!mxf->cbr_index && !mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) {
3349 if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count
3350 + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) {
3351 mxf->edit_units_count = 0;
3352 av_log(s, AV_LOG_ERROR, "could not allocate index entries\n");
3353 return err;
3354 }
3355 }
3356
3358 if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {
3359 av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");
3360 return -1;
3361 }
3362 } else if (st->codecpar->codec_id == AV_CODEC_ID_DNXHD) {
3363 if (!mxf_parse_dnxhd_frame(s, st, pkt)) {
3364 av_log(s, AV_LOG_ERROR, "could not get dnxhd profile\n");
3365 return -1;
3366 }
3367 } else if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) {
3368 if (!mxf_parse_prores_frame(s, st, pkt)) {
3369 av_log(s, AV_LOG_ERROR, "could not get prores profile\n");
3370 return -1;
3371 }
3372 } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) {
3373 if (!mxf_parse_dv_frame(s, st, pkt)) {
3374 av_log(s, AV_LOG_ERROR, "could not get dv profile\n");
3375 return -1;
3376 }
3377 } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
3378 if (!mxf_parse_h264_frame(s, st, pkt, &ie)) {
3379 av_log(s, AV_LOG_ERROR, "could not get h264 profile\n");
3380 return -1;
3381 }
3382 } else if (st->codecpar->codec_id == AV_CODEC_ID_FFV1) {
3383 if (!mxf_parse_ffv1_frame(s, st, pkt)) {
3384 av_log(s, AV_LOG_ERROR, "could not get ffv1 version\n");
3385 return -1;
3386 }
3387 } else if (st->codecpar->codec_id == AV_CODEC_ID_JPEG2000) {
3388 if (!mxf_parse_jpeg2000_frame(s, st, pkt)) {
3389 av_log(s, AV_LOG_ERROR, "could not get jpeg2000 profile\n");
3390 return -1;
3391 }
3392 }
3393
3394 if (mxf->cbr_index) {
3395 if (pkt->size != sc->frame_size && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
3396 av_log(s, AV_LOG_ERROR, "track %d: frame size does not match index unit size, %d != %d\n",
3397 st->index, pkt->size, sc->frame_size);
3398 return -1;
3399 }
3400 if (!mxf->header_written)
3402 }
3403
3404 if (IS_OPATOM(s))
3405 return mxf_write_opatom_packet(s, pkt, &ie);
3406
3407 if (!mxf->header_written) {
3408 if (mxf->edit_unit_byte_count) {
3409 if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0)
3410 return err;
3413 if (err < 0)
3414 return err;
3415 } else {
3416 if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)
3417 return err;
3418 }
3419 mxf->header_written = 1;
3420 }
3421
3422 if (st->index == 0) {
3423 if (!mxf->edit_unit_byte_count &&
3425 !(ie.flags & 0x33)) { // I-frame, GOP start
3427 if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0)
3428 return err;
3431 if (err < 0)
3432 return err;
3433 }
3434
3437
3438 if (!mxf->edit_unit_byte_count) {
3440 mxf->index_entries[mxf->edit_units_count].flags = ie.flags;
3442 mxf->body_offset += KAG_SIZE; // size of system element
3443 }
3444 mxf->edit_units_count++;
3445 } else if (!mxf->edit_unit_byte_count && st->index == 1) {
3446 if (!mxf->edit_units_count) {
3447 av_log(s, AV_LOG_ERROR, "No packets in first stream\n");
3448 return AVERROR_PATCHWELCOME;
3449 }
3452 }
3453
3455 avio_write(pb, sc->track_essence_element_key, 16); // write key
3456 if (IS_D10(s) && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
3458 } else {
3459 klv_encode_ber4_length(pb, pkt->size); // write length
3460 avio_write(pb, pkt->data, pkt->size);
3461 mxf->body_offset += 16+4+pkt->size + klv_fill_size(16+4+pkt->size);
3462 }
3463
3464 return 0;
3465}
3466
3468{
3469 MXFContext *mxf = s->priv_data;
3470 AVIOContext *pb = s->pb;
3471 uint64_t pos = avio_tell(pb);
3472 int i;
3473
3475 klv_encode_ber_length(pb, 28 + 12LL*mxf->body_partitions_count);
3476
3477 if (mxf->edit_unit_byte_count && !IS_OPATOM(s))
3478 avio_wb32(pb, 1); // BodySID of header partition
3479 else
3480 avio_wb32(pb, 0);
3481 avio_wb64(pb, 0); // offset of header partition
3482
3483 for (i = 0; i < mxf->body_partitions_count; i++) {
3484 avio_wb32(pb, 1); // BodySID
3486 }
3487
3488 avio_wb32(pb, 0); // BodySID of footer partition
3490
3491 avio_wb32(pb, avio_tell(pb) - pos + 4);
3492}
3493
3495{
3496 MXFContext *mxf = s->priv_data;
3497 AVIOContext *pb = s->pb;
3498 int i, err;
3499
3500 if (!mxf->header_written ||
3501 (IS_OPATOM(s) && !mxf->body_partition_offset)) {
3502 /* reason could be invalid options/not supported codec/out of memory */
3503 return AVERROR_UNKNOWN;
3504 }
3505
3507
3510 if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) { // no need to repeat index
3511 if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)
3512 return err;
3513 } else {
3514 if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0)
3515 return err;
3518 if (err < 0)
3519 return err;
3520 }
3521
3524
3525 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
3526 if (IS_OPATOM(s)) {
3527 /* rewrite body partition to update lengths */
3528 avio_seek(pb, mxf->body_partition_offset[0], SEEK_SET);
3529 if ((err = mxf_write_opatom_body_partition(s)) < 0)
3530 return err;
3531 }
3532
3533 avio_seek(pb, 0, SEEK_SET);
3534 if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) {
3535 if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0)
3536 return err;
3539 if (err < 0)
3540 return err;
3541 } else {
3542 if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0)
3543 return err;
3544 }
3545 // update footer partition offset
3546 for (i = 0; i < mxf->body_partitions_count; i++) {
3547 avio_seek(pb, mxf->body_partition_offset[i]+44, SEEK_SET);
3549 }
3550 }
3551
3552 return 0;
3553}
3554
3556{
3557 MXFContext *mxf = s->priv_data;
3558
3559 av_freep(&mxf->index_entries);
3561 av_freep(&mxf->timecode_track);
3562}
3563
3565{
3566 FFFormatContext *const si = ffformatcontext(s);
3567 int i, stream_count = 0;
3568
3569 for (i = 0; i < s->nb_streams; i++)
3570 stream_count += !!ffstream(s->streams[i])->last_in_packet_buffer;
3571
3572 if (stream_count && (s->nb_streams == stream_count || flush)) {
3574 if (s->nb_streams != stream_count) {
3575 PacketListEntry *last = NULL;
3576 // find last packet in edit unit
3577 while (pktl) {
3578 if (!stream_count || pktl->pkt.stream_index == 0)
3579 break;
3580 // update last packet in packet buffer
3581 if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer != pktl)
3582 ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer = pktl;
3583 last = pktl;
3584 pktl = pktl->next;
3585 stream_count--;
3586 }
3587 // purge packet queue
3588 while (pktl) {
3589 PacketListEntry *next = pktl->next;
3590 av_packet_unref(&pktl->pkt);
3591 av_freep(&pktl);
3592 pktl = next;
3593 }
3594 if (last)
3595 last->next = NULL;
3596 else {
3597 si->packet_buffer.head = NULL;
3598 si->packet_buffer.tail = NULL;
3599 goto out;
3600 }
3601 pktl = si->packet_buffer.head;
3602 }
3603
3604 if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer == pktl)
3607 av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", out->stream_index, out->dts);
3608 return 1;
3609 } else {
3610 out:
3611 return 0;
3612 }
3613}
3614
3616 const AVPacket *pkt)
3617{
3618 MXFStreamContext *sc = s->streams[pkt ->stream_index]->priv_data;
3619 MXFStreamContext *sc2 = s->streams[next->stream_index]->priv_data;
3620
3621 return next->dts > pkt->dts ||
3622 (next->dts == pkt->dts && sc->order < sc2->order);
3623}
3624
3626 int flush, int has_packet)
3627{
3628 int ret;
3629 if (has_packet) {
3630 MXFStreamContext *sc = s->streams[pkt->stream_index]->priv_data;
3631 pkt->pts = pkt->dts = sc->pkt_cnt++;
3633 return ret;
3634 }
3636}
3637
3639{
3640 if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
3641 if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
3642 AV_RB24(pkt->data) != 0x000001)
3643 return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
3644 }
3645 return 1;
3646}
3647
3648#define MXF_COMMON_OPTIONS \
3649 { "signal_standard", "Force/set Signal Standard",\
3650 offsetof(MXFContext, signal_standard), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
3651 { "bt601", "ITU-R BT.601 and BT.656, also SMPTE 125M (525 and 625 line interlaced)",\
3652 0, AV_OPT_TYPE_CONST, {.i64 = 1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
3653 { "bt1358", "ITU-R BT.1358 and ITU-R BT.799-3, also SMPTE 293M (525 and 625 line progressive)",\
3654 0, AV_OPT_TYPE_CONST, {.i64 = 2}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
3655 { "smpte347m", "SMPTE 347M (540 Mbps mappings)",\
3656 0, AV_OPT_TYPE_CONST, {.i64 = 3}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
3657 { "smpte274m", "SMPTE 274M (1125 line)",\
3658 0, AV_OPT_TYPE_CONST, {.i64 = 4}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
3659 { "smpte296m", "SMPTE 296M (750 line progressive)",\
3660 0, AV_OPT_TYPE_CONST, {.i64 = 5}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
3661 { "smpte349m", "SMPTE 349M (1485 Mbps mappings)",\
3662 0, AV_OPT_TYPE_CONST, {.i64 = 6}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
3663 { "smpte428", "SMPTE 428-1 DCDM",\
3664 0, AV_OPT_TYPE_CONST, {.i64 = 7}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},
3665
3666
3667
3668static const AVOption mxf_options[] = {
3670 { "store_user_comments", "",
3671 offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
3672 { NULL },
3673};
3674
3675static const AVClass mxf_muxer_class = {
3676 .class_name = "MXF muxer",
3677 .item_name = av_default_item_name,
3678 .option = mxf_options,
3679 .version = LIBAVUTIL_VERSION_INT,
3680};
3681
3682static const AVOption d10_options[] = {
3683 { "d10_channelcount", "Force/set channelcount in generic sound essence descriptor",
3684 offsetof(MXFContext, channel_count), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 8, AV_OPT_FLAG_ENCODING_PARAM},
3686 { "store_user_comments", "",
3687 offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
3688 { NULL },
3689};
3690
3692 .class_name = "MXF-D10 muxer",
3693 .item_name = av_default_item_name,
3694 .option = d10_options,
3695 .version = LIBAVUTIL_VERSION_INT,
3696};
3697
3698static const AVOption opatom_options[] = {
3699 { "mxf_audio_edit_rate", "Audio edit rate for timecode",
3700 offsetof(MXFContext, audio_edit_rate), AV_OPT_TYPE_RATIONAL, {.dbl=25}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
3702 { "store_user_comments", "",
3703 offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
3704 { NULL },
3705};
3706
3708 .class_name = "MXF-OPAtom muxer",
3709 .item_name = av_default_item_name,
3710 .option = opatom_options,
3711 .version = LIBAVUTIL_VERSION_INT,
3712};
3713
3715 .p.name = "mxf",
3716 .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format)"),
3717 .p.mime_type = "application/mxf",
3718 .p.extensions = "mxf",
3719 .priv_data_size = sizeof(MXFContext),
3720 .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
3721 .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
3722 .p.subtitle_codec = AV_CODEC_ID_EIA_608,
3723 .init = mxf_init,
3724 .write_packet = mxf_write_packet,
3725 .write_trailer = mxf_write_footer,
3726 .deinit = mxf_deinit,
3727 .p.flags = AVFMT_NOTIMESTAMPS,
3728 .interleave_packet = mxf_interleave,
3729 .p.priv_class = &mxf_muxer_class,
3730 .check_bitstream = mxf_check_bitstream,
3731};
3732
3734 .p.name = "mxf_d10",
3735 .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) D-10 Mapping"),
3736 .p.mime_type = "application/mxf",
3737 .priv_data_size = sizeof(MXFContext),
3738 .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
3739 .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
3740 .init = mxf_init,
3741 .write_packet = mxf_write_packet,
3742 .write_trailer = mxf_write_footer,
3743 .deinit = mxf_deinit,
3744 .p.flags = AVFMT_NOTIMESTAMPS,
3745 .interleave_packet = mxf_interleave,
3746 .p.priv_class = &mxf_d10_muxer_class,
3747};
3748
3750 .p.name = "mxf_opatom",
3751 .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) Operational Pattern Atom"),
3752 .p.mime_type = "application/mxf",
3753 .p.extensions = "mxf",
3754 .priv_data_size = sizeof(MXFContext),
3755 .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
3756 .p.video_codec = AV_CODEC_ID_DNXHD,
3757 .p.subtitle_codec = AV_CODEC_ID_EIA_608,
3758 .init = mxf_init,
3759 .write_packet = mxf_write_packet,
3760 .write_trailer = mxf_write_footer,
3761 .deinit = mxf_deinit,
3762 .p.flags = AVFMT_NOTIMESTAMPS,
3763 .interleave_packet = mxf_interleave,
3764 .p.priv_class = &mxf_opatom_muxer_class,
3765 .check_bitstream = mxf_check_bitstream,
3766};
const FFOutputFormat ff_mxf_muxer
Definition mxfenc.c:3714
const FFOutputFormat ff_mxf_opatom_muxer
Definition mxfenc.c:3749
const FFOutputFormat ff_mxf_d10_muxer
Definition mxfenc.c:3733
#define entry
static FILE * out
#define EXTERN
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
int ff_avc_decode_sps(H264SPS *sps, const uint8_t *buf, int buf_size)
Definition avc.c:196
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:865
Main libavformat public API header.
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition avformat.h:1570
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:500
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition aviobuf.c:464
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition avio.h:41
void avio_wl32(AVIOContext *s, unsigned int val)
Definition aviobuf.c:360
void avio_wl16(AVIOContext *s, unsigned int val)
Definition aviobuf.c:440
void avio_w8(AVIOContext *s, int b)
Definition aviobuf.c:184
void avio_wb32(AVIOContext *s, unsigned int val)
Definition aviobuf.c:368
void avio_wb16(AVIOContext *s, unsigned int val)
Definition aviobuf.c:446
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition avio.h:145
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:507
void avio_wb24(AVIOContext *s, unsigned int val)
Definition aviobuf.c:458
void avio_wb64(AVIOContext *s, uint64_t val)
Definition aviobuf.c:434
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
int avio_put_str16be(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16BE and write it.
void ffio_fill(AVIOContext *s, int b, int64_t count)
Definition aviobuf.c:192
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition bytestream.h:277
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition bytestream.h:168
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
#define s(width, name)
Definition cbs_vp9.c:198
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
Definition common.h:477
#define av_clip_uint16
Definition common.h:112
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
Misc types and constants that do not belong anywhere else.
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition defs.h:61
#define AV_PROFILE_PRORES_STANDARD
Definition defs.h:197
#define AV_PROFILE_PRORES_4444
Definition defs.h:199
#define AV_PROFILE_PRORES_LT
Definition defs.h:196
#define AV_PROFILE_PRORES_PROXY
Definition defs.h:195
@ AV_FIELD_TT
Top coded_first, top displayed first.
Definition defs.h:230
@ AV_FIELD_UNKNOWN
Definition defs.h:228
@ AV_FIELD_PROGRESSIVE
Definition defs.h:229
@ AV_FIELD_TB
Top coded first, bottom displayed first.
Definition defs.h:232
#define AV_PROFILE_PRORES_XQ
Definition defs.h:200
#define AV_PROFILE_PRORES_HQ
Definition defs.h:198
static AVPacket * pkt
static AVFrame * frame
void(* flush)(AVBSFContext *ctx)
Definition dts2pts.c:615
enum AVCodecID id
Definition dts2pts.c:612
double value
Definition eval.c:102
const char * key
int ret
Definition ffplay.c:391
#define sample
static const uint8_t frame_size[4]
Definition g723_1.h:222
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
exp golomb vlc stuff
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition golomb.h:120
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition golomb.h:104
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition opt.h:351
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
Definition opt.h:279
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition utils.c:557
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_PCM_S16LE
Definition codec_id.h:333
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_JPEG2000
Definition codec_id.h:138
@ AV_CODEC_ID_PCM_S24LE
Definition codec_id.h:345
@ AV_CODEC_ID_FFV1
Definition codec_id.h:83
@ AV_CODEC_ID_EIA_608
Definition codec_id.h:582
@ AV_CODEC_ID_DVVIDEO
Definition codec_id.h:74
@ AV_CODEC_ID_PRORES
Definition codec_id.h:198
@ AV_CODEC_ID_SMPTE_436M_ANC
Definition codec_id.h:616
@ AV_CODEC_ID_DNXHD
Definition codec_id.h:149
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
@ AV_CODEC_ID_MPEG1VIDEO
Definition codec_id.h:51
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition packet.c:571
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition packet.h:219
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:61
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition dict.h:75
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition mathematics.c:58
@ AV_ROUND_UP
Round toward +infinity.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition mem.c:326
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition avutil.h:202
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
#define AV_STRINGIFY(s)
Definition macros.h:66
int index
Definition gxfenc.c:90
H.264 common definitions.
@ H264_NAL_PPS
Definition h264.h:42
@ H264_NAL_SPS
Definition h264.h:41
@ H264_NAL_SLICE
Definition h264.h:35
@ H264_NAL_IDR_SLICE
Definition h264.h:39
int a
#define av_log2
Definition intmath.h:84
#define AV_RL24(x)
#define AV_RB32(p)
#define AV_WB64(p, v)
#define AV_RL16(p)
#define AV_RB24(x)
JPEG 2000 structures and defines common to encoder and decoder.
@ JPEG2000_SIZ
Definition jpeg2000.h:44
@ JPEG2000_SOC
Definition jpeg2000.h:42
enum MPFType type
Definition jpegmpfenc.c:55
unsigned offset
Definition libaomenc.c:763
static void write_metadata(AVFormatContext *s, unsigned int ts)
Definition flvenc.c:298
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:390
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition internal.h:135
int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int(*compare)(AVFormatContext *, const AVPacket *, const AVPacket *))
Add packet to an AVFormatContext's packet_buffer list, determining its interleaved position using com...
Definition mux.c:880
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition mux.c:1339
int ff_packet_list_get(PacketList *list, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
Definition packet_list.c:89
Libavformat version macros.
#define LIBAVFORMAT_VERSION_MICRO
Definition version.h:35
#define LIBAVFORMAT_VERSION
Definition version.h:40
#define LIBAVFORMAT_VERSION_MINOR
Definition version.h:34
#define LIBAVFORMAT_VERSION_MAJOR
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
version
Definition libkvazaar.c:313
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
uint32_t tag
Definition movenc.c:2144
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
Parse creation_time in AVFormatContext metadata if exists and warn if the parsing fails.
Definition mux_utils.c:137
const MXFCodecUL ff_mxf_data_definition_uls[]
SMPTE RP224 http://www.smpte-ra.org/mdd/index.html.
Definition mxf.c:31
const uint8_t ff_mxf_random_index_pack_key[16]
Definition mxf.c:26
const MXFCodecUL ff_mxf_color_space_uls[]
Definition mxf.c:134
const MXFCodecUL ff_mxf_color_trc_uls[]
Definition mxf.c:113
int ff_mxf_get_content_package_rate(AVRational time_base)
Definition mxf.c:220
const MXFCodecUL ff_mxf_color_primaries_uls[]
Definition mxf.c:98
#define FF_MXF_MasteringDisplayMinimumLuminance
Definition mxf.h:100
#define PRINT_KEY(pc, s, x)
Definition mxf.h:155
#define FF_MXF_MasteringDisplayPrimaries
Definition mxf.h:97
#define FF_MXF_MasteringDisplayWhitePointChromaticity
Definition mxf.h:98
#define FF_MXF_MASTERING_CHROMA_DEN
Definition mxf.h:102
#define FF_MXF_MASTERING_LUMA_DEN
Definition mxf.h:103
AVUUID UID
Definition mxf.h:30
#define FF_MXF_MasteringDisplayMaximumLuminance
Definition mxf.h:99
MXFMetadataSetType
Definition mxf.h:32
@ Sequence
Definition mxf.h:38
@ MultipleDescriptor
Definition mxf.h:39
@ MaterialPackage
Definition mxf.h:33
@ TapeDescriptor
Definition mxf.h:51
@ SourceClip
Definition mxf.h:35
@ IndexTableSegment
Definition mxf.h:47
@ FFV1SubDescriptor
Definition mxf.h:56
@ TaggedValue
Definition mxf.h:50
@ EssenceContainerData
Definition mxf.h:48
@ SourcePackage
Definition mxf.h:34
@ Preface
Definition mxf.h:43
@ SubDescriptor
Definition mxf.h:46
@ JPEG2000SubDescriptor
Definition mxf.h:57
@ TimecodeComponent
Definition mxf.h:36
@ Identification
Definition mxf.h:44
@ ContentStorage
Definition mxf.h:45
@ AVCSubDescriptor
Definition mxf.h:52
static const uint8_t mxf_indirect_value_utf16le[]
Definition mxfdec.c:356
static int64_t mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key)
Definition mxfenc.c:1738
static const UID mxf_d10_container_uls[]
Definition mxfenc.c:260
static const MXFCodecUL * mxf_get_codec_ul_by_id(const MXFCodecUL *uls, int id)
Definition mxfenc.c:713
static const uint8_t header_metadata_key[]
partial key for header metadata
Definition mxfenc.c:300
static unsigned klv_fill_size(uint64_t size)
Definition mxfenc.c:2001
static const uint8_t footer_partition_key[]
Definition mxfenc.c:287
#define PLATFORM_IDENT
Definition mxfenc.c:875
static const uint8_t opatom_ul[]
Definition mxfenc.c:286
static void mxf_write_identification(AVFormatContext *s)
Definition mxfenc.c:876
static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:1084
static const struct @372336353377014153333003247272374275277155076241 mxf_dv_uls[]
static int mxf_compare_timestamps(AVFormatContext *s, const AVPacket *next, const AVPacket *pkt)
Definition mxfenc.c:3615
static int mxf_write_mpegvideo_local_tags(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1654
static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flush)
Definition mxfenc.c:3564
static int mxf_write_opatom_body_partition(AVFormatContext *s)
Definition mxfenc.c:3261
static const UID mxf_generic_sound_descriptor_key
Definition mxfenc.c:1212
static void mxf_write_essence_container_refs(AVFormatContext *s)
Definition mxfenc.c:727
static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2427
static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational tbc)
Definition mxfenc.c:2892
static void mxf_write_refs_count(AVIOContext *pb, int ref_count)
Definition mxfenc.c:514
#define IS_D10(s)
Definition mxfenc.c:74
static const uint8_t uuid_base[]
Definition mxfenc.c:279
static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2311
static const struct @225240156112102161247264322247151334121242040336 mxf_essence_mappings[]
static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:1057
uint8_t interlaced
Definition mxfenc.c:2337
static int mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1647
static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2713
static const uint8_t klv_fill_key[]
Definition mxfenc.c:292
static void mxf_write_local_tag_utf16(AVFormatContext *s, int tag, const char *value)
Definition mxfenc.c:845
static int mxf_write_essence_container_data(AVFormatContext *s)
Definition mxfenc.c:1927
UID codec_ul
Definition mxfenc.c:2301
#define FFV1_CONTEXT_SIZE
Definition mxfenc.c:2660
static void mxf_write_track(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:956
ULIndex
Definition mxfenc.c:143
@ INDEX_JPEG2000
Definition mxfenc.c:151
@ INDEX_AES3
Definition mxfenc.c:145
@ INDEX_DNXHD
Definition mxfenc.c:150
@ INDEX_H264
Definition mxfenc.c:152
@ INDEX_DV
Definition mxfenc.c:149
@ INDEX_S436M
Definition mxfenc.c:153
@ INDEX_D10_AUDIO
Definition mxfenc.c:148
@ INDEX_PRORES
Definition mxfenc.c:154
@ INDEX_WAV
Definition mxfenc.c:146
@ INDEX_FFV1
Definition mxfenc.c:155
@ INDEX_MPEG2
Definition mxfenc.c:144
@ INDEX_D10_VIDEO
Definition mxfenc.c:147
static int get_ffv1_unsigned_symbol(RangeCoder *c, uint8_t *state)
Definition mxfenc.c:2639
static const UID mxf_rgba_descriptor_key
Definition mxfenc.c:295
static const UID mxf_ffv1_codec_uls[]
Definition mxfenc.c:270
static int mxf_get_essence_container_ul_index(enum AVCodecID id)
Definition mxfenc.c:563
static int klv_encode_ber_length(AVIOContext *pb, uint64_t len)
Definition mxfenc.c:528
static void mxf_write_content_storage(AVFormatContext *s, MXFPackage *packages, int package_count)
Definition mxfenc.c:929
static void mxf_write_tape_descriptor(AVFormatContext *s)
Definition mxfenc.c:1119
static const UID mxf_mpegvideo_descriptor_key
Definition mxfenc.c:1208
static const uint8_t product_uid[]
Definition mxfenc.c:278
static const UID mxf_jpeg2000_subdescriptor_key
Definition mxfenc.c:1216
#define EDIT_UNITS_PER_BODY
Definition mxfenc.c:77
static uint64_t mxf_parse_timestamp(int64_t timestamp64)
Definition mxfenc.c:2864
static int mxf_write_index_table_segment(AVFormatContext *s)
Definition mxfenc.c:2022
static int mxf_write_user_comments(AVFormatContext *s, const AVDictionary *m)
Definition mxfenc.c:1805
static int mxf_write_package(AVFormatContext *s, MXFPackage *package)
Definition mxfenc.c:1823
static const AVOption mxf_options[]
Definition mxfenc.c:3668
static const MXFLocalTagPair mxf_local_tag_batch[]
SMPTE RP210 http://www.smpte-ra.org/mdd/index.html https://smpte-ra.org/sites/default/files/Labels....
Definition mxfenc.c:307
static int mxf_check_frame_offset(AVFormatContext *s, int offset)
Definition mxfenc.c:2010
static const uint8_t system_metadata_package_set_key[]
Definition mxfenc.c:3177
static void klv_encode_ber4_length(AVIOContext *pb, int len)
Definition mxfenc.c:548
static const UID mxf_mpeg2_codec_uls[]
Definition mxfenc.c:2762
static const uint8_t header_closed_partition_key[]
Definition mxfenc.c:291
static const uint8_t primer_pack_key[]
Definition mxfenc.c:288
static uint32_t rescale_mastering_luma(AVRational q)
Definition mxfenc.c:1223
static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, MXFIndexEntry *e)
Definition mxfenc.c:2795
static int mxf_interleave(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
Definition mxfenc.c:3625
static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value)
Definition mxfenc.c:498
static const struct @117203202152267247126110227165170060075114153320 mxf_prores_codec_uls[]
static void mxf_write_common_fields(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1004
static const UID mxf_avc_subdescriptor_key
Definition mxfenc.c:1214
static int mxf_utf16_local_tag_length(const char *utf8_str)
Definition mxfenc.c:826
static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:3229
static void mxf_write_system_item(AVFormatContext *s)
Definition mxfenc.c:3179
int profile
Definition mxfenc.c:2300
static int mxf_write_aes3_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1760
static uint64_t mxf_utf16len(const char *utf8_str)
Definition mxfenc.c:804
static void mxf_deinit(AVFormatContext *s)
Definition mxfenc.c:3555
static int mxf_write_tagged_value(AVFormatContext *s, const char *name, const char *value)
Definition mxfenc.c:1776
static const AVClass mxf_muxer_class
Definition mxfenc.c:3675
static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, MXFIndexEntry *e)
Definition mxfenc.c:2520
static const AVOption d10_options[]
Definition mxfenc.c:3682
static int mxf_write_header_metadata_sets(AVFormatContext *s)
Definition mxfenc.c:1949
#define MXF_NUM_TAGS
Definition mxfenc.c:462
static const uint8_t index_table_segment_key[]
Definition mxfenc.c:289
static int64_t mxf_write_generic_picture_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1228
static void mxf_write_umid(AVFormatContext *s, int type)
Definition mxfenc.c:505
static void klv_encode_ber9_length(AVIOContext *pb, uint64_t len)
Definition mxfenc.c:554
static const uint8_t header_open_partition_key[]
Definition mxfenc.c:290
static const AVOption opatom_options[]
Definition mxfenc.c:3698
static const struct @213176060366221100351007056114013075347222044276 mxf_h264_codec_uls[]
UID uid
Definition mxfenc.c:2489
static const UID mxf_wav_descriptor_key
Definition mxfenc.c:1209
static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition mxfenc.c:3332
static const UID mxf_ffv1_subdescriptor_key
Definition mxfenc.c:1215
static int mxf_write_cdci_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1603
#define IS_OPATOM(s)
Definition mxfenc.c:75
static const struct @120164275265124234064020245000334222001022363076 mxf_dnxhd_codec_uls[]
static void mxf_write_ffv1_subdesc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1618
static void mxf_write_sequence(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:1030
static int mxf_init(AVFormatContext *s)
Definition mxfenc.c:2943
static const MXFLocalTagPair * mxf_lookup_local_tag(int tag)
Definition mxfenc.c:572
static int mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1767
const UID container_ul
Definition mxfenc.c:2402
static void mxf_update_klv_size(AVIOContext *pb, int64_t pos)
Definition mxfenc.c:1512
static uint16_t rescale_mastering_chroma(AVRational q)
Definition mxfenc.c:1218
static const UID mxf_d10_codec_uls[]
Definition mxfenc.c:251
static const UID mxf_aes3_descriptor_key
Definition mxfenc.c:1210
#define KAG_SIZE
Definition mxfenc.c:78
static int mxf_write_wav_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1753
static void mxf_write_random_index_pack(AVFormatContext *s)
Definition mxfenc.c:3467
static int64_t mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const UID key)
Definition mxfenc.c:1169
static const uint8_t system_metadata_pack_key[]
Definition mxfenc.c:3176
static const uint8_t op1a_ul[]
complete key for operation pattern, partitions, and primer pack
Definition mxfenc.c:285
static const MXFContainerEssenceEntry mxf_essence_container_uls[]
Definition mxfenc.c:187
int8_t intra_only
Definition mxfenc.c:2493
static void mxf_mark_tag_unused(MXFContext *mxf, int tag)
Definition mxfenc.c:585
static void mxf_write_local_tag(AVFormatContext *s, int size, int tag)
Definition mxfenc.c:694
static enum AVChromaLocation choose_chroma_location(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:2916
static const uint8_t smpte_12m_timecode_track_data_ul[]
Definition mxfenc.c:1002
static void mxf_gen_umid(AVFormatContext *s)
Definition mxfenc.c:2880
static int mxf_write_jpeg2000_subdesc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1545
static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2362
static const UID * mxf_get_mpeg2_codec_ul(AVCodecParameters *par)
Definition mxfenc.c:2775
static int mxf_write_partition(AVFormatContext *s, int bodysid, int indexsid, const uint8_t *key, int write_metadata)
Definition mxfenc.c:2194
#define DESCRIPTOR_COUNT(essence_container_count)
Definition mxfenc.c:724
static void mxf_write_primer_pack(AVFormatContext *s)
Definition mxfenc.c:591
static void mxf_write_preface(AVFormatContext *s)
Definition mxfenc.c:749
static int64_t mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, const UID key)
Definition mxfenc.c:1689
static const AVClass mxf_opatom_muxer_class
Definition mxfenc.c:3707
static const UID mxf_s436m_anc_descriptor_key
Definition mxfenc.c:1207
static void mxf_write_metadata_key(AVIOContext *pb, unsigned int value)
Definition mxfenc.c:707
static void store_version(AVFormatContext *s)
Definition mxfenc.c:859
static void mxf_write_multi_descriptor(AVFormatContext *s)
Definition mxfenc.c:1132
static void mxf_write_avc_subdesc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1521
static int mxf_write_footer(AVFormatContext *s)
Definition mxfenc.c:3494
uint16_t cid
Definition mxfenc.c:2336
static int mxf_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
Definition mxfenc.c:3638
static const uint8_t multiple_desc_ul[]
Definition mxfenc.c:301
#define MXF_COMMON_OPTIONS
Definition mxfenc.c:3648
static void mxf_compute_edit_unit_byte_count(AVFormatContext *s)
Definition mxfenc.c:3311
static const uint8_t umid_ul[]
Definition mxfenc.c:280
static int klv_ber_length(uint64_t len)
Definition mxfenc.c:520
static int mxf_parse_ffv1_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2661
static int mxf_write_opatom_packet(AVFormatContext *s, AVPacket *pkt, MXFIndexEntry *ie)
Definition mxfenc.c:3282
static const UID mxf_cdci_descriptor_key
Definition mxfenc.c:1211
static const uint8_t body_partition_key[]
Definition mxfenc.c:293
static void mxf_write_klv_fill(AVFormatContext *s)
Definition mxfenc.c:2182
static const AVClass mxf_d10_muxer_class
Definition mxfenc.c:3691
const uint8_t * ff_nal_find_startcode(const uint8_t *p, const uint8_t *end)
Definition nal.c:68
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
AVChromaLocation
Location of chroma samples.
Definition pixfmt.h:811
@ AVCHROMA_LOC_TOP
Definition pixfmt.h:816
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition pixfmt.h:815
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition pixfmt.h:813
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition pixfmt.h:814
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:812
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:775
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:758
const char * name
Definition qsvenc.c:142
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
Definition rangecoder.c:53
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
Definition rangecoder.c:68
Range coder.
static int get_rac(RangeCoder *c, uint8_t *const state)
Definition rangecoder.h:118
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition spdifenc.c:431
Accelerated start code search function for start codes common to MPEG-1/2/4 video,...
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
enum AVColorSpace color_space
Definition codec_par.h:192
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
enum AVFieldOrder field_order
The order of the fields in interlaced video.
Definition codec_par.h:182
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition codec_par.h:88
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition codec_par.h:99
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition codec_par.h:135
int block_align
The number of bytes per coded audio frame, required by some formats.
Definition codec_par.h:221
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
Definition codec_par.h:161
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
enum AVColorPrimaries color_primaries
Definition codec_par.h:190
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
enum AVColorTransferCharacteristic color_trc
Definition codec_par.h:191
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition codec_par.h:83
enum AVChromaLocation chroma_location
Definition codec_par.h:193
enum AVColorRange color_range
Additional colorspace characteristics.
Definition codec_par.h:189
int depth
Number of bits in the component.
Definition pixdesc.h:57
char * key
Definition dict.h:91
char * value
Definition dict.h:92
Format I/O context.
Definition avformat.h:1401
Bytestream IO Context.
Definition avio.h:160
unsigned char * buf_ptr
Current position in the buffer.
Definition avio.h:227
Mastering display metadata capable of representing the color volume of the display used to master the...
AVOption.
Definition opt.h:428
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition packet.h:431
uint8_t * data
Definition packet.h:432
This structure stores compressed data.
Definition packet.h:587
int stream_index
Definition packet.h:612
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition packet.h:609
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition pixdesc.h:71
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
AVDictionary * metadata
Definition avformat.h:848
void * priv_data
Definition avformat.h:793
int index
stream index in AVFormatContext
Definition avformat.h:774
AVRational avg_frame_rate
Average framerate.
Definition avformat.h:857
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807
AVRational r_frame_rate
Real base framerate of the stream.
Definition avformat.h:902
uint32_t flags
flags such as drop frame, +24 hours support, ...
Definition timecode.h:43
AVRational rate
frame rate in rational form
Definition timecode.h:44
int start
timecode frame start (first base frame number)
Definition timecode.h:42
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
Definition internal.h:86
PacketListEntry * last_in_packet_buffer
last packet in packet_buffer for this stream when muxing.
Definition internal.h:335
Definition avc.h:32
UID uid
Definition mxf.h:106
int id
Definition mxf.h:108
int(* write_desc)(AVFormatContext *, AVStream *)
Definition mxfenc.c:133
int64_t footer_partition_offset
Definition mxfenc.c:466
uint32_t tagged_value_count
Definition mxfenc.c:489
int last_indexed_edit_unit
Definition mxfenc.c:474
uint64_t * body_partition_offset
Definition mxfenc.c:475
uint8_t unused_tags[MXF_NUM_TAGS]
local tags that we know will not be used
Definition mxfenc.c:494
int store_user_comments
Definition mxfenc.c:491
uint64_t duration
Definition mxfenc.c:478
int signal_standard
Definition mxfenc.c:488
unsigned body_partitions_count
Definition mxfenc.c:476
AVClass * av_class
Definition mxfenc.c:465
AVStream * timecode_track
Definition mxfenc.c:480
MXFIndexEntry * index_entries
Definition mxfenc.c:470
AVRational audio_edit_rate
Definition mxfenc.c:490
int cbr_index
use a constant bitrate index
Definition mxfenc.c:493
uint32_t instance_number
Definition mxfenc.c:485
AVRational time_base
Definition mxfenc.c:468
AVTimecode tc
timecode context
Definition mxfenc.c:479
int edit_unit_byte_count
fixed edit unit byte count
Definition mxfenc.c:482
int track_instance_count
Definition mxfenc.c:492
uint64_t body_offset
Definition mxfenc.c:484
int timecode_base
rounded time code base (25 or 30)
Definition mxfenc.c:481
int content_package_rate
content package rate in system element, see SMPTE 326M
Definition mxfenc.c:483
uint8_t umid[16]
unique material identifier
Definition mxfenc.c:486
int header_written
Definition mxfenc.c:469
int channel_count
Definition mxfenc.c:487
uint8_t slice_count
index slice count minus 1 (1 if no audio, 0 otherwise)
Definition mxfenc.c:473
uint64_t timestamp
timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8)
Definition mxfenc.c:472
int last_key_index
index of last key frame
Definition mxfenc.c:477
unsigned edit_units_count
Definition mxfenc.c:471
int essence_container_count
Definition mxfenc.c:467
MXFStreamContext timecode_track_priv
Definition mxfenc.c:495
unsigned slice_offset
offset of audio slice
Definition mxfenc.c:82
uint64_t offset
Definition mxfenc.c:81
uint8_t flags
Definition mxfenc.c:84
uint16_t temporal_ref
Definition mxfenc.c:83
struct MXFPackage * ref
Definition mxfenc.c:140
enum MXFMetadataSetType type
Definition mxfenc.c:138
int instance
Definition mxfenc.c:139
char * name
Definition mxfdec.c:276
int max_gop
maximum gop size, used by mpeg-2 descriptor
Definition mxfenc.c:118
int temporal_reordering
Definition mxfenc.c:111
enum MXFMetadataSetType sub_descriptor
Definition mxfenc.c:124
int version
format version, used in ffv1 descriptor
Definition mxfenc.c:121
int cid
compression id, used by dnxhd
Definition mxfenc.c:126
int index
index in mxf_essence_container_uls table
Definition mxfenc.c:104
int closed_gop
gop is closed, used in mpeg-2 frame parsing
Definition mxfenc.c:113
UID track_essence_element_key
Definition mxfenc.c:103
const UID * codec_ul
Definition mxfenc.c:105
int field_dominance
tff=1, bff=2
Definition mxfenc.c:109
int low_delay
low delay, used in mpeg-2 descriptor
Definition mxfenc.c:120
int micro_version
format micro_version, used in ffv1 descriptor
Definition mxfenc.c:122
int frame_size
frame size in bytes
Definition mxfenc.c:116
AVRational aspect_ratio
display aspect ratio
Definition mxfenc.c:112
int seq_closed_gop
all gops in sequence are closed, used in mpeg-2 descriptor
Definition mxfenc.c:117
int order
interleaving order if dts are equal
Definition mxfenc.c:107
int64_t pkt_cnt
pkt counter for muxed packets
Definition mxfenc.c:102
int interlaced
whether picture is interlaced
Definition mxfenc.c:108
j2k_info_t j2k_info
Definition mxfenc.c:123
const UID * picture_descriptor_key
Definition mxfenc.c:125
int signal_standard
Definition mxfenc.c:110
int b_picture_count
maximum number of consecutive b pictures, used in mpeg-2 descriptor
Definition mxfenc.c:119
const UID * container_ul
Definition mxfenc.c:106
struct PacketListEntry * next
PacketListEntry * tail
PacketListEntry * head
uint8_t j2k_comp_desc[12]
j2k components descriptor (Ssiz(i), XRsiz(i), YRsiz(i))
Definition mxfenc.c:98
uint32_t j2k_ysiz
j2k height of the reference grid (Ysiz)
Definition mxfenc.c:91
uint32_t j2k_xsiz
j2k width of the reference grid (Xsiz)
Definition mxfenc.c:90
uint16_t j2k_cap
j2k required decoder capabilities
Definition mxfenc.c:88
uint32_t j2k_y0siz
j2k vertical offset from the origin of the reference grid to the left side of the image (Y0siz)
Definition mxfenc.c:93
uint32_t j2k_ytsiz
j2k height of one reference tile with respect to the reference grid (YTsiz)
Definition mxfenc.c:95
uint32_t j2k_x0siz
j2k horizontal offset from the origin of the reference grid to the left side of the image (X0siz)
Definition mxfenc.c:92
uint32_t j2k_yt0siz
j2k vertical offset from the origin of the reference grid to the left side of the first tile (YT0siz)
Definition mxfenc.c:97
uint16_t j2k_rsiz
j2k required decoder capabilities (Rsiz)
Definition mxfenc.c:89
uint32_t j2k_xt0siz
j2k horizontal offset from the origin of the reference grid to the left side of the first tile (XT0si...
Definition mxfenc.c:96
uint32_t j2k_xtsiz
j2k width of one reference tile with respect to the reference grid (XTsiz)
Definition mxfenc.c:94
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static struct @232240247175332074307271266321204261331170211232 state
#define gmtime_r
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
Parse timecode representation (hh:mm:ss[:;.
Definition timecode.c:241
int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx)
Init a timecode struct with the passed parameters.
Definition timecode.c:201
uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum)
Convert frame number to SMPTE 12M binary representation.
Definition timecode.c:54
Timecode helpers header.
@ AV_TIMECODE_FLAG_DROPFRAME
timecode is drop frame
Definition timecode.h:36
int size
const char * g
Definition vf_curves.c:128
static unsigned int seed
Definition videogen.c:78
int len
static double c[64]