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
46#include "libavutil/mem.h"
47#include "libavutil/opt.h"
49#include "libavutil/timecode.h"
50#include "libavutil/avassert.h"
52#include "libavutil/pixdesc.h"
54#include "libavcodec/defs.h"
56#include "libavcodec/golomb.h"
57#include "libavcodec/h264.h"
58#include "libavcodec/jpeg2000.h"
59#include "packet_internal.h"
62#include "avformat.h"
63#include "avio_internal.h"
64#include "internal.h"
65#include "avc.h"
66#include "nal.h"
67#include "mux.h"
68#include "mxf.h"
69#include "config.h"
70#include "version.h"
71
74
75#define IS_D10(s) ((s)->oformat == &ff_mxf_d10_muxer.p)
76#define IS_OPATOM(s) ((s)->oformat == &ff_mxf_opatom_muxer.p)
77
78#define EDIT_UNITS_PER_BODY 250
79#define KAG_SIZE 512
80
81typedef struct MXFIndexEntry {
82 uint64_t offset;
83 unsigned slice_offset; ///< offset of audio slice
84 uint16_t temporal_ref;
85 uint8_t flags;
87
88typedef struct j2k_info_t {
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 uint16_t j2k_csiz; ///< number of coded components (Csiz)
99 uint8_t j2k_comp_desc[12]; ///< j2k components descriptor (Ssiz(i), XRsiz(i), YRsiz(i))
100} j2k_info_t;
101
102typedef struct MXFStreamContext {
103 int64_t pkt_cnt; ///< pkt counter for muxed packets
105 int index; ///< index in mxf_essence_container_uls table
106 const UID *codec_ul;
108 UID clip_container_ul; ///< clip wrapping essence container ul, used by OPAtom
109 int order; ///< interleaving order if dts are equal
110 int interlaced; ///< whether picture is interlaced
111 int field_dominance; ///< first field in temporal order, 1 or 2
112 int display_f2_offset; ///< DisplayF2Offset, 0 or -1
115 AVRational aspect_ratio; ///< display aspect ratio
116 int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing
119 int frame_size; ///< frame size in bytes
120 int element_size; ///< KAG aligned element size, constant for PCM and CBE
121 int seq_closed_gop; ///< all gops in sequence are closed, used in mpeg-2 descriptor
122 int max_gop; ///< maximum gop size, used by mpeg-2 descriptor
123 int b_picture_count; ///< maximum number of consecutive b pictures, used in mpeg-2 descriptor
124 int low_delay; ///< low delay, used in mpeg-2 descriptor
125 int version; ///< format version, used in ffv1 descriptor
126 int micro_version; ///< format micro_version, used in ffv1 descriptor
130 int cid; ///< compression id, used by dnxhd
131 int color_warned; ///< unsupported color properties have been reported
132 /* color properties found in the essence bitstream, unspecified if absent */
138
145
146typedef struct MXFPackage {
147 char *name;
151} MXFPackage;
152
167
168static const struct {
183
189
192
194
196
198 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 },
199 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
200 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 },
202 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 },
203 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x03,0x00 },
204 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
206 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 },
207 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 },
208 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
210 // D-10 Video
211 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
212 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
213 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 },
215 // D-10 Audio
216 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
217 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
218 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
220 // DV
221 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x7F,0x01 },
222 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
223 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x00,0x00,0x00 },
225 // DNxHD
226 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x0D,0x01,0x03,0x01,0x02,0x11,0x01,0x00 },
227 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x0C,0x00 },
228 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 },
230 // JPEG2000
231 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c,0x01,0x00 },
232 { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x08,0x00 },
233 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 },
235 // H.264
236 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x10,0x60,0x01 },
237 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 },
238 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 },
240 // S436M ANC
241 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x0e,0x00,0x00 },
242 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x17,0x01,0x02,0x00 },
243 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x01,0x5C,0x00 },
245 // ProRes
246 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x1c,0x01,0x00 },
247 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x17,0x00 },
248 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x03,0x00 },
250 // FFV1
251 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x23,0x01,0x00 },
252 { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x15,0x01,0x1d,0x00 },
253 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x09,0x00,0x00 },
255 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
256 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
257 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
258 NULL },
259};
260
261static const UID mxf_d10_codec_uls[] = {
262 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, // D-10 625/50 PAL 50mb/s
263 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x02 }, // D-10 525/50 NTSC 50mb/s
264 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x03 }, // D-10 625/50 PAL 40mb/s
265 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x04 }, // D-10 525/50 NTSC 40mb/s
266 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, // D-10 625/50 PAL 30mb/s
267 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 }, // D-10 525/50 NTSC 30mb/s
268};
269
270static const UID mxf_d10_container_uls[] = {
271 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, // D-10 625/50 PAL 50mb/s
272 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 }, // D-10 525/50 NTSC 50mb/s
273 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, // D-10 625/50 PAL 40mb/s
274 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, // D-10 525/50 NTSC 40mb/s
275 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, // D-10 625/50 PAL 30mb/s
276 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 }, // D-10 525/50 NTSC 30mb/s
277};
278
279
280static const UID mxf_ffv1_codec_uls[] = {
281 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x01,0x00 }, // FFV1 version 0
282 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x02,0x00 }, // FFV1 version 1
283 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x03,0x00 }, // FFV1 version 2 (was only experimental)
284 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x04,0x00 }, // FFV1 version 3
285 { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x05,0x00 }, // FFV1 version 4
286};
287
288static const uint8_t product_uid[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd,0x00,0x0c,0x00,0x02};
289static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff };
290static const uint8_t umid_ul[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13 };
291
292/**
293 * complete key for operation pattern, partitions, and primer pack
294 */
295static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x09,0x00 };
296static const uint8_t opatom_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x02,0x01,0x10,0x03,0x00,0x00 };
297static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete
298static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 };
299static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 };
300static const uint8_t header_open_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }; // OpenIncomplete
301static const uint8_t header_closed_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }; // ClosedComplete
302static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };
303static const uint8_t body_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }; // ClosedComplete
304
305static const UID mxf_rgba_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x29,0x00 };
306
307/**
308 * partial key for header metadata
309 */
310static const uint8_t header_metadata_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01 };
311static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x0D,0x01,0x03,0x01,0x02,0x7F,0x01,0x00 };
312
313/**
314 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html
315 * https://smpte-ra.org/sites/default/files/Labels.xml
316 */
318 // preface set
319 { 0x3C0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x02,0x00,0x00,0x00,0x00}}, /* Instance UID */
320 { 0x3B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x04,0x00,0x00}}, /* Last Modified Date */
321 { 0x3B05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x05,0x00,0x00,0x00}}, /* Version */
322 { 0x3B07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x01,0x04,0x00,0x00,0x00}}, /* Object Model Version */
323 { 0x3B06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x04,0x00,0x00}}, /* Identifications reference */
324 { 0x3B03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x01,0x00,0x00}}, /* Content Storage reference */
325 { 0x3B09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x03,0x00,0x00,0x00,0x00}}, /* Operational Pattern UL */
326 { 0x3B0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x01,0x00,0x00}}, /* Essence Containers UL batch */
327 { 0x3B0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x02,0x02,0x10,0x02,0x02,0x00,0x00}}, /* DM Schemes UL batch */
328 // Identification
329 { 0x3C09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x01,0x00,0x00,0x00}}, /* This Generation UID */
330 { 0x3C01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x02,0x01,0x00,0x00}}, /* Company Name */
331 { 0x3C02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x03,0x01,0x00,0x00}}, /* Product Name */
332 { 0x3C03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x04,0x00,0x00,0x00}}, /* Product Version */
333 { 0x3C04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x05,0x01,0x00,0x00}}, /* Version String */
334 { 0x3C05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x07,0x00,0x00,0x00}}, /* Product ID */
335 { 0x3C06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x03,0x00,0x00}}, /* Modification Date */
336 { 0x3C07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x0A,0x00,0x00,0x00}}, /* Toolkit Version */
337 { 0x3C08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x20,0x07,0x01,0x06,0x01,0x00,0x00}}, /* Platform */
338 // Content Storage
339 { 0x1901, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x01,0x00,0x00}}, /* Package strong reference batch */
340 { 0x1902, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x05,0x02,0x00,0x00}}, /* Package strong reference batch */
341 // Essence Container Data
342 { 0x2701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x06,0x01,0x00,0x00,0x00}}, /* Linked Package UID */
343 { 0x3F07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x04,0x00,0x00,0x00,0x00}}, /* BodySID */
344 // Package
345 { 0x4401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x01,0x15,0x10,0x00,0x00,0x00,0x00}}, /* Package UID */
346 { 0x4405, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x01,0x03,0x00,0x00}}, /* Package Creation Date */
347 { 0x4404, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x10,0x02,0x05,0x00,0x00}}, /* Package Modified Date */
348 { 0x4402, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x01,0x03,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Package Name */
349 { 0x4403, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x05,0x00,0x00}}, /* Tracks Strong reference array */
350 { 0x4701, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x03,0x00,0x00}}, /* Descriptor */
351 // Track
352 { 0x4801, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Track ID */
353 { 0x4804, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x01,0x04,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Track Number */
354 { 0x4B01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x05,0x30,0x04,0x05,0x00,0x00,0x00,0x00}}, /* Edit Rate */
355 { 0x4B02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x03,0x00,0x00}}, /* Origin */
356 { 0x4803, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x02,0x04,0x00,0x00}}, /* Sequence reference */
357 // Sequence
358 { 0x0201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x07,0x01,0x00,0x00,0x00,0x00,0x00}}, /* Data Definition UL */
359 { 0x0202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x02,0x01,0x01,0x03,0x00,0x00}}, /* Duration */
360 { 0x1001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x09,0x00,0x00}}, /* Structural Components reference array */
361 // Source Clip
362 { 0x1201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x04,0x00,0x00}}, /* Start position */
363 { 0x1101, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x01,0x00,0x00,0x00}}, /* SourcePackageID */
364 { 0x1102, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x03,0x02,0x00,0x00,0x00}}, /* SourceTrackID */
365 // Timecode Component
366 { 0x1501, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x07,0x02,0x01,0x03,0x01,0x05,0x00,0x00}}, /* Start Time Code */
367 { 0x1502, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x04,0x01,0x01,0x02,0x06,0x00,0x00}}, /* Rounded Time Code Base */
368 { 0x1503, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x04,0x01,0x01,0x05,0x00,0x00,0x00}}, /* Drop Frame */
369 // File Descriptor
370 { 0x3F01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x04,0x06,0x0B,0x00,0x00}}, /* Sub Descriptors reference array */
371 { 0x3006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x06,0x01,0x01,0x03,0x05,0x00,0x00,0x00}}, /* Linked Track ID */
372 { 0x3001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x01,0x00,0x00,0x00,0x00}}, /* SampleRate */
373 { 0x3002, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x02,0x00,0x00,0x00,0x00}}, /* ContainerDuration */
374 { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */
375 // Generic Picture Essence Descriptor
376 { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */
377 { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */
378 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */
379 { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */
380 { 0x3216, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x08,0x00,0x00,0x00}}, /* Stored F2 Offset */
381 { 0x3205, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x08,0x00,0x00,0x00}}, /* Sampled Width */
382 { 0x3204, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x07,0x00,0x00,0x00}}, /* Sampled Height */
383 { 0x3206, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x09,0x00,0x00,0x00}}, /* Sampled X Offset */
384 { 0x3207, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0A,0x00,0x00,0x00}}, /* Sampled Y Offset */
385 { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */
386 { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */
387 { 0x320A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0D,0x00,0x00,0x00}}, /* Display X offset */
388 { 0x320B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0E,0x00,0x00,0x00}}, /* Presentation Y offset */
389 { 0x3217, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x07,0x00,0x00,0x00}}, /* Display F2 offset */
390 { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */
391 { 0x3210, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x01,0x02,0x00}}, /* Transfer characteristic */
392 { 0x321A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x03,0x01,0x00}}, /* Coding Equations (color space) */
393 { 0x3219, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x04,0x01,0x02,0x01,0x01,0x06,0x01,0x00}}, /* Color Primaries */
394 { 0x3213, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x02,0x00,0x00,0x00,0x00}}, /* Image Start Offset */
395 { 0x3214, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Image End Offset */
396 { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */
397 { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */
398 { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard */
399 // CDCI Picture Essence Descriptor
400 { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */
401 { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */
402 { 0x3308, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x01,0x10,0x00,0x00,0x00}}, /* Vertical Subsampling */
403 { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */
404 { 0x3307, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x04,0x00,0x00,0x00,0x00}}, /* Padding Bits */
405 { 0x3304, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x03,0x00,0x00,0x00}}, /* Black Ref level */
406 { 0x3305, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x04,0x00,0x00,0x00}}, /* White Ref level */
407 { 0x3306, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x05,0x00,0x00,0x00}}, /* Color Range */
408 // RGBA Picture Essence Descriptor
409 { 0x3401, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x05,0x03,0x06,0x00,0x00,0x00}}, /* Pixel Layout */
410 { 0x3406, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x05,0x03,0x0B,0x00,0x00,0x00}}, /* Component Max Ref */
411 { 0x3407, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x05,0x03,0x0C,0x00,0x00,0x00}}, /* Component Min Ref */
412 // Generic Sound Essence Descriptor
413 { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */
414 { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */
415 { 0x3D04, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x02,0x01,0x01,0x03,0x00,0x00,0x00}}, /* Audio Ref Level */
416 { 0x3D07, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x01,0x01,0x04,0x00,0x00,0x00}}, /* ChannelCount */
417 { 0x3D01, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x03,0x04,0x00,0x00,0x00}}, /* Quantization bits */
418 { 0x3D06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x02,0x04,0x02,0x00,0x00,0x00,0x00}}, /* Sound Essence Compression */
419 // Index Table Segment
420 { 0x3F0B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x05,0x30,0x04,0x06,0x00,0x00,0x00,0x00}}, /* Index Edit Rate */
421 { 0x3F0C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x01,0x03,0x01,0x0A,0x00,0x00}}, /* Index Start Position */
422 { 0x3F0D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x07,0x02,0x02,0x01,0x01,0x02,0x00,0x00}}, /* Index Duration */
423 { 0x3F05, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x06,0x02,0x01,0x00,0x00,0x00,0x00}}, /* Edit Unit Byte Count */
424 { 0x3F06, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x01,0x03,0x04,0x05,0x00,0x00,0x00,0x00}}, /* IndexSID */
425 { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */
426 { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */
427 { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */
428 // MPEG video Descriptor
429 { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
430 { 0x8003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x05,0x00,0x00}}, /* LowDelay */
431 { 0x8004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x06,0x00,0x00}}, /* ClosedGOP */
432 { 0x8006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x08,0x00,0x00}}, /* MaxGOP */
433 { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
434 { 0x8008, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x09,0x00,0x00}}, /* BPictureCount */
435 // Wave Audio Essence Descriptor
436 { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
437 { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
438 // mxf_user_comments_local_tag
439 { 0x4406, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0C,0x00,0x00,0x00}}, /* User Comments */
440 { 0x5001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x09,0x01,0x00,0x00}}, /* Name */
441 { 0x5003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0A,0x01,0x00,0x00}}, /* Value */
442 // sub descriptor used AVC, JPEG2000 and FFV1
443 { 0x8100, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00}}, /* SubDescriptors */
444 // mxf_avc_subdescriptor_local_tags
445 { 0x8200, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0E,0x00,0x00}}, /* AVC Decoding Delay */
446 { 0x8201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0A,0x00,0x00}}, /* AVC Profile */
447 { 0x8202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x06,0x01,0x0D,0x00,0x00}}, /* AVC Level */
448 // ff_mxf_mastering_display_local_tags
453 // FFV1
454 { 0xDFD9, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x06,0x00,0x00,0x00}}, /* FFV1 Micro-version */
455 { 0xDFDA, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x05,0x00,0x00,0x00}}, /* FFV1 Version */
456 { 0xDFDB, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x01,0x00,0x00,0x00}}, /* FFV1 Initialization Metadata */
457 // ff_mxf_jpeg2000_local_tags
458 { 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 */
459 { 0x8402, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x02,0x00,0x00,0x00}}, /* Xsiz: Width of the reference grid */
460 { 0x8403, {0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x03,0x00,0x00,0x00}}, /* Ysiz: Height of the reference grid */
461 { 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 */
462 { 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 */
463 { 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 */
464 { 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 */
465 { 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 */
466 { 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 */
467 { 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 */
468 { 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. */
469 { 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. */
470};
471
472#define MXF_NUM_TAGS FF_ARRAY_ELEMS(mxf_local_tag_batch)
473
474typedef struct MXFContext {
482 uint64_t timestamp; ///< timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8)
486 int last_key_index; ///< index of last key frame
487 uint64_t duration;
488 AVTimecode tc; ///< timecode context
490 int timecode_base; ///< rounded time code base (25 or 30)
491 int edit_unit_byte_count; ///< fixed edit unit byte count
492 int content_package_rate; ///< content package rate in system element, see SMPTE 326M
493 uint64_t body_offset;
495 uint8_t umid[16]; ///< unique material identifier
501 int track_instance_count; // used to generate MXFTrack uuids
502 int cbr_index; ///< use a constant bitrate index
503 uint8_t unused_tags[MXF_NUM_TAGS]; ///< local tags that we know will not be used
505 PacketList anc_queue; ///< ANC packets not yet assigned to an edit unit
507 int64_t start_pts; ///< pts of the first displayed video frame
508} MXFContext;
509
511{
512 avio_write(pb, uuid_base, 10);
513 avio_wb16(pb, type);
514 avio_wb32(pb, value);
515}
516
518{
519 MXFContext *mxf = s->priv_data;
520 avio_write(s->pb, umid_ul, 13);
521 avio_wb24(s->pb, mxf->instance_number);
522 avio_write(s->pb, mxf->umid, 15);
523 avio_w8(s->pb, type);
524}
525
526static void mxf_write_refs_count(AVIOContext *pb, int ref_count)
527{
528 avio_wb32(pb, ref_count);
529 avio_wb32(pb, 16);
530}
531
532static int klv_ber_length(uint64_t len)
533{
534 if (len < 128)
535 return 1;
536 else
537 return (av_log2(len) >> 3) + 2;
538}
539
540static int klv_encode_ber_length(AVIOContext *pb, uint64_t len)
541{
542 // Determine the best BER size
543 int size = klv_ber_length(len);
544 if (size == 1) {
545 //short form
546 avio_w8(pb, len);
547 return 1;
548 }
549
550 size --;
551 // long form
552 avio_w8(pb, 0x80 + size);
553 while(size) {
554 size--;
555 avio_w8(pb, len >> 8 * size & 0xff);
556 }
557 return 0;
558}
559
561{
562 avio_w8(pb, 0x80 + 3);
563 avio_wb24(pb, len);
564}
565
566static void klv_encode_ber8_length(AVIOContext *pb, uint64_t len)
567{
568 avio_wb64(pb, (UINT64_C(0x87) << 56) | (len & UINT64_C(0x00FFFFFFFFFFFFFF)));
569}
570
571/*
572 * Get essence container ul index
573 */
575{
576 int i;
577 for (i = 0; mxf_essence_mappings[i].id; i++)
578 if (mxf_essence_mappings[i].id == id)
579 return mxf_essence_mappings[i].index;
580 return -1;
581}
582
584{
585 for (int i = 0; i < MXF_NUM_TAGS; i++) {
586 if (mxf_local_tag_batch[i].local_tag == tag) {
587 return &mxf_local_tag_batch[i];
588 }
589 }
590
591 // this assert can only be hit during development
592 av_assert0(0 && "you forgot to add your new tag to mxf_local_tag_batch");
593 return NULL;
594}
595
596static void mxf_mark_tag_unused(MXFContext *mxf, int tag)
597{
599 mxf->unused_tags[pair - mxf_local_tag_batch] = 1;
600}
601
603{
604 MXFContext *mxf = s->priv_data;
605 AVIOContext *pb = s->pb;
606 int local_tag_number = MXF_NUM_TAGS, i;
607 int will_have_avc_tags = 0, will_have_mastering_tags = 0, will_have_ffv1_tags = 0, will_have_jpeg2000_tags = 0;
608 int will_have_sub_descriptor = 0, will_have_rgba_descriptor = 0;
609
610 for (i = 0; i < s->nb_streams; i++) {
611 AVStream *st = s->streams[i];
612 MXFStreamContext *sc = st->priv_data;
614 will_have_avc_tags = 1;
615 }
619 will_have_mastering_tags = 1;
620 }
621 if (st->codecpar->codec_id == AV_CODEC_ID_FFV1) {
622 will_have_ffv1_tags = 1;
623 }
625 will_have_jpeg2000_tags = 1;
626 }
627 if (sc->sub_descriptor) {
628 will_have_sub_descriptor = 1;
629 }
631 will_have_rgba_descriptor = 1;
632 }
633 }
634
635 if (!mxf->store_user_comments) {
636 mxf_mark_tag_unused(mxf, 0x4406);
637 mxf_mark_tag_unused(mxf, 0x5001);
638 mxf_mark_tag_unused(mxf, 0x5003);
639 }
640
641 if (!will_have_sub_descriptor) {
642 mxf_mark_tag_unused(mxf, 0x8100);
643 }
644
645 if (!will_have_rgba_descriptor) {
646 mxf_mark_tag_unused(mxf, 0x3401);
647 mxf_mark_tag_unused(mxf, 0x3406);
648 mxf_mark_tag_unused(mxf, 0x3407);
649 }
650
651 if (!will_have_avc_tags) {
652 mxf_mark_tag_unused(mxf, 0x8200);
653 mxf_mark_tag_unused(mxf, 0x8201);
654 mxf_mark_tag_unused(mxf, 0x8202);
655 }
656
657 if (!will_have_mastering_tags) {
658 mxf_mark_tag_unused(mxf, 0x8301);
659 mxf_mark_tag_unused(mxf, 0x8302);
660 mxf_mark_tag_unused(mxf, 0x8303);
661 mxf_mark_tag_unused(mxf, 0x8304);
662 }
663
664 if (!will_have_ffv1_tags) {
665 mxf_mark_tag_unused(mxf, 0xDFD9);
666 mxf_mark_tag_unused(mxf, 0xDFDA);
667 mxf_mark_tag_unused(mxf, 0xDFDB);
668 }
669
670 if (!will_have_jpeg2000_tags) {
671 mxf_mark_tag_unused(mxf, 0x8401);
672 mxf_mark_tag_unused(mxf, 0x8402);
673 mxf_mark_tag_unused(mxf, 0x8403);
674 mxf_mark_tag_unused(mxf, 0x8404);
675 mxf_mark_tag_unused(mxf, 0x8405);
676 mxf_mark_tag_unused(mxf, 0x8406);
677 mxf_mark_tag_unused(mxf, 0x8407);
678 mxf_mark_tag_unused(mxf, 0x8408);
679 mxf_mark_tag_unused(mxf, 0x8409);
680 mxf_mark_tag_unused(mxf, 0x840A);
681 mxf_mark_tag_unused(mxf, 0x840B);
682 mxf_mark_tag_unused(mxf, 0x840C);
683 }
684
685 for (i = 0; i < MXF_NUM_TAGS; i++) {
686 if (mxf->unused_tags[i]) {
687 local_tag_number--;
688 }
689 }
690
692 klv_encode_ber_length(pb, local_tag_number * 18 + 8);
693
694 avio_wb32(pb, local_tag_number); // local_tag num
695 avio_wb32(pb, 18); // item size, always 18 according to the specs
696
697 for (i = 0; i < MXF_NUM_TAGS; i++) {
698 if (mxf->unused_tags[i] == 0) {
699 avio_wb16(pb, mxf_local_tag_batch[i].local_tag);
701 }
702 }
703}
704
706{
707 MXFContext *mxf = s->priv_data;
708 AVIOContext *pb = s->pb;
710
711 // make sure the tag was not declared unnecessary upfront
712 av_assert0(mxf->unused_tags[pair - mxf_local_tag_batch] == 0);
713
714 avio_wb16(pb, tag);
715 avio_wb16(pb, size);
716}
717
718static void mxf_write_metadata_key(AVIOContext *pb, unsigned int value)
719{
721 avio_wb24(pb, value);
722}
723
724static const MXFCodecUL *mxf_get_codec_ul_by_id(const MXFCodecUL *uls, int id)
725{
726 while (uls->uid[0]) {
727 if (id == uls->id)
728 break;
729 uls++;
730 }
731 return uls;
732}
733
734//one EC -> one descriptor. N ECs -> MultipleDescriptor + N descriptors
735#define DESCRIPTOR_COUNT(essence_container_count) \
736 (essence_container_count > 1 ? essence_container_count + 1 : essence_container_count)
737
739{
740 MXFContext *c = s->priv_data;
741 AVIOContext *pb = s->pb;
742 int i;
743
744 mxf_write_refs_count(pb, DESCRIPTOR_COUNT(c->essence_container_count));
745 av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count);
746 for (i = 0; i < s->nb_streams; i++) {
747 MXFStreamContext *sc = s->streams[i]->priv_data;
748 // check first track of essence container type and only write it once
749 if (sc->track_essence_element_key[15] != (sc->index == INDEX_S436M))
750 continue;
751 avio_write(pb, *sc->container_ul, 16);
752 if (c->essence_container_count == 1)
753 break;
754 }
755
756 if (c->essence_container_count > 1)
758}
759
761{
762 AVIOContext *pb = s->pb;
763
764 if (IS_OPATOM(s)) {
765 avio_write(pb, opatom_ul, 16);
766 } else {
767 avio_write(pb, op1a_ul, 14);
768 // qualifiers, ST 378 6.4: multi-track if more than one essence track
769 avio_w8(pb, s->nb_streams > 1 ? 0x09 : 0x01);
770 avio_w8(pb, op1a_ul[15]);
771 }
772}
773
775{
776 MXFContext *mxf = s->priv_data;
777 AVIOContext *pb = s->pb;
778
779 mxf_write_metadata_key(pb, 0x012f00);
780 PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
782
783 // write preface set uid
784 mxf_write_local_tag(s, 16, 0x3C0A);
785 mxf_write_uuid(pb, Preface, 0);
786 PRINT_KEY(s, "preface uid", pb->buf_ptr - 16);
787
788 // last modified date
789 mxf_write_local_tag(s, 8, 0x3B02);
790 avio_wb64(pb, mxf->timestamp);
791
792 // write version
793 mxf_write_local_tag(s, 2, 0x3B05);
794 avio_wb16(pb, 259); // v1.3
795
796 // Object Model Version
797 mxf_write_local_tag(s, 4, 0x3B07);
798 avio_wb32(pb, 1);
799
800 // write identification_refs
801 mxf_write_local_tag(s, 16 + 8, 0x3B06);
804
805 // write content_storage_refs
806 mxf_write_local_tag(s, 16, 0x3B03);
808
809 // operational pattern
810 mxf_write_local_tag(s, 16, 0x3B09);
812
813 // write essence_container_refs
816
817 // write dm_scheme_refs, empty batch of ULs
818 mxf_write_local_tag(s, 8, 0x3B0B);
820}
821
822/*
823 * Returns the length of the UTF-16 string, in 16-bit characters, that would result
824 * from decoding the utf-8 string.
825 */
826static uint64_t mxf_utf16len(const char *utf8_str)
827{
828 const uint8_t *q = utf8_str;
829 uint64_t size = 0;
830 while (*q) {
831 uint32_t ch;
832 GET_UTF8(ch, *q++, goto invalid;)
833 if (ch < 0x10000)
834 size++;
835 else
836 size += 2;
837 continue;
838invalid:
839 av_log(NULL, AV_LOG_ERROR, "Invalid UTF8 sequence in mxf_utf16len\n\n");
840 }
841 size += 1;
842 return size;
843}
844
845/*
846 * Returns the calculated length a local tag containing an utf-8 string as utf-16
847 */
848static int mxf_utf16_local_tag_length(const char *utf8_str)
849{
850 uint64_t size;
851
852 if (!utf8_str)
853 return 0;
854
855 size = mxf_utf16len(utf8_str);
856 if (size >= UINT16_MAX/2) {
857 av_log(NULL, AV_LOG_ERROR, "utf16 local tag size %"PRIx64" invalid (too large), ignoring\n", size);
858 return 0;
859 }
860
861 return 4 + size * 2;
862}
863
864/*
865 * Write a local tag containing an utf-8 string as utf-16
866 */
867static void mxf_write_local_tag_utf16(AVFormatContext *s, int tag, const char *value)
868{
869 AVIOContext *pb = s->pb;
870 uint64_t size = mxf_utf16len(value);
871
872 if (size >= UINT16_MAX/2) {
873 av_log(NULL, AV_LOG_ERROR, "utf16 local tag size %"PRIx64" invalid (too large), ignoring\n", size);
874 return;
875 }
876
879}
880
882 AVIOContext *pb = s->pb;
883
884 if (s->flags & AVFMT_FLAG_BITEXACT) {
885 avio_wb16(pb, 0); // major
886 avio_wb16(pb, 0); // minor
887 avio_wb16(pb, 0); // tertiary
888 } else {
891 avio_wb16(pb, LIBAVFORMAT_VERSION_MICRO); // tertiary
892 }
893 avio_wb16(pb, 0); // patch
894 avio_wb16(pb, 0); // release
895}
896
897#define PLATFORM_IDENT "Lavf " AV_STRINGIFY((OS_NAME))
899{
900 MXFContext *mxf = s->priv_data;
901 AVIOContext *pb = s->pb;
902 AVDictionaryEntry *com_entry = av_dict_get(s->metadata, "company_name", NULL, 0);
903 AVDictionaryEntry *product_entry = av_dict_get(s->metadata, "product_name", NULL, 0);
904 AVDictionaryEntry *version_entry = av_dict_get(s->metadata, "product_version", NULL, 0);
905 const char *company = com_entry ? com_entry->value : "FFmpeg";
906 const char *product = product_entry ? product_entry->value : !IS_OPATOM(s) ? "OP1a Muxer" : "OPAtom Muxer";
907 const char *platform = s->flags & AVFMT_FLAG_BITEXACT ? "Lavf" : PLATFORM_IDENT;
908 const char *version = version_entry ? version_entry->value :
909 s->flags & AVFMT_FLAG_BITEXACT ? "0.0.0" :
911 int length;
912
913 mxf_write_metadata_key(pb, 0x013000);
914 PRINT_KEY(s, "identification key", pb->buf_ptr - 16);
915
916 length = 100 +mxf_utf16_local_tag_length(company) +
920 klv_encode_ber_length(pb, length);
921
922 // write uid
923 mxf_write_local_tag(s, 16, 0x3C0A);
925 PRINT_KEY(s, "identification uid", pb->buf_ptr - 16);
926
927 // write generation uid
928 mxf_write_local_tag(s, 16, 0x3C09);
930 mxf_write_local_tag_utf16(s, 0x3C01, company); // Company Name
931 mxf_write_local_tag_utf16(s, 0x3C02, product); // Product Name
932
933 mxf_write_local_tag(s, 10, 0x3C03); // Product Version
935
936 mxf_write_local_tag_utf16(s, 0x3C04, version); // Version String
937 mxf_write_local_tag_utf16(s, 0x3C08, platform); // Platform
938
939 // write product uid
940 mxf_write_local_tag(s, 16, 0x3C05);
941 avio_write(pb, product_uid, 16);
942
943 // modification date
944 mxf_write_local_tag(s, 8, 0x3C06);
945 avio_wb64(pb, mxf->timestamp);
946
947 mxf_write_local_tag(s, 10, 0x3C07); // Toolkit Version
949}
950
951static void mxf_write_content_storage(AVFormatContext *s, MXFPackage *packages, int package_count)
952{
953 AVIOContext *pb = s->pb;
954 int i;
955
956 mxf_write_metadata_key(pb, 0x011800);
957 PRINT_KEY(s, "content storage key", pb->buf_ptr - 16);
958 klv_encode_ber_length(pb, 60 + (16 * package_count));
959
960 // write uid
961 mxf_write_local_tag(s, 16, 0x3C0A);
963 PRINT_KEY(s, "content storage uid", pb->buf_ptr - 16);
964
965 // write package reference
966 mxf_write_local_tag(s, 16 * package_count + 8, 0x1901);
967 mxf_write_refs_count(pb, package_count);
968 for (i = 0; i < package_count; i++) {
969 mxf_write_uuid(pb, packages[i].type, packages[i].instance);
970 }
971
972 // write essence container data
973 mxf_write_local_tag(s, 8 + 16, 0x1902);
976}
977
979{
980 MXFContext *mxf = s->priv_data;
981 AVIOContext *pb = s->pb;
982 MXFStreamContext *sc = st->priv_data;
983
984 mxf_write_metadata_key(pb, 0x013b00);
985 PRINT_KEY(s, "track key", pb->buf_ptr - 16);
986 klv_encode_ber_length(pb, 80);
987
988 // write track uid
989 mxf_write_local_tag(s, 16, 0x3C0A);
991 PRINT_KEY(s, "track uid", pb->buf_ptr - 16);
992
993 // write track id
994 mxf_write_local_tag(s, 4, 0x4801);
995 avio_wb32(pb, st->index+2);
996
997 // write track number
998 mxf_write_local_tag(s, 4, 0x4804);
999 if (package->type == MaterialPackage)
1000 avio_wb32(pb, 0); // track number of material package is 0
1001 else
1002 avio_write(pb, sc->track_essence_element_key + 12, 4);
1003
1004 // write edit rate
1005 mxf_write_local_tag(s, 8, 0x4B01);
1006
1007 if (st == mxf->timecode_track && IS_OPATOM(s)) {
1008 avio_wb32(pb, mxf->tc.rate.num);
1009 avio_wb32(pb, mxf->tc.rate.den);
1010 } else {
1011 avio_wb32(pb, mxf->time_base.den);
1012 avio_wb32(pb, mxf->time_base.num);
1013 }
1014
1015 // write origin
1016 mxf_write_local_tag(s, 8, 0x4B02);
1017 avio_wb64(pb, 0);
1018
1019 // write sequence refs
1020 mxf_write_local_tag(s, 16, 0x4803);
1022}
1023
1024static 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 };
1025
1027{
1028 MXFContext *mxf = s->priv_data;
1029 AVIOContext *pb = s->pb;
1030
1031 // find data define uls
1032 mxf_write_local_tag(s, 16, 0x0201);
1033 if (st == mxf->timecode_track)
1035 else {
1036 const MXFCodecUL* data_def_ul = mxf_get_codec_ul_by_id(
1039 avio_write(pb, data_def_ul->uid, 16);
1040 }
1041
1042 // write duration
1043 mxf_write_local_tag(s, 8, 0x0202);
1044
1045 if (st != mxf->timecode_track && IS_OPATOM(s) && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
1047 } else {
1048 avio_wb64(pb, mxf->duration);
1049 }
1050}
1051
1053{
1054 MXFContext *mxf = s->priv_data;
1055 AVIOContext *pb = s->pb;
1056 enum MXFMetadataSetType component;
1057
1058 mxf_write_metadata_key(pb, 0x010f00);
1059 PRINT_KEY(s, "sequence key", pb->buf_ptr - 16);
1060 klv_encode_ber_length(pb, 80);
1061
1062 mxf_write_local_tag(s, 16, 0x3C0A);
1064
1065 PRINT_KEY(s, "sequence uid", pb->buf_ptr - 16);
1067
1068 // write structural component
1069 mxf_write_local_tag(s, 16 + 8, 0x1001);
1070 mxf_write_refs_count(pb, 1);
1071 if (st == mxf->timecode_track)
1072 component = TimecodeComponent;
1073 else
1074 component = SourceClip;
1075
1076 mxf_write_uuid(pb, component, mxf->track_instance_count);
1077}
1078
1080{
1081 MXFContext *mxf = s->priv_data;
1082 AVIOContext *pb = s->pb;
1083
1084 mxf_write_metadata_key(pb, 0x011400);
1085 klv_encode_ber_length(pb, 75);
1086
1087 // UID
1088 mxf_write_local_tag(s, 16, 0x3C0A);
1090
1092
1093 // Start Time Code
1094 mxf_write_local_tag(s, 8, 0x1501);
1095 avio_wb64(pb, mxf->tc.start);
1096
1097 // Rounded Time Code Base
1098 mxf_write_local_tag(s, 2, 0x1502);
1099 avio_wb16(pb, mxf->timecode_base);
1100
1101 // Drop Frame
1102 mxf_write_local_tag(s, 1, 0x1503);
1104}
1105
1107{
1108 MXFContext *mxf = s->priv_data;
1109 AVIOContext *pb = s->pb;
1110
1111 mxf_write_metadata_key(pb, 0x011100);
1112 PRINT_KEY(s, "structural component key", pb->buf_ptr - 16);
1113 klv_encode_ber_length(pb, 108);
1114
1115 // write uid
1116 mxf_write_local_tag(s, 16, 0x3C0A);
1118
1119 PRINT_KEY(s, "structural component uid", pb->buf_ptr - 16);
1121
1122 // write start_position
1123 mxf_write_local_tag(s, 8, 0x1201);
1124 avio_wb64(pb, 0);
1125
1126 // write source package uid, end of the reference
1127 mxf_write_local_tag(s, 32, 0x1101);
1128 if (!package->ref) {
1129 ffio_fill(pb, 0, 32);
1130 } else
1131 mxf_write_umid(s, package->ref->instance);
1132
1133 // write source track id
1134 mxf_write_local_tag(s, 4, 0x1102);
1135 if (package->type == SourcePackage && !package->ref)
1136 avio_wb32(pb, 0);
1137 else
1138 avio_wb32(pb, st->index+2);
1139}
1140
1142{
1143 AVIOContext *pb = s->pb;
1144
1145 mxf_write_metadata_key(pb, 0x012e00);
1146 PRINT_KEY(s, "tape descriptor key", pb->buf_ptr - 16);
1147 klv_encode_ber_length(pb, 20);
1148 mxf_write_local_tag(s, 16, 0x3C0A);
1150 PRINT_KEY(s, "tape_desc uid", pb->buf_ptr - 16);
1151}
1152
1153
1155{
1156 MXFContext *mxf = s->priv_data;
1157 AVIOContext *pb = s->pb;
1158 const uint8_t *ul;
1159 int i;
1160
1161 mxf_write_metadata_key(pb, 0x014400);
1162 PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16);
1163 klv_encode_ber_length(pb, 64 + 16LL * s->nb_streams);
1164
1165 mxf_write_local_tag(s, 16, 0x3C0A);
1167 PRINT_KEY(s, "multi_desc uid", pb->buf_ptr - 16);
1168
1169 // write sample rate
1170 mxf_write_local_tag(s, 8, 0x3001);
1171 avio_wb32(pb, mxf->time_base.den);
1172 avio_wb32(pb, mxf->time_base.num);
1173
1174 // write essence container ul
1175 mxf_write_local_tag(s, 16, 0x3004);
1176 if (mxf->essence_container_count > 1)
1177 ul = multiple_desc_ul;
1178 else {
1179 MXFStreamContext *sc = s->streams[0]->priv_data;
1180 ul = *sc->container_ul;
1181 }
1182 avio_write(pb, ul, 16);
1183
1184 // write sub descriptor refs
1185 mxf_write_local_tag(s, s->nb_streams * 16 + 8, 0x3F01);
1186 mxf_write_refs_count(pb, s->nb_streams);
1187 for (i = 0; i < s->nb_streams; i++)
1189}
1190
1192{
1193 MXFContext *mxf = s->priv_data;
1194 MXFStreamContext *sc = st->priv_data;
1195 AVIOContext *pb = s->pb;
1196 int64_t pos;
1197
1198 avio_write(pb, key, 16);
1200 pos = avio_tell(pb);
1201
1202 mxf_write_local_tag(s, 16, 0x3C0A);
1204
1205 mxf_write_local_tag(s, 4, 0x3006);
1206 avio_wb32(pb, st->index+2);
1207
1208 mxf_write_local_tag(s, 8, 0x3001);
1209 if (IS_D10(s)) {
1210 avio_wb32(pb, mxf->time_base.den);
1211 avio_wb32(pb, mxf->time_base.num);
1212 } else {
1215 avio_wb32(pb, st->codecpar->sample_rate);
1216 avio_wb32(pb, 1);
1217 } else {
1218 avio_wb32(pb, mxf->time_base.den);
1219 avio_wb32(pb, mxf->time_base.num);
1220 }
1221 }
1222
1223 mxf_write_local_tag(s, 16, 0x3004);
1224 avio_write(pb, *sc->container_ul, 16);
1225
1226 return pos;
1227}
1228
1229static const UID mxf_s436m_anc_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 };
1230static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
1231static const UID mxf_wav_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 };
1232static const UID mxf_aes3_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 };
1233static const UID mxf_cdci_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x28,0x00 };
1234static const UID mxf_generic_sound_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x42,0x00 };
1235
1236static const UID mxf_avc_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x6E,0x00 };
1237static const UID mxf_ffv1_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x81,0x03 };
1238static const UID mxf_jpeg2000_subdescriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x5A,0x00};
1239
1240static inline uint16_t rescale_mastering_chroma(AVRational q)
1241{
1243}
1244
1245static inline uint32_t rescale_mastering_luma(AVRational q)
1246{
1248}
1249
1250static const char *color_name(const char *name)
1251{
1252 return name ? name : "reserved";
1253}
1254
1256{
1257 MXFStreamContext *sc = st->priv_data;
1258 AVIOContext *pb = s->pb;
1259 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
1260 int stored_width = st->codecpar->width;
1261 int stored_height = st->codecpar->height;
1262 int display_width;
1263 int display_height;
1264 int f1, f2;
1265 const MXFCodecUL *color_primaries_ul;
1266 const MXFCodecUL *color_trc_ul;
1267 const MXFCodecUL *color_space_ul;
1269 const AVPacketSideData *side_data;
1270 int component_depth = pix_desc->comp[0].depth;
1271
1272 /* the essence bitstream takes precedence where it describes the color */
1276 sc->color_trc = st->codecpar->color_trc;
1278 sc->color_space = st->codecpar->color_space;
1280 sc->color_range = st->codecpar->color_range;
1281
1285
1286 if (!sc->color_warned) {
1287 if (!color_primaries_ul->uid[0] && sc->color_primaries != AVCOL_PRI_UNSPECIFIED)
1288 av_log(s, AV_LOG_WARNING, "Color primaries %s have no MXF label, not writing them\n",
1290 if (!color_trc_ul->uid[0] && sc->color_trc != AVCOL_TRC_UNSPECIFIED)
1291 av_log(s, AV_LOG_WARNING, "Color transfer %s has no MXF label, not writing it\n",
1293 if (!color_space_ul->uid[0] && sc->color_space != AVCOL_SPC_UNSPECIFIED)
1294 av_log(s, AV_LOG_WARNING, "Color matrix %s has no MXF label, not writing it\n",
1296 sc->color_warned = 1;
1297 }
1298
1300 if (st->codecpar->height == 1080)
1301 stored_width = 1920;
1302 else if (st->codecpar->height == 720)
1303 stored_width = 1280;
1304 }
1305 display_width = stored_width;
1306
1307 switch (st->codecpar->codec_id) {
1308 case AV_CODEC_ID_DNXHD:
1309 if (sc->cid < 1270) // DNxHD
1310 break;
1311 // fall for DNxHR RI rasters
1314 case AV_CODEC_ID_H264:
1315 //Based on 16x16 macroblocks
1316 stored_width = (stored_width+15)/16*16;
1317 stored_height = (stored_height+15)/16*16;
1318 break;
1319 default:
1320 break;
1321 }
1322
1323 //Stored width
1324 mxf_write_local_tag(s, 4, 0x3203);
1325 avio_wb32(pb, stored_width);
1326
1327 //Stored height
1328 mxf_write_local_tag(s, 4, 0x3202);
1329 avio_wb32(pb, stored_height>>sc->interlaced);
1330
1331 if (IS_D10(s)) {
1332 //Stored F2 Offset
1333 mxf_write_local_tag(s, 4, 0x3216);
1334 avio_wb32(pb, 0);
1335
1336 //Image Start Offset
1337 mxf_write_local_tag(s, 4, 0x3213);
1338 avio_wb32(pb, 0);
1339
1340 //Image End Offset
1341 mxf_write_local_tag(s, 4, 0x3214);
1342 avio_wb32(pb, 0);
1343 }
1344
1345 //Sampled width
1346 mxf_write_local_tag(s, 4, 0x3205);
1347 avio_wb32(pb, display_width);
1348
1349 //Samples height
1350 mxf_write_local_tag(s, 4, 0x3204);
1351 avio_wb32(pb, st->codecpar->height>>sc->interlaced);
1352
1353 //Sampled X Offset
1354 mxf_write_local_tag(s, 4, 0x3206);
1355 avio_wb32(pb, 0);
1356
1357 //Sampled Y Offset
1358 mxf_write_local_tag(s, 4, 0x3207);
1359 avio_wb32(pb, 0);
1360
1361 //Display width
1362 mxf_write_local_tag(s, 4, 0x3209);
1363 avio_wb32(pb, display_width);
1364
1365 if (st->codecpar->height == 608) // PAL + VBI
1366 display_height = 576;
1367 else if (st->codecpar->height == 512) // NTSC + VBI
1368 display_height = 486;
1369 else
1370 display_height = st->codecpar->height;
1371
1372 //Display height
1373 mxf_write_local_tag(s, 4, 0x3208);
1374 avio_wb32(pb, display_height>>sc->interlaced);
1375
1376 // display X offset
1377 mxf_write_local_tag(s, 4, 0x320A);
1378 avio_wb32(pb, 0);
1379
1380 // display Y offset
1381 mxf_write_local_tag(s, 4, 0x320B);
1382 avio_wb32(pb, (st->codecpar->height - display_height)>>sc->interlaced);
1383
1384 if (sc->interlaced) {
1385 //Display F2 Offset
1386 mxf_write_local_tag(s, 4, 0x3217);
1388 }
1389
1391 uint8_t rgb_layout[16] = {
1392 'R', component_depth,
1393 'G', component_depth,
1394 'B', component_depth,
1395 };
1396 // pixel layout
1397 mxf_write_local_tag(s, 16, 0x3401);
1398 avio_write(pb, rgb_layout, 16);
1399
1400 /* unknown DNxHD range is not assumed to be full range */
1401 if (!(pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) &&
1404 uint32_t max_ref = (UINT64_C(1) << component_depth) - 1;
1405 uint32_t min_ref = 0;
1406
1407 if (sc->color_range == AVCOL_RANGE_MPEG) {
1408 max_ref = 235U << (component_depth - 8);
1409 min_ref = 16U << (component_depth - 8);
1410 }
1411 mxf_write_local_tag(s, 4, 0x3406);
1412 avio_wb32(pb, max_ref);
1413 mxf_write_local_tag(s, 4, 0x3407);
1414 avio_wb32(pb, min_ref);
1415 }
1416 } else {
1417 int h_chroma_sub_sample = 1 << pix_desc->log2_chroma_w;
1418 int v_chroma_sub_sample = 1 << pix_desc->log2_chroma_h;
1419 int color_siting;
1420
1421 // component depth
1422 mxf_write_local_tag(s, 4, 0x3301);
1423 avio_wb32(pb, component_depth);
1424
1425 // horizontal subsampling
1426 mxf_write_local_tag(s, 4, 0x3302);
1427 avio_wb32(pb, h_chroma_sub_sample);
1428
1429 // vertical subsampling
1430 mxf_write_local_tag(s, 4, 0x3308);
1431 avio_wb32(pb, v_chroma_sub_sample);
1432
1433 switch (choose_chroma_location(s, st)) {
1434 case AVCHROMA_LOC_TOPLEFT: color_siting = 0; break;
1435 case AVCHROMA_LOC_LEFT: color_siting = 6; break;
1436 case AVCHROMA_LOC_TOP: color_siting = 1; break;
1437 case AVCHROMA_LOC_CENTER: color_siting = 3; break;
1438 default: color_siting = 0xff;
1439 }
1440
1441 if (IS_D10(s))
1442 color_siting = 0; // color siting is specified to be 0 in d-10 specs
1443
1444 // color siting
1445 mxf_write_local_tag(s, 1, 0x3303);
1446 avio_w8(pb, color_siting);
1447
1448 // Padding Bits
1449 mxf_write_local_tag(s, 2, 0x3307);
1450 avio_wb16(pb, 0);
1451
1453 int black = 0,
1454 white = (1<<component_depth) - 1,
1455 color = (1<<component_depth);
1456 if (sc->color_range == AVCOL_RANGE_MPEG) {
1457 black = 1 << (component_depth - 4);
1458 white = 235 << (component_depth - 8);
1459 color = (14 << (component_depth - 4)) + 1;
1460 }
1461 mxf_write_local_tag(s, 4, 0x3304);
1462 avio_wb32(pb, black);
1463 mxf_write_local_tag(s, 4, 0x3305);
1464 avio_wb32(pb, white);
1465 mxf_write_local_tag(s, 4, 0x3306);
1466 avio_wb32(pb, color);
1467 }
1468 }
1469
1470 if (sc->signal_standard) {
1471 mxf_write_local_tag(s, 1, 0x3215);
1472 avio_w8(pb, sc->signal_standard);
1473 }
1474
1475 // frame layout
1476 mxf_write_local_tag(s, 1, 0x320C);
1477 avio_w8(pb, sc->interlaced);
1478
1479 // video line map
1480 switch (st->codecpar->height) {
1481 case 576: f1 = 23; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 335 : 336; break;
1482 case 608: f1 = 7; f2 = 320; break;
1483 case 480: f1 = 20; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 285 : 283; break;
1484 case 512: f1 = 7; f2 = 270; break;
1485 case 720: f1 = 26; f2 = 0; break; // progressive
1486 case 1080: f1 = 21; f2 = 584; break;
1487 default: f1 = 0; f2 = 0; break;
1488 }
1489
1490 if (!sc->interlaced && f2) {
1491 f2 = 0;
1492 f1 *= 2;
1493 }
1494
1495 mxf_write_local_tag(s, 16, 0x320D);
1496 avio_wb32(pb, 2);
1497 avio_wb32(pb, 4);
1498 avio_wb32(pb, f1);
1499 avio_wb32(pb, f2);
1500
1501 mxf_write_local_tag(s, 8, 0x320E);
1502 avio_wb32(pb, sc->aspect_ratio.num);
1503 avio_wb32(pb, sc->aspect_ratio.den);
1504
1505 if (color_primaries_ul->uid[0]) {
1506 mxf_write_local_tag(s, 16, 0x3219);
1507 avio_write(pb, color_primaries_ul->uid, 16);
1508 };
1509
1510 if (color_trc_ul->uid[0]) {
1511 mxf_write_local_tag(s, 16, 0x3210);
1512 avio_write(pb, color_trc_ul->uid, 16);
1513 };
1514
1515 if (color_space_ul->uid[0]) {
1516 mxf_write_local_tag(s, 16, 0x321A);
1517 avio_write(pb, color_space_ul->uid, 16);
1518 };
1519
1520 mxf_write_local_tag(s, 16, 0x3201);
1521 avio_write(pb, *sc->codec_ul, 16);
1522
1523 // Mastering Display metadata
1527 if (side_data) {
1529 if (metadata->has_primaries) {
1530 mxf_write_local_tag(s, 12, 0x8301);
1531 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[0][0]));
1532 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[0][1]));
1533 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[1][0]));
1534 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[1][1]));
1535 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[2][0]));
1536 avio_wb16(pb, rescale_mastering_chroma(metadata->display_primaries[2][1]));
1537 mxf_write_local_tag(s, 4, 0x8302);
1538 avio_wb16(pb, rescale_mastering_chroma(metadata->white_point[0]));
1539 avio_wb16(pb, rescale_mastering_chroma(metadata->white_point[1]));
1540 } else {
1541 av_log(NULL, AV_LOG_VERBOSE, "Not writing mastering display primaries. Missing data.\n");
1542 }
1543 if (metadata->has_luminance) {
1544 mxf_write_local_tag(s, 4, 0x8303);
1545 avio_wb32(pb, rescale_mastering_luma(metadata->max_luminance));
1546 mxf_write_local_tag(s, 4, 0x8304);
1547 avio_wb32(pb, rescale_mastering_luma(metadata->min_luminance));
1548 } else {
1549 av_log(NULL, AV_LOG_VERBOSE, "Not writing mastering display luminances. Missing data.\n");
1550 }
1551 }
1552
1553 if (sc->interlaced && sc->field_dominance) {
1554 mxf_write_local_tag(s, 1, 0x3212);
1555 avio_w8(pb, sc->field_dominance);
1556 }
1557
1558 if (sc->sub_descriptor) {
1559 mxf_write_local_tag(s, 8 + 16, 0x8100);
1560 mxf_write_refs_count(pb, 1);
1561 mxf_write_uuid(pb, sc->sub_descriptor, 0);
1562 }
1563
1566
1567 return pos;
1568}
1569
1571{
1572 int64_t cur_pos = avio_tell(pb);
1573 int size = cur_pos - pos;
1574 avio_seek(pb, pos - 4, SEEK_SET);
1576 avio_seek(pb, cur_pos, SEEK_SET);
1577}
1578
1580{
1581 AVIOContext *pb = s->pb;
1582 int64_t pos;
1583
1586 pos = avio_tell(pb);
1587
1588 mxf_write_local_tag(s, 16, 0x3C0A);
1590
1591 mxf_write_local_tag(s, 1, 0x8200);
1592 avio_w8(pb, 0xFF); // AVC Decoding Delay, unknown
1593
1594 mxf_write_local_tag(s, 1, 0x8201);
1595 avio_w8(pb, st->codecpar->profile); // AVC Profile
1596
1597 mxf_write_local_tag(s, 1, 0x8202);
1598 avio_w8(pb, st->codecpar->level); // AVC Level
1599
1601}
1602
1604{
1605 MXFStreamContext *sc = st->priv_data;
1606 AVIOContext *pb = s->pb;
1607 int64_t pos;
1608 unsigned int ncomponents = sc->j2k_info.j2k_csiz;
1609
1610 /* JPEG2000 subdescriptor key */
1613 pos = avio_tell(pb);
1614
1615 mxf_write_local_tag(s, 16, 0x3C0A);
1617
1618 /* Value defining the decoder capabilities (rsiz) */
1619 mxf_write_local_tag(s, 2, 0x8401);
1620 avio_wb16(pb, sc->j2k_info.j2k_rsiz);
1621 /* Width of the JPEG2000 reference grid (Xsiz) */
1622 mxf_write_local_tag(s, 4, 0x8402);
1623 avio_wb32(pb, sc->j2k_info.j2k_xsiz);
1624 /* Height of the JPEG2000 reference grid (Ysiz) */
1625 mxf_write_local_tag(s, 4, 0x8403);
1626 avio_wb32(pb, sc->j2k_info.j2k_ysiz);
1627 /* Horizontal offset from the reference grid origin to the left side of the image area (X0siz) */
1628 mxf_write_local_tag(s, 4, 0x8404);
1629 avio_wb32(pb, sc->j2k_info.j2k_x0siz);
1630 /* Vertical offset from the reference grid origin to the left side of the image area (Y0siz) */
1631 mxf_write_local_tag(s, 4, 0x8405);
1632 avio_wb32(pb, sc->j2k_info.j2k_y0siz);
1633 /* Width of one reference tile with respect to the reference grid (XTsiz) */
1634 mxf_write_local_tag(s, 4, 0x8406);
1635 avio_wb32(pb, sc->j2k_info.j2k_xtsiz);
1636 /* Height of one reference tile with respect to the reference grid (YTsiz) */
1637 mxf_write_local_tag(s, 4, 0x8407);
1638 avio_wb32(pb, sc->j2k_info.j2k_ytsiz);
1639 /* Horizontal offset from the origin of the reference grid to the left side of the first tile (XT0siz) */
1640 mxf_write_local_tag(s, 4, 0x8408);
1641 avio_wb32(pb, sc->j2k_info.j2k_xt0siz);
1642 /* Vertical offset from the origin of the reference grid to the left side of the first tile (YT0siz) */
1643 mxf_write_local_tag(s, 4, 0x8409);
1644 avio_wb32(pb, sc->j2k_info.j2k_yt0siz);
1645 /* Image components number (Csiz) */
1646 mxf_write_local_tag(s, 2, 0x840A);
1647 avio_wb16(pb, ncomponents);
1648 /* Array of picture components where each component comprises 3 bytes named Ssiz(i) (Pixel bitdepth - 1),
1649 XRSiz(i) (Horizontal sampling), YRSiz(i) (Vertical sampling). The array of 3-byte groups is preceded
1650 by the array header comprising a 4-byte value of the number of components followed by a 4-byte
1651 value of 3. */
1652 mxf_write_local_tag(s, 8 + 3 * ncomponents, 0x840B);
1653 avio_wb32(pb, ncomponents);
1654 avio_wb32(pb, 3);
1655 avio_write(pb, sc->j2k_info.j2k_comp_desc, 3 * ncomponents);
1656
1658 return 0;
1659}
1660
1662{
1663 MXFStreamContext *sc = st->priv_data;
1666
1667 switch (sc->sub_descriptor) {
1668 case AVCSubDescriptor: mxf_write_avc_subdesc(s, st); break;
1670 case FFV1SubDescriptor: mxf_write_ffv1_subdesc(s, st); break;
1671 }
1672
1673 return 0;
1674}
1675
1677{
1678 AVIOContext *pb = s->pb;
1679 MXFStreamContext *sc = st->priv_data;
1680 int64_t pos;
1681
1684 pos = avio_tell(pb);
1685
1686 mxf_write_local_tag(s, 16, 0x3C0A);
1688
1689 if (st->codecpar->extradata_size) {
1691 avio_write(pb, st->codecpar->extradata, st->codecpar->extradata_size); // FFV1InitializationMetadata
1692 }
1693
1694 mxf_write_local_tag(s, 2, 0xDFDA);
1695 avio_wb16(pb, sc->version); // FFV1Version
1696
1697 if (st->codecpar->extradata_size) {
1698 mxf_write_local_tag(s, 2, 0xDFD9);
1699 avio_wb16(pb, sc->micro_version); // FFV1MicroVersion
1700 }
1701
1703}
1704
1711
1713{
1714 AVIOContext *pb = s->pb;
1715 MXFStreamContext *sc = st->priv_data;
1716 int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level;
1717
1718 // bit rate
1719 mxf_write_local_tag(s, 4, 0x8000);
1720 avio_wb32(pb, sc->video_bit_rate);
1721
1722 // profile and level
1723 mxf_write_local_tag(s, 1, 0x8007);
1724 if (!st->codecpar->profile)
1725 profile_and_level |= 0x80; // escape bit
1726 avio_w8(pb, profile_and_level);
1727
1728 // low delay
1729 mxf_write_local_tag(s, 1, 0x8003);
1730 avio_w8(pb, sc->low_delay);
1731
1732 // closed gop
1733 mxf_write_local_tag(s, 1, 0x8004);
1734 avio_w8(pb, sc->seq_closed_gop);
1735
1736 // max gop
1737 mxf_write_local_tag(s, 2, 0x8006);
1738 avio_wb16(pb, sc->max_gop);
1739
1740 // b picture count
1741 mxf_write_local_tag(s, 2, 0x8008);
1742 avio_wb16(pb, sc->b_picture_count);
1743
1744 return 0;
1745}
1746
1748{
1749 AVIOContext *pb = s->pb;
1750 MXFContext *mxf = s->priv_data;
1751 int show_warnings = !mxf->footer_partition_offset;
1753
1754 if (IS_OPATOM(s)) {
1755 mxf_write_local_tag(s, 8, 0x3002);
1757 }
1758
1759 // audio locked
1760 mxf_write_local_tag(s, 1, 0x3D02);
1761 avio_w8(pb, 1);
1762
1763 // write audio sampling rate
1764 mxf_write_local_tag(s, 8, 0x3D03);
1765 avio_wb32(pb, st->codecpar->sample_rate);
1766 avio_wb32(pb, 1);
1767
1768 if (IS_D10(s)) {
1769 mxf_write_local_tag(s, 1, 0x3D04);
1770 avio_w8(pb, 0);
1771 }
1772
1773 mxf_write_local_tag(s, 4, 0x3D07);
1774 if (mxf->channel_count == -1) {
1775 if (show_warnings && IS_D10(s) &&
1776 (st->codecpar->ch_layout.nb_channels != 4) &&
1777 (st->codecpar->ch_layout.nb_channels != 8))
1778 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");
1780 } else if (IS_D10(s)) {
1781 if (show_warnings && (mxf->channel_count < st->codecpar->ch_layout.nb_channels))
1782 av_log(s, AV_LOG_WARNING, "d10_channelcount < actual number of audio channels : some channels will be discarded\n");
1783 if (show_warnings && (mxf->channel_count != 4) && (mxf->channel_count != 8))
1784 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");
1785 avio_wb32(pb, mxf->channel_count);
1786 } else {
1788 }
1789
1790 mxf_write_local_tag(s, 4, 0x3D01);
1792
1793 return pos;
1794}
1795
1797{
1798 AVIOContext *pb = s->pb;
1800
1801 mxf_write_local_tag(s, 2, 0x3D0A);
1802 avio_wb16(pb, st->codecpar->block_align);
1803
1804 // avg bytes per sec
1805 mxf_write_local_tag(s, 4, 0x3D09);
1807
1808 return pos;
1809}
1810
1812{
1815 return 0;
1816}
1817
1824
1831
1832static const uint8_t mxf_indirect_value_utf16le[] = { 0x4c,0x00,0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 };
1833
1834static int mxf_write_tagged_value(AVFormatContext *s, const char* name, const char* value)
1835{
1836 MXFContext *mxf = s->priv_data;
1837 AVIOContext *pb = s->pb;
1838 int name_size = mxf_utf16_local_tag_length(name);
1839 int indirect_value_size = 13 + mxf_utf16_local_tag_length(value);
1840
1841 if (!name_size || indirect_value_size == 13)
1842 return 1;
1843
1844 mxf_write_metadata_key(pb, 0x013f00);
1845 klv_encode_ber_length(pb, 24 + name_size + indirect_value_size);
1846
1847 // write instance UID
1848 mxf_write_local_tag(s, 16, 0x3C0A);
1850
1851 // write name
1852 mxf_write_local_tag_utf16(s, 0x5001, name); // Name
1853
1854 // write indirect value
1855 mxf_write_local_tag(s, indirect_value_size, 0x5003);
1858
1859 mxf->tagged_value_count++;
1860 return 0;
1861}
1862
1864{
1865 MXFContext *mxf = s->priv_data;
1867 int count = 0;
1868
1869 while ((t = av_dict_get(m, "comment_", t, AV_DICT_IGNORE_SUFFIX))) {
1870 if (mxf->tagged_value_count >= UINT16_MAX) {
1871 av_log(s, AV_LOG_ERROR, "too many tagged values, ignoring remaining\n");
1872 return count;
1873 }
1874
1875 if (mxf_write_tagged_value(s, t->key + 8, t->value) == 0)
1876 count++;
1877 }
1878 return count;
1879}
1880
1882{
1883 MXFContext *mxf = s->priv_data;
1884 AVIOContext *pb = s->pb;
1885 int i, track_count = s->nb_streams+1;
1886 int name_size = mxf_utf16_local_tag_length(package->name);
1887 int user_comment_count = 0;
1888
1889 if (package->type == MaterialPackage) {
1890 if (mxf->store_user_comments)
1891 user_comment_count = mxf_write_user_comments(s, s->metadata);
1892 mxf_write_metadata_key(pb, 0x013600);
1893 PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
1894 klv_encode_ber_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12LL*mxf->store_user_comments);
1895 } else {
1896 mxf_write_metadata_key(pb, 0x013700);
1897 PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
1898 klv_encode_ber_length(pb, 112 + name_size + (16*track_count) + 12LL*mxf->store_user_comments); // 20 bytes length for descriptor reference
1899 }
1900
1901 // write uid
1902 mxf_write_local_tag(s, 16, 0x3C0A);
1903 mxf_write_uuid(pb, package->type, package->instance);
1904 av_log(s, AV_LOG_DEBUG, "package type:%d\n", package->type);
1905 PRINT_KEY(s, "package uid", pb->buf_ptr - 16);
1906
1907 // write package umid
1908 mxf_write_local_tag(s, 32, 0x4401);
1909 mxf_write_umid(s, package->instance);
1910 PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16);
1911
1912 // package name
1913 if (name_size)
1914 mxf_write_local_tag_utf16(s, 0x4402, package->name);
1915
1916 // package creation date
1917 mxf_write_local_tag(s, 8, 0x4405);
1918 avio_wb64(pb, mxf->timestamp);
1919
1920 // package modified date
1921 mxf_write_local_tag(s, 8, 0x4404);
1922 avio_wb64(pb, mxf->timestamp);
1923
1924 // write track refs
1925 mxf_write_local_tag(s, track_count*16 + 8, 0x4403);
1926 mxf_write_refs_count(pb, track_count);
1927 // these are the uuids of the tracks the will be written in mxf_write_track
1928 for (i = 0; i < track_count; i++)
1930
1931 // write user comment refs
1932 if (mxf->store_user_comments) {
1933 mxf_write_local_tag(s, user_comment_count*16 + 8, 0x4406);
1934 mxf_write_refs_count(pb, user_comment_count);
1935 for (i = 0; i < user_comment_count; i++)
1936 mxf_write_uuid(pb, TaggedValue, mxf->tagged_value_count - user_comment_count + i);
1937 }
1938
1939 // write multiple descriptor reference
1940 if (package->type == SourcePackage && package->instance == 1) {
1941 mxf_write_local_tag(s, 16, 0x4701);
1942 if (s->nb_streams > 1) {
1945 } else
1947 } else if (package->type == SourcePackage && package->instance == 2) {
1948 mxf_write_local_tag(s, 16, 0x4701);
1951 }
1952
1953 /*
1954 * for every 1 track in a package there is 1 sequence and 1 component.
1955 * all 3 of these elements share the same instance number for generating
1956 * there instance uuids. mxf->track_instance_count stores this value.
1957 * mxf->track_instance_count is incremented after a group of all 3 of
1958 * these elements are written.
1959 */
1960
1961 // write timecode track
1962 mxf_write_track(s, mxf->timecode_track, package);
1963 mxf_write_sequence(s, mxf->timecode_track, package);
1965 mxf->track_instance_count++;
1966
1967 for (i = 0; i < s->nb_streams; i++) {
1968 AVStream *st = s->streams[i];
1969 mxf_write_track(s, st, package);
1970 mxf_write_sequence(s, st, package);
1971 mxf_write_structural_component(s, st, package);
1972 mxf->track_instance_count++;
1973
1974 if (package->type == SourcePackage && package->instance == 1) {
1975 MXFStreamContext *sc = st->priv_data;
1976 int ret = mxf_essence_container_uls[sc->index].write_desc(s, st);
1977 if (ret < 0)
1978 return ret;
1979 }
1980 }
1981
1982 return 0;
1983}
1984
1986{
1987 AVIOContext *pb = s->pb;
1988
1989 mxf_write_metadata_key(pb, 0x012300);
1990 klv_encode_ber_length(pb, 72);
1991
1992 mxf_write_local_tag(s, 16, 0x3C0A); // Instance UID
1994
1995 mxf_write_local_tag(s, 32, 0x2701); // Linked Package UID
1996 mxf_write_umid(s, 1);
1997
1998 mxf_write_local_tag(s, 4, 0x3F07); // BodySID
1999 avio_wb32(pb, 1);
2000
2001 mxf_write_local_tag(s, 4, 0x3F06); // IndexSID
2002 avio_wb32(pb, 2);
2003
2004 return 0;
2005}
2006
2008{
2009 MXFContext *mxf = s->priv_data;
2011 AVStream *st = NULL;
2012 int i;
2013 MXFPackage packages[3] = {{0}};
2014 int package_count = 2;
2015 packages[0].type = MaterialPackage;
2016 packages[1].type = SourcePackage;
2017 packages[1].instance = 1;
2018 packages[0].ref = &packages[1];
2019
2020
2021 if (entry = av_dict_get(s->metadata, "material_package_name", NULL, 0))
2022 packages[0].name = entry->value;
2023
2024 if (entry = av_dict_get(s->metadata, "file_package_name", NULL, 0)) {
2025 packages[1].name = entry->value;
2026 } else {
2027 /* check if any of the streams contain a file_package_name */
2028 for (i = 0; i < s->nb_streams; i++) {
2029 st = s->streams[i];
2030 if (entry = av_dict_get(st->metadata, "file_package_name", NULL, 0)) {
2031 packages[1].name = entry->value;
2032 break;
2033 }
2034 }
2035 }
2036
2037 entry = av_dict_get(s->metadata, "reel_name", NULL, 0);
2038 if (entry) {
2039 packages[2].name = entry->value;
2040 packages[2].type = SourcePackage;
2041 packages[2].instance = 2;
2042 packages[1].ref = &packages[2];
2043 package_count = 3;
2044 }
2045
2048 mxf_write_content_storage(s, packages, package_count);
2049 mxf->track_instance_count = 0;
2050 for (i = 0; i < package_count; i++) {
2051 int ret = mxf_write_package(s, &packages[i]);
2052 if (ret < 0)
2053 return ret;
2054 }
2056 return 0;
2057}
2058
2059static unsigned klv_fill_size(uint64_t size)
2060{
2061 unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
2062 if (pad < 20) // smallest fill item possible
2063 return pad + KAG_SIZE;
2064 else
2065 return pad & (KAG_SIZE-1);
2066}
2067
2068// KAG-aligned size including the 16-byte key and 4-byte BER length,
2069// and the fill KLV that always follows, ST 379-2 8.3.
2070static unsigned mxf_element_size(unsigned payload)
2071{
2072 return FFALIGN(16 + 4 + payload + 16 + 4, KAG_SIZE);
2073}
2074
2075/**
2076 * Number of slices minus 1. Elements following the VBE picture are in slice 1,
2077 * there should be no slices if the picture is the last element, ST 377-1 11.1.4.
2078 */
2080{
2081 MXFContext *mxf = s->priv_data;
2082 return !mxf->edit_unit_byte_count && s->nb_streams > 1;
2083}
2084
2086{
2087 return 11 + 4 * mxf_index_slice_count(s);
2088}
2089
2090// largest IndexEntryArray fitting a 2 byte local set length
2092{
2093 return (UINT16_MAX - 8) / mxf_index_entry_size(s);
2094}
2095
2097{
2098 // one delta entry per element, plus the system item except in OPAtom
2099 return s->nb_streams + !IS_OPATOM(s);
2100}
2101
2103{
2104 if (offset >= INT8_MIN && offset <= INT8_MAX)
2105 return 0;
2106
2107 av_log(s, AV_LOG_ERROR, "Current implementation requires frame offset (%d) "
2108 "to be within the range of [%d,%d]. Please reduce encoder GOP size, "
2109 "or add support for wider frame offset ranges.\n",
2110 offset, INT8_MIN, INT8_MAX);
2111 return AVERROR_PATCHWELCOME;
2112}
2113
2114// Fixed local tags and DeltaEntryArray, excluding the KLV key and length.
2116{
2117 return 85 + 12 + 6 * mxf_index_delta_count(s);
2118}
2119
2121{
2122 MXFContext *mxf = s->priv_data;
2123 AVIOContext *pb = s->pb;
2124 unsigned element_delta = 0;
2125 unsigned size = mxf_index_header_size(s);
2126 int i;
2127
2128 if (duration)
2132
2133 // instance id
2134 mxf_write_local_tag(s, 16, 0x3C0A);
2136
2137 // index edit rate
2138 mxf_write_local_tag(s, 8, 0x3F0B);
2139 avio_wb32(pb, mxf->time_base.den);
2140 avio_wb32(pb, mxf->time_base.num);
2141
2142 // index start position
2143 mxf_write_local_tag(s, 8, 0x3F0C);
2144 avio_wb64(pb, start);
2145
2146 // index duration, 0 if the index table covers whole container
2147 mxf_write_local_tag(s, 8, 0x3F0D);
2148 avio_wb64(pb, duration);
2149
2150 // edit unit byte count
2151 mxf_write_local_tag(s, 4, 0x3F05);
2153
2154 // index sid
2155 mxf_write_local_tag(s, 4, 0x3F06);
2156 avio_wb32(pb, 2);
2157
2158 // body sid
2159 mxf_write_local_tag(s, 4, 0x3F07);
2160 avio_wb32(pb, 1);
2161
2162 // real slice count - 1
2163 mxf_write_local_tag(s, 1, 0x3F08);
2165
2166 // delta entry array
2168 avio_wb32(pb, mxf_index_delta_count(s)); // num of entries
2169 avio_wb32(pb, 6); // size of one entry
2170 if (!IS_OPATOM(s)) {
2171 // write system item delta entry
2172 avio_w8(pb, 0);
2173 avio_w8(pb, 0); // slice entry
2174 avio_wb32(pb, 0); // element delta
2175 }
2176 // write each stream delta entry
2177 for (i = 0; i < s->nb_streams; i++) {
2178 AVStream *st = s->streams[i];
2179 MXFStreamContext *sc = st->priv_data;
2181 if (mxf->edit_unit_byte_count) {
2182 avio_w8(pb, 0); // slice number
2183 avio_wb32(pb, sc->slice_offset);
2184 } else if (i == 0) { // video track
2185 avio_w8(pb, 0); // slice number
2186 // system item size including klv fill, no system item in OPAtom
2187 avio_wb32(pb, IS_OPATOM(s) ? 0 : KAG_SIZE);
2188 } else { // audio or data track
2189 avio_w8(pb, 1);
2190 avio_wb32(pb, element_delta);
2191 element_delta += sc->element_size;
2192 }
2193 }
2194}
2195
2196static void mxf_write_fill(AVIOContext *pb, unsigned size)
2197{
2198 avio_write(pb, klv_fill_key, 16);
2199 size -= 16 + 4;
2201 ffio_fill(pb, 0, size);
2202}
2203
2205{
2206 unsigned pad = klv_fill_size(avio_tell(s->pb));
2207 if (pad) {
2208 mxf_write_fill(s->pb, pad);
2209 av_assert1(!(avio_tell(s->pb) & (KAG_SIZE-1)));
2210 }
2211}
2212
2214{
2215 MXFContext *mxf = s->priv_data;
2216 AVIOContext *pb = s->pb;
2217 int i, j;
2218 int key_index = mxf->last_key_index;
2219 int prev_non_b_picture = 0;
2220 int err;
2221
2222 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
2223
2224 if (!mxf->edit_units_count && !mxf->edit_unit_byte_count)
2225 return 0;
2226
2227 if (mxf->edit_unit_byte_count) {
2229 } else {
2230 MXFStreamContext *sc = s->streams[0]->priv_data;
2231
2232 for (i = 0; i < mxf->edit_units_count; i++) {
2233 int temporal_offset = 0;
2234
2235 // split the index table so that each segment fits 2 byte local set lengths
2236 if (!(i % mxf_index_max_entries(s))) {
2237 int nb_entries = FFMIN(mxf->edit_units_count - i, mxf_index_max_entries(s));
2238 if (i)
2241 nb_entries);
2242 mxf_write_local_tag(s, 8 + nb_entries*mxf_index_entry_size(s), 0x3F0A);
2243 avio_wb32(pb, nb_entries); // num of entries
2244 avio_wb32(pb, mxf_index_entry_size(s)); // size of one entry
2245 }
2246
2247 if (!(mxf->index_entries[i].flags & 0x33)) { // I-frame
2248 sc->max_gop = FFMAX(sc->max_gop, i - mxf->last_key_index);
2249 mxf->last_key_index = key_index;
2250 key_index = i;
2251 }
2252
2253 if (sc->temporal_reordering) {
2254 int pic_num_in_gop = i - key_index;
2255 if (pic_num_in_gop != mxf->index_entries[i].temporal_ref) {
2256 for (j = key_index; j < mxf->edit_units_count; j++) {
2257 if (pic_num_in_gop == mxf->index_entries[j].temporal_ref)
2258 break;
2259 }
2260 if (j == mxf->edit_units_count)
2261 av_log(s, AV_LOG_WARNING, "missing frames\n");
2262 temporal_offset = j - key_index - pic_num_in_gop;
2263 err = mxf_check_frame_offset(s, temporal_offset);
2264 if (err < 0)
2265 return err;
2266 }
2267 }
2268 avio_w8(pb, temporal_offset);
2269
2270 if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction
2271 int offset = mxf->last_key_index - i;
2273 if (err < 0)
2274 return err;
2275 sc->b_picture_count = FFMAX(sc->b_picture_count, i - prev_non_b_picture);
2276 avio_w8(pb, offset);
2277 } else {
2278 int offset = key_index - i;
2280 if (err < 0)
2281 return err;
2282 avio_w8(pb, offset); // key frame offset
2283 if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward
2284 mxf->last_key_index = key_index;
2285 prev_non_b_picture = i;
2286 }
2287
2288 if (!(mxf->index_entries[i].flags & 0x33) && // I-frame
2289 mxf->index_entries[i].flags & 0x40 && !temporal_offset)
2290 mxf->index_entries[i].flags |= 0x80; // random access
2291 avio_w8(pb, mxf->index_entries[i].flags);
2292 // stream offset
2293 avio_wb64(pb, mxf->index_entries[i].offset);
2296 }
2297
2298 mxf->last_key_index = key_index - mxf->edit_units_count;
2300 mxf->edit_units_count = 0;
2301 }
2302
2303 return 0;
2304}
2305
2306static int mxf_write_partition(AVFormatContext *s, int bodysid,
2307 int indexsid,
2308 const uint8_t *key, int write_metadata)
2309{
2310 MXFContext *mxf = s->priv_data;
2311 AVIOContext *pb = s->pb;
2312 int64_t header_byte_count_offset;
2313 uint64_t index_byte_count = 0;
2314 uint64_t partition_offset = avio_tell(pb);
2315 int err;
2316
2317 if (!mxf->edit_unit_byte_count && mxf->edit_units_count) {
2318 unsigned nb_segments = 1 + (mxf->edit_units_count - 1) / mxf_index_max_entries(s);
2319 // key and ber4 length, fixed sets, delta and index entry arrays per segment
2320 unsigned segment_header_size = 16 + 4 + mxf_index_header_size(s) + 12;
2321 unsigned full_segment_size = segment_header_size + mxf_index_max_entries(s) * mxf_index_entry_size(s);
2322 // segments are KAG aligned, the last one by the fill below
2323 index_byte_count = (uint64_t)nb_segments * segment_header_size +
2324 (uint64_t)mxf->edit_units_count * mxf_index_entry_size(s) +
2325 (uint64_t)(nb_segments - 1) * klv_fill_size(full_segment_size);
2326 } else if (mxf->edit_unit_byte_count && indexsid)
2327 index_byte_count = 16 + 4 + mxf_index_header_size(s);
2328
2329 if (index_byte_count)
2330 index_byte_count += klv_fill_size(index_byte_count);
2331
2332 if (key && !memcmp(key, body_partition_key, 16)) {
2334 sizeof(*mxf->body_partition_offset))) < 0) {
2335 mxf->body_partitions_count = 0;
2336 return err;
2337 }
2338 mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;
2339 }
2340
2341 // write klv
2342 if (key)
2343 avio_write(pb, key, 16);
2344 else
2346
2348
2349 // write partition value
2350 avio_wb16(pb, 1); // majorVersion
2351 avio_wb16(pb, 3); // minorVersion
2352 avio_wb32(pb, KAG_SIZE); // KAGSize
2353
2354 avio_wb64(pb, partition_offset); // ThisPartition
2355
2356 if (key && !memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)
2357 avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition
2358 else if (key && !memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)
2359 avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition
2360 else
2361 avio_wb64(pb, 0);
2362
2363 avio_wb64(pb, mxf->footer_partition_offset); // footerPartition
2364
2365 // set offset
2366 header_byte_count_offset = avio_tell(pb);
2367 avio_wb64(pb, 0); // headerByteCount, update later
2368
2369 // indexTable
2370 avio_wb64(pb, index_byte_count); // indexByteCount
2371 avio_wb32(pb, index_byte_count ? indexsid : 0); // indexSID
2372
2373 // BodyOffset
2374 if (bodysid && mxf->edit_units_count && mxf->body_partitions_count && !IS_OPATOM(s))
2375 avio_wb64(pb, mxf->body_offset);
2376 else
2377 avio_wb64(pb, 0);
2378
2379 avio_wb32(pb, bodysid); // bodySID
2380
2381 // operational pattern
2383
2384 // essence container
2386
2387 if (write_metadata) {
2388 // mark the start of the headermetadata and calculate metadata size
2389 int64_t pos, start;
2390 unsigned header_byte_count;
2391
2393 start = avio_tell(s->pb);
2397 pos = avio_tell(s->pb);
2398 header_byte_count = pos - start + klv_fill_size(pos);
2399
2400 // update header_byte_count
2401 avio_seek(pb, header_byte_count_offset, SEEK_SET);
2402 avio_wb64(pb, header_byte_count);
2403 avio_seek(pb, pos, SEEK_SET);
2404 }
2405
2406 if(key)
2408
2409 return 0;
2410}
2411
2412static const struct {
2416 { AV_PROFILE_PRORES_PROXY, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x01,0x00 } },
2417 { AV_PROFILE_PRORES_LT, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x02,0x00 } },
2418 { AV_PROFILE_PRORES_STANDARD, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x03,0x00 } },
2419 { AV_PROFILE_PRORES_HQ, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x04,0x00 } },
2420 { AV_PROFILE_PRORES_4444, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x05,0x00 } },
2421 { AV_PROFILE_PRORES_XQ, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x03,0x06,0x06,0x00 } },
2423
2425{
2426 MXFContext *mxf = s->priv_data;
2427 MXFStreamContext *sc = st->priv_data;
2428 int i, profile;
2429
2430 if (mxf->header_written)
2431 return 1;
2432
2433 profile = st->codecpar->profile;
2434 for (i = 0; i < FF_ARRAY_ELEMS(mxf_prores_codec_uls); i++) {
2436 sc->codec_ul = &mxf_prores_codec_uls[i].codec_ul;
2437 break;
2438 }
2439 }
2441 return 0;
2442
2443 /* frame header color fields, SMPTE RDD 36 */
2444 if (pkt->size >= 25 && AV_RL32(pkt->data + 4) == AV_RL32("icpf")) {
2445 int interlace_mode = (pkt->data[8 + 12] >> 2) & 3;
2446
2447 if (pkt->data[22]) // 0 is unknown
2448 sc->color_primaries = pkt->data[22];
2449 /* code 1 covers BT.601, BT.709 and BT.2020, keep a more precise stream value */
2450 if (pkt->data[23] &&
2451 (pkt->data[23] != AVCOL_TRC_BT709 ||
2455 sc->color_trc = pkt->data[23];
2456 if (pkt->data[24]) // 0 is unknown, not RGB
2457 sc->color_space = pkt->data[24];
2458
2459 // interlace_mode: 1 top field first, 2 bottom field first,
2460 // RDD 44 Table 6 also signals bottom field first with DisplayF2Offset -1.
2461 // Fields of a stream marked progressive (PsF) stay a full frame.
2463 (interlace_mode == 1 || interlace_mode == 2)) {
2464 sc->interlaced = 1;
2465 // Field 1 is first in both modes; the offset puts it below field 2 for BFF.
2466 sc->field_dominance = 1;
2467 sc->display_f2_offset = -(interlace_mode == 2);
2468 }
2469 }
2470
2471 sc->frame_size = pkt->size;
2472
2473 return 1;
2474}
2475
2476static const struct {
2477 uint16_t cid;
2478 uint8_t interlaced;
2479 UID codec_ul;
2480} mxf_dnxhd_codec_uls[] = {
2481 { 1235, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 } }, // 1080p 10bit HIGH
2482 { 1237, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x03,0x00,0x00 } }, // 1080p 8bit MED
2483 { 1238, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x04,0x00,0x00 } }, // 1080p 8bit HIGH
2484 { 1241, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x07,0x00,0x00 } }, // 1080i 10bit HIGH
2485 { 1242, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x08,0x00,0x00 } }, // 1080i 8bit MED
2486 { 1243, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x09,0x00,0x00 } }, // 1080i 8bit HIGH
2487 { 1244, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x0a,0x00,0x00 } }, // 1080i 8bit TR
2488 { 1250, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x10,0x00,0x00 } }, // 720p 10bit
2489 { 1251, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x11,0x00,0x00 } }, // 720p 8bit HIGH
2490 { 1252, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x12,0x00,0x00 } }, // 720p 8bit MED
2491 { 1253, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x13,0x00,0x00 } }, // 720p 8bit LOW
2492 { 1256, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x16,0x00,0x00 } }, // 1080p 10bit 444
2493 { 1258, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x18,0x00,0x00 } }, // 720p 8bit TR
2494 { 1259, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x19,0x00,0x00 } }, // 1080p 8bit TR
2495 { 1260, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x1a,0x00,0x00 } }, // 1080i 8bit TR MBAFF
2496 { 1270, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x24,0x00,0x00 } }, // DNXHR 444
2497 { 1271, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x25,0x00,0x00 } }, // DNXHR HQX
2498 { 1272, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x26,0x00,0x00 } }, // DNXHR HQ
2499 { 1273, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x27,0x00,0x00 } }, // DNXHR SQ
2500 { 1274, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x28,0x00,0x00 } }, // DNXHR LB
2502
2504{
2505 MXFContext *mxf = s->priv_data;
2506 MXFStreamContext *sc = st->priv_data;
2507 int i, clv, rgb;
2508
2509 if (mxf->header_written)
2510 return 1;
2511
2512 if (pkt->size < 0x2d)
2513 return 0;
2514
2515 sc->cid = AV_RB32(pkt->data + 0x28);
2516 for (i = 0; i < FF_ARRAY_ELEMS(mxf_dnxhd_codec_uls); i++) {
2517 if (sc->cid == mxf_dnxhd_codec_uls[i].cid) {
2518 sc->codec_ul = &mxf_dnxhd_codec_uls[i].codec_ul;
2519 sc->interlaced = mxf_dnxhd_codec_uls[i].interlaced;
2520 break;
2521 }
2522 }
2524 return 0;
2525
2526 if (sc->cid >= 1270) { // RI raster
2528 st->codecpar->width, st->codecpar->height,
2529 INT_MAX);
2530 } else {
2531 sc->aspect_ratio = (AVRational){ 16, 9 };
2532 }
2533
2534 sc->frame_size = pkt->size;
2535
2536 /* RGB color format with 4:4:4 sampling */
2537 rgb = (sc->cid == 1270 || sc->cid == 1256) && (pkt->data[0x2c] & 0x41) == 0x41;
2538 if (rgb)
2540
2541 clv = (pkt->data[0x2c] >> 1) & 3;
2542 if (clv < 3) { // in-band color volume, video range
2543 static const enum AVColorSpace clv_spaces[3] = {
2545 };
2546 AVCodecParameters *par = st->codecpar;
2547 /* older encoders wrote CLV=0 for any primaries */
2548 if (clv && par->color_primaries == AVCOL_PRI_UNSPECIFIED)
2551 par->color_space = rgb ? AVCOL_SPC_RGB : clv_spaces[clv];
2554 }
2555
2556 return 1;
2557}
2558
2559static const struct {
2561 const UID codec_ul;
2562} mxf_dv_uls[] = {
2563 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x01,0x01 }, // IEC DV25 525/60
2564 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x01,0x00 } },
2565 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x02,0x01 }, // IEC DV25 626/50
2566 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 } },
2567 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x40,0x01 }, // DV25 525/60
2568 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x01,0x00 }, },
2569 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, // DV25 625/50
2570 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 }, },
2571 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x50,0x01 }, // DV50 525/60
2572 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x03,0x00 }, },
2573 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x51,0x01 }, // DV50 625/50
2574 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 }, },
2575 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x60,0x01 }, // DV100 1080/60
2576 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x05,0x00 }, },
2577 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x61,0x01 }, // DV100 1080/50
2578 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x06,0x00 }, },
2579 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x62,0x01 }, // DV100 720/60
2580 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x07,0x00 }, },
2581 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x63,0x01 }, // DV100 720/50
2582 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x08,0x00 }, },
2584
2586{
2587 MXFContext *mxf = s->priv_data;
2588 MXFStreamContext *sc = st->priv_data;
2589 const uint8_t *vs_pack, *vsc_pack;
2590 int apt, ul_index, stype, pal;
2591
2592 if (mxf->header_written)
2593 return 1;
2594
2595 // Check for minimal frame size
2596 if (pkt->size < 120000)
2597 return -1;
2598
2599 apt = pkt->data[4] & 0x7;
2600 vs_pack = pkt->data + 80*5 + 48;
2601 vsc_pack = pkt->data + 80*5 + 53;
2602 stype = vs_pack[3] & 0x1f;
2603 pal = (vs_pack[3] >> 5) & 0x1;
2604
2605 if ((vsc_pack[2] & 0x07) == 0x02) {
2606 sc->aspect_ratio = (AVRational){ 16, 9 };
2607 } else {
2608 sc->aspect_ratio = (AVRational){ 4, 3 };
2609 }
2610
2611 sc->interlaced = (vsc_pack[3] >> 4) & 0x01;
2612 // TODO: fix dv encoder to set proper FF/FS value in VSC pack
2613 // and set field dominance accordingly
2614 // av_log(s, AV_LOG_DEBUG, "DV vsc pack ff/ss = %x\n", vsc_pack[2] >> 6);
2615
2616 switch (stype) {
2617 case 0x18: // DV100 720p
2618 ul_index = 8+pal;
2619 if (sc->interlaced) {
2620 av_log(s, AV_LOG_ERROR, "source marked as interlaced but codec profile is progressive\n");
2621 sc->interlaced = 0;
2622 }
2623 break;
2624 case 0x14: // DV100 1080i
2625 ul_index = 6+pal;
2626 break;
2627 case 0x04: // DV50
2628 ul_index = 4+pal;
2629 break;
2630 default: // DV25
2631 if (!apt) { // IEC
2632 ul_index = 0+pal;
2633 } else {
2634 ul_index = 2+pal;
2635 }
2636 }
2637
2638 sc->container_ul = &mxf_dv_uls[ul_index].container_ul;
2639 sc->codec_ul = &mxf_dv_uls[ul_index].codec_ul;
2640
2641 sc->frame_size = pkt->size;
2642
2643 return 1;
2644}
2645
2646static const struct {
2649 uint8_t profile;
2650 uint8_t interlaced;
2651 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
2652} mxf_h264_codec_uls[] = {
2653 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 0, 66, 0, -1 }, // AVC Baseline
2654 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x20,0x01 }, 0, 77, 0, -1 }, // AVC Main
2655 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x30,0x01 }, 0, 88, 0, -1 }, // AVC Extended
2656 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x40,0x01 }, 0, 100, 0, -1 }, // AVC High
2657 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x50,0x01 }, 0, 110, 0, 0 }, // AVC High 10
2658 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x60,0x01 }, 0, 122, 0, 0 }, // AVC High 422
2659 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x70,0x01 }, 0, 244, 0, 0 }, // AVC High 444
2660 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x20,0x01 }, 0, 110, 0, 1 }, // AVC High 10 Intra
2661 {{ 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
2662 {{ 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
2663 {{ 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
2664 {{ 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
2665 {{ 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
2666 {{ 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
2667 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x30,0x01 }, 0, 122, 0, 1 }, // AVC High 422 Intra
2668 {{ 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
2669 {{ 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
2670 {{ 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
2671 {{ 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
2672 {{ 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
2673 {{ 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
2674 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x01,0x32,0x40,0x01 }, 0, 244, 0, 1 }, // AVC High 444 Intra
2675 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0d,0x04,0x01,0x02,0x02,0x01,0x32,0x50,0x01 }, 0, 44, 0, -1 }, // AVC CAVLC 444
2677
2680{
2681 MXFContext *mxf = s->priv_data;
2682 MXFStreamContext *sc = st->priv_data;
2683 H264SPS seq, *const sps = &seq;
2684 GetBitContext gb;
2685 const uint8_t *buf = pkt->data;
2686 const uint8_t *buf_end = pkt->data + pkt->size;
2687 const uint8_t *nal_end;
2688 const UID *codec_ul = NULL;
2689 uint32_t state = -1;
2690 int extra_size = 512; // support AVC Intra files without SPS/PPS header
2691 int i, frame_size, slice_type, has_sps = 0, intra_only = 0, avc_intra = 0, ret;
2692
2693 for (;;) {
2694 buf = avpriv_find_start_code(buf, buf_end, &state);
2695 if (buf >= buf_end)
2696 break;
2697
2698 switch (state & 0x1f) {
2699 case H264_NAL_SPS:
2700 e->flags |= 0x40;
2701
2702 if (mxf->header_written)
2703 break;
2704
2705 nal_end = ff_nal_find_startcode(buf, buf_end);
2706 ret = ff_avc_decode_sps(sps, buf, nal_end - buf);
2707 if (ret < 0) {
2708 av_log(s, AV_LOG_ERROR, "error parsing sps\n");
2709 return 0;
2710 }
2711 has_sps = 1;
2712
2713 sc->aspect_ratio.num = st->codecpar->width * sps->sar.num;
2714 sc->aspect_ratio.den = st->codecpar->height * sps->sar.den;
2716 sc->aspect_ratio.num, sc->aspect_ratio.den, 1024*1024);
2717 intra_only = (sps->constraint_set_flags >> 3) & 1;
2718 sc->interlaced = !sps->frame_mbs_only_flag;
2719
2720 if (sps->video_signal_type_present_flag) {
2721 sc->color_range = sps->video_full_range_flag ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
2722 if (sps->colour_description_present_flag) {
2723 sc->color_primaries = sps->colour_primaries;
2724 sc->color_trc = sps->transfer_characteristics;
2725 sc->color_space = sps->matrix_coefficients;
2726 }
2727 }
2728
2729 buf = nal_end;
2730 break;
2731 case H264_NAL_PPS:
2732 if (e->flags & 0x40) { // sequence header present
2733 e->flags |= 0x80; // random access
2734 extra_size = 0;
2735 }
2736 break;
2737 case H264_NAL_IDR_SLICE:
2738 e->flags |= 0x04; // IDR Picture
2739 buf = buf_end;
2740 break;
2741 case H264_NAL_SLICE:
2742 init_get_bits8(&gb, buf, buf_end - buf);
2743 get_ue_golomb_long(&gb); // skip first_mb_in_slice
2744 slice_type = get_ue_golomb_31(&gb);
2745 switch (slice_type % 5) {
2746 case 0:
2747 e->flags |= 0x20; // P Picture
2748 e->flags |= 0x06; // P Picture
2749 break;
2750 case 1:
2751 e->flags |= 0x30; // B Picture
2752 e->flags |= 0x03; // non-referenced B Picture
2753 break;
2754 }
2755 buf = buf_end;
2756 break;
2757 default:
2758 break;
2759 }
2760 }
2761
2762 if (mxf->header_written)
2763 return 1;
2764
2765 if (!has_sps)
2767 frame_size = pkt->size + extra_size;
2768
2769 for (i = 0; i < FF_ARRAY_ELEMS(mxf_h264_codec_uls); i++) {
2772 sc->aspect_ratio = (AVRational){ 16, 9 }; // 16:9 is mandatory for broadcast HD
2773 st->codecpar->profile = mxf_h264_codec_uls[i].profile;
2774 avc_intra = 1;
2775 mxf->cbr_index = 1;
2776 sc->frame_size = pkt->size;
2777 if (sc->interlaced)
2778 sc->field_dominance = 1; // top field first is mandatory for AVC Intra
2779 break;
2780 } else if (has_sps && mxf_h264_codec_uls[i].frame_size == 0 &&
2781 mxf_h264_codec_uls[i].profile == sps->profile_idc &&
2782 (mxf_h264_codec_uls[i].intra_only < 0 ||
2783 mxf_h264_codec_uls[i].intra_only == intra_only)) {
2785 st->codecpar->profile = sps->profile_idc;
2786 st->codecpar->level = sps->level_idc;
2787 // continue to check for avc intra
2788 }
2789 }
2790
2791 if (!codec_ul) {
2792 av_log(s, AV_LOG_ERROR, "h264 profile not supported\n");
2793 return 0;
2794 }
2795
2796 sc->codec_ul = codec_ul;
2797
2798 if (avc_intra)
2800 else
2802
2803 return 1;
2804}
2805
2806static inline int get_ffv1_unsigned_symbol(RangeCoder *c, uint8_t *state) {
2807 if(get_rac(c, state+0))
2808 return 0;
2809 else{
2810 int i, e;
2811 unsigned a;
2812 e= 0;
2813 while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10
2814 e++;
2815 if (e > 31)
2816 return AVERROR_INVALIDDATA;
2817 }
2818
2819 a= 1;
2820 for(i=e-1; i>=0; i--){
2821 a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31
2822 }
2823
2824 return a;
2825 }
2826}
2827#define FFV1_CONTEXT_SIZE 32
2829{
2830 MXFContext *mxf = s->priv_data;
2831 MXFStreamContext *sc = st->priv_data;
2832 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
2833 uint8_t state[FFV1_CONTEXT_SIZE];
2834 RangeCoder c;
2835 unsigned v;
2836
2837 sc->frame_size = pkt->size;
2838
2839 if (mxf->header_written)
2840 return 1;
2841
2842 memset(state, 128, sizeof(state));
2843 if (st->codecpar->extradata) {
2845 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
2847 if (v < 2 || v > 4) {
2848 av_log(s, AV_LOG_ERROR, "unsupported ffv1 version %d\n", v);
2849 return 0;
2850 }
2852 } else {
2853 uint8_t keystate = 128;
2854 ff_init_range_decoder(&c, pkt->data, pkt->size);
2855 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
2856 get_rac(&c, &keystate); // keyframe
2858 if (v >= 2)
2859 return 0;
2860 }
2861 sc->version = v;
2862 sc->codec_ul = &mxf_ffv1_codec_uls[v];
2864
2866 sc->interlaced = 1;
2868 }
2872 sc->aspect_ratio.num, sc->aspect_ratio.den, INT_MAX);
2873
2874 if (pix_desc->flags & AV_PIX_FMT_FLAG_RGB)
2876
2877 return 1;
2878}
2879
2880/* Position the reader within the first Contiguous Codestream box (T.800, I.5.4). */
2882{
2883 while (bytestream2_get_bytes_left(g) >= 8) {
2884 unsigned int remaining = bytestream2_get_bytes_left(g);
2885 uint64_t size = bytestream2_get_be32u(g);
2886 uint32_t type = bytestream2_get_be32u(g);
2887 unsigned int header_size = 8;
2888
2889 if (size == 1) {
2890 size = bytestream2_get_be64(g);
2891 header_size = 16;
2892 } else if (!size) {
2893 size = remaining;
2894 }
2895 if (size < header_size || size > remaining)
2896 return AVERROR_INVALIDDATA;
2897 if (type == MKBETAG('j', 'p', '2', 'c')) {
2898 bytestream2_init(g, g->buffer, size - header_size);
2899 return 0;
2900 }
2901 bytestream2_skipu(g, size - header_size);
2902 }
2903 return AVERROR_INVALIDDATA;
2904}
2905
2907{
2908 MXFContext *mxf = s->priv_data;
2909 MXFStreamContext *sc = st->priv_data;
2910 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
2912 unsigned int j2k_ncomponents;
2913 int is_jp2;
2914
2915 if (mxf->header_written)
2916 return 1;
2917
2918 bytestream2_init(&g,pkt->data,pkt->size);
2919
2920 is_jp2 = bytestream2_peek_be64(&g) == 0x0000000c6a502020;
2921 if (is_jp2) {
2922 if (mxf_jp2_find_codestream(&g) < 0) {
2923 av_log(s, AV_LOG_ERROR, "Could not locate JPEG 2000 codestream box\n");
2924 return AVERROR_INVALIDDATA;
2925 }
2926 } else {
2927 while (bytestream2_get_bytes_left(&g) >= 3 && bytestream2_peek_be16(&g) != JPEG2000_SOC)
2928 bytestream2_skip(&g, 1);
2929 }
2930
2931 if (bytestream2_get_be16(&g) != JPEG2000_SOC) {
2932 av_log(s, AV_LOG_ERROR, "Mandatory SOC marker is not present\n");
2933 return AVERROR_INVALIDDATA;
2934 }
2935
2936 /* Extract useful size information from the SIZ marker */
2937 if (bytestream2_get_be16(&g) != JPEG2000_SIZ) {
2938 av_log(s, AV_LOG_ERROR, "Mandatory SIZ marker is not present\n");
2939 return AVERROR_INVALIDDATA;
2940 }
2941 if (bytestream2_get_bytes_left(&g) < 38) {
2942 av_log(s, AV_LOG_ERROR, "Truncated JPEG 2000 SIZ header\n");
2943 return AVERROR_INVALIDDATA;
2944 }
2945 bytestream2_skip(&g, 2); // Skip Lsiz
2946 sc->j2k_info.j2k_rsiz = bytestream2_get_be16u(&g);
2947 sc->j2k_info.j2k_xsiz = bytestream2_get_be32u(&g);
2948 sc->j2k_info.j2k_ysiz = bytestream2_get_be32u(&g);
2949 sc->j2k_info.j2k_x0siz = bytestream2_get_be32u(&g);
2950 sc->j2k_info.j2k_y0siz = bytestream2_get_be32u(&g);
2951 sc->j2k_info.j2k_xtsiz = bytestream2_get_be32u(&g);
2952 sc->j2k_info.j2k_ytsiz = bytestream2_get_be32u(&g);
2953 sc->j2k_info.j2k_xt0siz = bytestream2_get_be32u(&g);
2954 sc->j2k_info.j2k_yt0siz = bytestream2_get_be32u(&g);
2955 j2k_ncomponents = bytestream2_get_be16u(&g);
2956 if (!j2k_ncomponents || j2k_ncomponents > sizeof(sc->j2k_info.j2k_comp_desc) / 3) {
2957 av_log(s, AV_LOG_ERROR, "Unsupported JPEG 2000 component count: %u\n", j2k_ncomponents);
2958 return AVERROR_INVALIDDATA;
2959 }
2960 /* JP2 component mapping can change the decoded channel count. */
2961 if (!is_jp2 && j2k_ncomponents != pix_desc->nb_components) {
2962 av_log(s, AV_LOG_ERROR, "Incoherence about components image number.\n");
2963 return AVERROR_INVALIDDATA;
2964 }
2965 if (bytestream2_get_bytes_left(&g) < 3 * j2k_ncomponents) {
2966 av_log(s, AV_LOG_ERROR, "Truncated JPEG 2000 SIZ component records\n");
2967 return AVERROR_INVALIDDATA;
2968 }
2969 bytestream2_get_bufferu(&g, sc->j2k_info.j2k_comp_desc, 3 * j2k_ncomponents);
2970
2971 sc->j2k_info.j2k_csiz = j2k_ncomponents;
2972 sc->frame_size = pkt->size;
2974
2975 return 1;
2976}
2977
2978static const UID mxf_mpeg2_codec_uls[] = {
2979 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x10,0x00 }, // MP-ML I-Frame
2980 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, // MP-ML Long GOP
2981 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, // 422P-ML I-Frame
2982 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, // 422P-ML Long GOP
2983 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x02,0x00 }, // MP-HL I-Frame
2984 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP
2985 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame
2986 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP
2987 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame
2988 { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP
2989};
2990
2992{
2993 int long_gop = 1;
2994
2995 if (par->profile == 4) { // Main
2996 if (par->level == 8) // Main
2997 return &mxf_mpeg2_codec_uls[0+long_gop];
2998 else if (par->level == 4) // High
2999 return &mxf_mpeg2_codec_uls[4+long_gop];
3000 else if (par->level == 6) // High 14
3001 return &mxf_mpeg2_codec_uls[8+long_gop];
3002 } else if (par->profile == 0) { // 422
3003 if (par->level == 5) // Main
3004 return &mxf_mpeg2_codec_uls[2+long_gop];
3005 else if (par->level == 2) // High
3006 return &mxf_mpeg2_codec_uls[6+long_gop];
3007 }
3008 return NULL;
3009}
3010
3013{
3014 MXFContext *mxf = s->priv_data;
3015 MXFStreamContext *sc = st->priv_data;
3016 uint32_t c = -1;
3017 int i;
3018
3019 for(i = 0; i < pkt->size - 4; i++) {
3020 c = (c<<8) + pkt->data[i];
3021 if (c == 0x1b5) {
3022 if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext
3023 st->codecpar->profile = pkt->data[i+1] & 0x07;
3024 st->codecpar->level = pkt->data[i+2] >> 4;
3025 sc->low_delay = pkt->data[i+6] >> 7;
3026 } else if (i + 4 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x20) { // seq display ext
3027 /* Header metadata must keep its size when rewritten. */
3028 if (!mxf->header_written && (pkt->data[i+1] & 0x01)) { // colour_description
3029 sc->color_primaries = pkt->data[i+2];
3030 sc->color_trc = pkt->data[i+3];
3031 sc->color_space = pkt->data[i+4];
3032 }
3033 } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
3034 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame
3035 if (sc->interlaced)
3036 sc->field_dominance = 1 + !(pkt->data[i+4] & 0x80); // top field first
3037 break;
3038 }
3039 } else if (c == 0x1b8) { // gop
3040 if (pkt->data[i+4]>>6 & 0x01) { // closed
3041 if (sc->seq_closed_gop == -1)
3042 sc->seq_closed_gop = 1;
3043 sc->closed_gop = 1;
3044 if (e->flags & 0x40) // sequence header present
3045 e->flags |= 0x80; // random access
3046 } else {
3047 sc->seq_closed_gop = 0;
3048 sc->closed_gop = 0;
3049 }
3050 } else if (c == 0x1b3) { // seq
3051 e->flags |= 0x40;
3052 switch ((pkt->data[i+4]>>4) & 0xf) {
3053 case 2: sc->aspect_ratio = (AVRational){ 4, 3}; break;
3054 case 3: sc->aspect_ratio = (AVRational){ 16, 9}; break;
3055 case 4: sc->aspect_ratio = (AVRational){221,100}; break;
3056 default:
3058 st->codecpar->width, st->codecpar->height, 1024*1024);
3059 }
3060 } else if (c == 0x100) { // pic
3061 int pict_type = (pkt->data[i+2]>>3) & 0x07;
3062 e->temporal_ref = (pkt->data[i+1]<<2) | (pkt->data[i+2]>>6);
3063 if (pict_type == 2) { // P-frame
3064 e->flags |= 0x22;
3065 sc->closed_gop = 0; // reset closed GOP, don't matter anymore
3066 } else if (pict_type == 3) { // B-frame
3067 if (sc->closed_gop)
3068 e->flags |= 0x13; // only backward prediction
3069 else
3070 e->flags |= 0x33;
3071 sc->temporal_reordering = -1;
3072 } else if (!pict_type) {
3073 av_log(s, AV_LOG_ERROR, "error parsing mpeg2 frame\n");
3074 return 0;
3075 }
3076 }
3077 }
3078 if (!IS_D10(s)) {
3080 if (!codec_ul)
3081 return 0;
3082 sc->codec_ul = codec_ul;
3084 }
3085 return 1;
3086}
3087
3088static uint64_t mxf_parse_timestamp(int64_t timestamp64)
3089{
3090 time_t timestamp = timestamp64 / 1000000;
3091 struct tm tmbuf;
3092 struct tm *time = gmtime_r(&timestamp, &tmbuf);
3093 if (!time)
3094 return 0;
3095 return (uint64_t)(time->tm_year+1900) << 48 |
3096 (uint64_t)(time->tm_mon+1) << 40 |
3097 (uint64_t) time->tm_mday << 32 |
3098 time->tm_hour << 24 |
3099 time->tm_min << 16 |
3100 time->tm_sec << 8 |
3101 (timestamp64 % 1000000) / 4000;
3102}
3103
3105{
3106 MXFContext *mxf = s->priv_data;
3107 uint32_t seed = av_get_random_seed();
3108 uint64_t umid = seed + 0x5294713400000000LL;
3109
3110 AV_WB64(mxf->umid , umid);
3111 AV_WB64(mxf->umid+8, umid>>8);
3112
3113 mxf->instance_number = seed & 0xFFFFFF;
3114}
3115
3117{
3118 MXFContext *mxf = s->priv_data;
3119 AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
3120
3122 if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
3123 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);
3124 return AVERROR(EINVAL);
3125 } else {
3126 av_log(s, AV_LOG_WARNING, "Unofficial frame rate %d/%d.\n", tbc.den, tbc.num);
3127 }
3128 }
3129
3130 mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
3131 if (!tcr)
3132 tcr = av_dict_get(st->metadata, "timecode", NULL, 0);
3133
3134 if (tcr)
3135 return av_timecode_init_from_string(&mxf->tc, av_inv_q(tbc), tcr->value, s);
3136 else
3137 return av_timecode_init(&mxf->tc, av_inv_q(tbc), 0, 0, s);
3138}
3139
3141{
3142 AVCodecParameters *par = st->codecpar;
3143 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(par->format);
3144
3146 return par->chroma_location;
3147
3148 if (pix_desc->log2_chroma_h == 0) {
3149 return AVCHROMA_LOC_TOPLEFT;
3150 } else if (pix_desc->log2_chroma_w == 1 && pix_desc->log2_chroma_h == 1) {
3152 switch (par->codec_id) {
3153 case AV_CODEC_ID_MJPEG:
3155 }
3156 }
3158 switch (par->codec_id) {
3160 }
3161 }
3162 }
3163
3165}
3166
3168{
3169 MXFContext *mxf = s->priv_data;
3170 int i, ret;
3171 uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
3172 int64_t timestamp = 0;
3173
3174 if (IS_OPATOM(s)) {
3175 const AVCodecParameters *par;
3176
3177 if (s->nb_streams != 1) {
3178 av_log(s, AV_LOG_ERROR, "there must be exactly one stream for mxf opatom\n");
3179 return -1;
3180 }
3181 par = s->streams[0]->codecpar;
3182 // This muxer writes one clip KLV; ProRes and ANC mappings use frame elements.
3183 if (par->codec_id == AV_CODEC_ID_PRORES ||
3184 (par->codec_type != AVMEDIA_TYPE_VIDEO &&
3185 par->codec_type != AVMEDIA_TYPE_AUDIO)) {
3186 av_log(s, AV_LOG_ERROR, "%s is not supported in MXF OPAtom\n",
3188 return AVERROR_PATCHWELCOME;
3189 }
3190 }
3191
3192 if (!av_dict_get(s->metadata, "comment_", NULL, AV_DICT_IGNORE_SUFFIX))
3193 mxf->store_user_comments = 0;
3194
3196 mxf->anc_pkt = av_packet_alloc();
3197 if (!mxf->anc_pkt)
3198 return AVERROR(ENOMEM);
3199
3200 for (i = 0; i < s->nb_streams; i++) {
3201 AVStream *st = s->streams[i];
3202 MXFStreamContext *sc = av_mallocz(sizeof(*sc));
3203 if (!sc)
3204 return AVERROR(ENOMEM);
3205 st->priv_data = sc;
3206 sc->index = -1;
3211
3212 if (((i == 0) ^ (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) && !IS_OPATOM(s)) {
3213 av_log(s, AV_LOG_ERROR, "there must be exactly one video stream and it must be the first one\n");
3214 return -1;
3215 }
3216
3218 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
3219 AVRational tbc = (AVRational){ 0, 0 };
3220
3221 if (!pix_desc) {
3222 av_log(s, AV_LOG_ERROR, "video stream require the codec pixel format to be set\n");
3223 return -1;
3224 }
3225
3226 if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0)
3227 tbc = av_inv_q(st->avg_frame_rate);
3228 else if (st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0)
3229 tbc = av_inv_q(st->r_frame_rate);
3230
3233 av_make_q(st->codecpar->width, st->codecpar->height));
3234 }
3235
3237 mxf->time_base = tbc;
3238 avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
3239 if((ret = mxf_init_timecode(s, st, tbc)) < 0)
3240 return ret;
3241
3243 sc->seq_closed_gop = -1; // unknown yet
3244 }
3245
3247 sc->video_bit_rate = st->codecpar->bit_rate;
3248
3249 if (IS_D10(s) ||
3252 mxf->cbr_index = 1;
3253
3254 if (IS_D10(s)) {
3255 int ntsc = mxf->time_base.den != 25;
3256 int ul_index;
3257
3259 av_log(s, AV_LOG_ERROR, "error MXF D-10 only support MPEG-2 Video\n");
3260 return AVERROR(EINVAL);
3261 }
3262 if ((sc->video_bit_rate == 50000000) && (mxf->time_base.den == 25)) {
3263 ul_index = 0;
3264 } else if ((sc->video_bit_rate == 49999840 || sc->video_bit_rate == 50000000) && ntsc) {
3265 ul_index = 1;
3266 } else if (sc->video_bit_rate == 40000000) {
3267 ul_index = 2+ntsc;
3268 } else if (sc->video_bit_rate == 30000000) {
3269 ul_index = 4+ntsc;
3270 } else {
3271 av_log(s, AV_LOG_ERROR, "error MXF D-10 only support 30/40/50 mbit/s\n");
3272 return -1;
3273 }
3274
3275 sc->codec_ul = &mxf_d10_codec_uls[ul_index];
3276 sc->container_ul = &mxf_d10_container_uls[ul_index];
3277 sc->index = INDEX_D10_VIDEO;
3278 sc->signal_standard = 1;
3279 sc->frame_size = (int64_t)sc->video_bit_rate *
3280 mxf->time_base.num / (8*mxf->time_base.den);
3281 }
3282 if (mxf->signal_standard >= 0)
3284 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
3285 char bsf_arg[32];
3286 if (st->codecpar->sample_rate != 48000) {
3287 av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n");
3288 return -1;
3289 }
3290 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
3291 if (IS_D10(s)) {
3292 if (st->index != 1) {
3293 av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n");
3294 return -1;
3295 }
3298 av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
3299 return AVERROR_PATCHWELCOME;
3300 }
3301 if (st->codecpar->ch_layout.nb_channels > 8) {
3302 av_log(s, AV_LOG_ERROR, "MXF D-10 supports at most 8 audio channels\n");
3303 return AVERROR(EINVAL);
3304 }
3305 sc->index = INDEX_D10_AUDIO;
3306 sc->container_ul = ((MXFStreamContext*)s->streams[0]->priv_data)->container_ul;
3307 sc->frame_size = 4 + 8 * av_rescale_rnd(st->codecpar->sample_rate, mxf->time_base.num, mxf->time_base.den, AV_ROUND_UP) * 4;
3308 } else if (IS_OPATOM(s)) {
3310
3313 av_log(s, AV_LOG_ERROR, "Only pcm_s16le and pcm_s24le audio codecs are implemented\n");
3314 return AVERROR_PATCHWELCOME;
3315 }
3316 if (st->codecpar->ch_layout.nb_channels != 1) {
3317 av_log(s, AV_LOG_ERROR, "MXF OPAtom only supports single channel audio\n");
3318 return AVERROR(EINVAL);
3319 }
3320
3321 mxf->time_base = st->time_base;
3322 if((ret = mxf_init_timecode(s, st, tbc)) < 0)
3323 return ret;
3324
3326 sc->index = INDEX_WAV;
3327 }
3328 snprintf(bsf_arg, sizeof(bsf_arg), "r=%d/%d", mxf->tc.rate.num, mxf->tc.rate.den);
3329 ret = ff_stream_add_bitstream_filter(st, "pcm_rechunk", bsf_arg);
3330 if (ret < 0)
3331 return ret;
3332 if (!IS_D10(s) && !IS_OPATOM(s)) {
3333 // pcm_rechunk checked the channel count and frame size
3334 int sample_size = st->codecpar->ch_layout.nb_channels *
3336 sc->frame_size = sample_size * av_rescale_rnd(st->codecpar->sample_rate, mxf->time_base.num,
3337 mxf->time_base.den, AV_ROUND_UP);
3339 }
3341 AVDictionaryEntry* e = av_dict_get(st->metadata, "data_type", NULL, 0);
3342 if ((e && !strcmp(e->value, "vbi_vanc_smpte_436M")) ||
3345 sc->index = INDEX_S436M;
3346 } else {
3347 av_log(s, AV_LOG_ERROR, "track %d: unsupported data type\n", i);
3348 return -1;
3349 }
3350 if (st->index != s->nb_streams - 1) {
3351 av_log(s, AV_LOG_ERROR, "data track must be placed last\n");
3352 return -1;
3353 }
3355 // an ANC element only holds the captions of one frame
3356 char bsf_arg[64] = "split=1";
3357 if (mxf->time_base.num != 0 && mxf->time_base.den != 0) {
3358 // frame rate is reciprocal of time base
3359 snprintf(bsf_arg, sizeof(bsf_arg), "split=1:cdp_frame_rate=%d/%d", mxf->time_base.den, mxf->time_base.num);
3360 }
3361 ret = ff_stream_add_bitstream_filter(st, "eia608_to_smpte436m", bsf_arg);
3362 if (ret < 0)
3363 return ret;
3364 }
3365 }
3366
3367 if (sc->index == -1) {
3369 if (sc->index == -1) {
3370 av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
3371 "codec not currently supported in container\n", i);
3372 return -1;
3373 }
3374 }
3375
3376 if (!sc->codec_ul)
3377 sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
3378 if (!sc->container_ul)
3379 sc->container_ul = &mxf_essence_container_uls[sc->index].container_ul;
3380
3381 memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
3382 sc->track_essence_element_key[15] = present[sc->index];
3383 // ANC element numbers start at 1, ST 436-1
3384 if (sc->index == INDEX_S436M)
3385 sc->track_essence_element_key[15]++;
3386 if (!IS_OPATOM(s)) {
3387 PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
3388 }
3389
3390 if (!present[sc->index])
3392 present[sc->index]++;
3393 }
3394
3395 if (IS_D10(s) || IS_OPATOM(s)) {
3396 mxf->essence_container_count = 1;
3397 }
3398
3399 if (!(s->flags & AVFMT_FLAG_BITEXACT))
3400 mxf_gen_umid(s);
3401
3402 for (i = 0; i < s->nb_streams; i++) {
3403 MXFStreamContext *sc = s->streams[i]->priv_data;
3404 // update element count
3405 sc->track_essence_element_key[13] = present[sc->index];
3406 if (!memcmp(sc->track_essence_element_key, mxf_essence_container_uls[INDEX_DV].element_ul, 13)) // DV
3407 sc->order = (0x15 << 24) | AV_RB32(sc->track_essence_element_key+13);
3408 else
3410 }
3411
3412 if (ff_parse_creation_time_metadata(s, &timestamp, 0) > 0)
3413 mxf->timestamp = mxf_parse_timestamp(timestamp);
3414 mxf->duration = -1;
3415
3416 mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
3417 if (!mxf->timecode_track)
3418 return AVERROR(ENOMEM);
3420 mxf->timecode_track->index = -1;
3421
3422 return 0;
3423}
3424
3425static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 };
3426static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 };
3427
3429{
3430 MXFContext *mxf = s->priv_data;
3431 AVIOContext *pb = s->pb;
3432 unsigned frame;
3433 uint32_t time_code;
3434 int i, system_item_bitmap = 0x58; // UL, user date/time stamp, picture present
3435
3437
3438 // write system metadata pack
3440 klv_encode_ber4_length(pb, 57);
3441
3442 for (i = 0; i < s->nb_streams; i++) {
3443 if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
3444 system_item_bitmap |= 0x4;
3445 else if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_DATA ||
3446 s->streams[i]->codecpar->codec_id == AV_CODEC_ID_EIA_608)
3447 system_item_bitmap |= 0x2;
3448 }
3449 avio_w8(pb, system_item_bitmap);
3450 avio_w8(pb, mxf->content_package_rate); // content package rate
3451 avio_w8(pb, 0x00); // content package type
3452 avio_wb16(pb, 0x00); // channel handle
3453 avio_wb16(pb, frame & 0xFFFF); // continuity count, supposed to overflow
3454 if (mxf->essence_container_count > 1)
3456 else {
3457 MXFStreamContext *sc = s->streams[0]->priv_data;
3458 avio_write(pb, *sc->container_ul, 16);
3459 }
3460 avio_w8(pb, 0);
3461 avio_wb64(pb, 0);
3462 avio_wb64(pb, 0); // creation date/time stamp
3463
3464 avio_w8(pb, 0x81); // SMPTE 12M time code
3466 avio_wb32(pb, time_code);
3467 avio_wb32(pb, 0); // binary group data
3468 avio_wb64(pb, 0);
3469
3470 // write system metadata package set
3472 klv_encode_ber4_length(pb, 35);
3473 avio_w8(pb, 0x83); // UMID
3474 avio_wb16(pb, 0x20);
3475 mxf_write_umid(s, 1);
3476}
3477
3479{
3480 MXFContext *mxf = s->priv_data;
3481 AVIOContext *pb = s->pb;
3482 int frame_size = pkt->size / st->codecpar->block_align;
3483 const uint8_t *samples = pkt->data;
3484 const uint8_t *const end = pkt->data + pkt->size;
3485 int i;
3486
3488
3489 avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
3490 avio_wl16(pb, frame_size);
3491 avio_w8(pb, (1 << st->codecpar->ch_layout.nb_channels)-1);
3492
3493 while (samples < end) {
3494 for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) {
3495 uint32_t sample;
3497 sample = AV_RL24(samples)<< 4;
3498 samples += 3;
3499 } else {
3500 sample = AV_RL16(samples)<<12;
3501 samples += 2;
3502 }
3503 avio_wl32(pb, sample | i);
3504 }
3505 for (; i < 8; i++)
3506 avio_wl32(pb, i);
3507 }
3508}
3509
3511{
3512 MXFContext *mxf = s->priv_data;
3513 AVIOContext *pb = s->pb;
3514 AVStream *st = s->streams[0];
3515 MXFStreamContext *sc = st->priv_data;
3516 const uint8_t *key = NULL;
3517
3518 int err;
3519
3520 if (!mxf->header_written)
3522
3523 if ((err = mxf_write_partition(s, 1, 0, key, 0)) < 0)
3524 return err;
3527 // 8 byte BER length for clip wrapping, ST 381-3 7.2 and ST 382 6.5.5
3529 return 0;
3530}
3531
3532/**
3533 * OPAtom essence is written as a single clip wrapped KLV,
3534 * use the clip wrapping essence container label and element type.
3535 */
3537{
3538 AVStream *st = s->streams[0];
3539 MXFStreamContext *sc = st->priv_data;
3540 int wrapping_byte, element_type;
3541
3542 switch (st->codecpar->codec_id) {
3543 case AV_CODEC_ID_MPEG2VIDEO: // ST 381-1
3544 case AV_CODEC_ID_H264: // ST 381-3
3545 wrapping_byte = 15; element_type = 0x06; break;
3546 case AV_CODEC_ID_DVVIDEO: // ST 383
3547 wrapping_byte = 15; element_type = 0x02; break;
3548 case AV_CODEC_ID_DNXHD: // ST 2019-4
3549 wrapping_byte = 14; element_type = 0x0D; break;
3550 case AV_CODEC_ID_JPEG2000: // ST 422
3551 wrapping_byte = 14; element_type = 0x09; break;
3552 case AV_CODEC_ID_FFV1: // RDD 48
3553 wrapping_byte = 14; element_type = 0x1E; break;
3554 case AV_CODEC_ID_PCM_S16LE: // ST 382
3556 wrapping_byte = 14; element_type = 0x02; break;
3557 default:
3558 av_log(s, AV_LOG_ERROR, "%s has no clip wrapping essence container, not supported in OPAtom\n",
3560 return AVERROR_PATCHWELCOME;
3561 }
3562
3563 memcpy(sc->clip_container_ul, *sc->container_ul, 16);
3564 sc->clip_container_ul[wrapping_byte] = 0x02;
3566 sc->track_essence_element_key[14] = element_type;
3567 PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
3568 return 0;
3569}
3570
3572{
3573 MXFContext *mxf = s->priv_data;
3574 AVIOContext *pb = s->pb;
3575
3576 int err;
3577
3578 if (!mxf->header_written) {
3579 if ((err = mxf_opatom_clip_wrap(s)) < 0)
3580 return err;
3581
3582 if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)
3583 return err;
3585
3586 if ((err = mxf_write_opatom_body_partition(s)) < 0)
3587 return err;
3588 mxf->header_written = 1;
3589 }
3590
3591 if (!mxf->edit_unit_byte_count) {
3593 mxf->index_entries[mxf->edit_units_count].flags = ie->flags;
3595 }
3596 mxf->edit_units_count++;
3597 avio_write(pb, pkt->data, pkt->size);
3598 mxf->body_offset += pkt->size;
3599
3600 return 0;
3601}
3602
3604{
3605 MXFContext *mxf = s->priv_data;
3606 int i;
3607
3608 if (IS_OPATOM(s)) {
3609 MXFStreamContext *sc = s->streams[0]->priv_data;
3611 return;
3612 }
3613
3614 mxf->edit_unit_byte_count = KAG_SIZE; // system element
3615 for (i = 0; i < s->nb_streams; i++) {
3616 AVStream *st = s->streams[i];
3617 MXFStreamContext *sc = st->priv_data;
3619 // ANC packets have no fixed size, keep a KAG of payload plus the fill
3620 if (sc->index == INDEX_S436M)
3621 sc->element_size = mxf_element_size(KAG_SIZE - 16 - 4);
3622 else if (!sc->element_size)
3625 }
3626}
3627
3629{
3630 MXFContext *mxf = s->priv_data;
3631 AVIOContext *pb = s->pb;
3632 AVStream *st = s->streams[pkt->stream_index];
3633 MXFStreamContext *sc = st->priv_data;
3634 MXFIndexEntry ie = {0};
3635 int err, pad = 0;
3636
3637 if (!mxf->header_written && pkt->stream_index != 0 &&
3638 !IS_OPATOM(s)) {
3639 av_log(s, AV_LOG_ERROR, "Received non-video packet before "
3640 "header has been written\n");
3641 return AVERROR_INVALIDDATA;
3642 }
3643
3644 if (!mxf->cbr_index && !mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) {
3645 if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count
3646 + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) {
3647 mxf->edit_units_count = 0;
3648 av_log(s, AV_LOG_ERROR, "could not allocate index entries\n");
3649 return err;
3650 }
3651 }
3652
3654 if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {
3655 av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");
3656 return -1;
3657 }
3658 } else if (st->codecpar->codec_id == AV_CODEC_ID_DNXHD) {
3659 if (!mxf_parse_dnxhd_frame(s, st, pkt)) {
3660 av_log(s, AV_LOG_ERROR, "could not get dnxhd profile\n");
3661 return -1;
3662 }
3663 } else if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) {
3664 if (!mxf_parse_prores_frame(s, st, pkt)) {
3665 av_log(s, AV_LOG_ERROR, "could not get prores profile\n");
3666 return -1;
3667 }
3668 } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) {
3669 if (!mxf_parse_dv_frame(s, st, pkt)) {
3670 av_log(s, AV_LOG_ERROR, "could not get dv profile\n");
3671 return -1;
3672 }
3673 } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
3674 if (!mxf_parse_h264_frame(s, st, pkt, &ie)) {
3675 av_log(s, AV_LOG_ERROR, "could not get h264 profile\n");
3676 return -1;
3677 }
3678 } else if (st->codecpar->codec_id == AV_CODEC_ID_FFV1) {
3679 if (!mxf_parse_ffv1_frame(s, st, pkt)) {
3680 av_log(s, AV_LOG_ERROR, "could not get ffv1 version\n");
3681 return -1;
3682 }
3683 } else if (st->codecpar->codec_id == AV_CODEC_ID_JPEG2000) {
3684 if ((err = mxf_parse_jpeg2000_frame(s, st, pkt)) < 0)
3685 return err;
3686 }
3687
3688 // codecs without sequence headers: every key frame is a random access point
3692 pkt->flags & AV_PKT_FLAG_KEY)
3693 ie.flags |= 0x80;
3694
3695 if (mxf->cbr_index) {
3696 if (pkt->size != sc->frame_size && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
3697 av_log(s, AV_LOG_ERROR, "track %d: frame size does not match index unit size, %d != %d\n",
3698 st->index, pkt->size, sc->frame_size);
3699 return -1;
3700 }
3701 if (!mxf->header_written)
3703 }
3704
3705 if (IS_OPATOM(s))
3706 return mxf_write_opatom_packet(s, pkt, &ie);
3707
3708 if (!mxf->header_written) {
3709 if (mxf->edit_unit_byte_count) {
3710 if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0)
3711 return err;
3714 if (err < 0)
3715 return err;
3716 } else {
3717 if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)
3718 return err;
3719 }
3720 mxf->header_written = 1;
3721 }
3722
3723 if (st->index == 0) {
3724 if (!mxf->edit_unit_byte_count &&
3726 !(ie.flags & 0x33)) { // I-frame, GOP start
3728 if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0)
3729 return err;
3732 if (err < 0)
3733 return err;
3734 }
3735
3738
3739 if (!mxf->edit_unit_byte_count) {
3741 mxf->index_entries[mxf->edit_units_count].flags = ie.flags;
3743 mxf->body_offset += KAG_SIZE; // size of system element
3744 }
3745 mxf->edit_units_count++;
3746 } else if (!mxf->edit_unit_byte_count && st->index == 1) {
3747 if (!mxf->edit_units_count) {
3748 av_log(s, AV_LOG_ERROR, "No packets in first stream\n");
3749 return AVERROR_PATCHWELCOME;
3750 }
3753 }
3754
3755 // keep fill presence consistent across content packages, ST 379-2 8.3,
3756 // and pad to a constant element size
3757 if (sc->index != INDEX_D10_AUDIO) {
3758 unsigned element_size = sc->element_size ? sc->element_size : mxf_element_size(pkt->size);
3759 unsigned max_size = element_size - 2 * (16 + 4);
3760
3761 if (sc->element_size && sc->frame_size)
3762 max_size = FFMIN(max_size, sc->frame_size);
3763 if ((unsigned)pkt->size > max_size) {
3764 av_log(s, AV_LOG_ERROR, "track %d: packet size %d exceeds %u bytes per edit unit\n",
3765 st->index, pkt->size, max_size);
3766 return AVERROR(EINVAL);
3767 }
3768 pad = element_size - 16 - 4 - pkt->size;
3769 }
3770
3772 avio_write(pb, sc->track_essence_element_key, 16); // write key
3773 if (IS_D10(s) && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
3775 } else {
3776 klv_encode_ber4_length(pb, pkt->size); // write length
3777 avio_write(pb, pkt->data, pkt->size);
3778 mxf_write_fill(pb, pad);
3779 mxf->body_offset += 16 + 4 + (unsigned)pkt->size + pad;
3780 }
3781
3782 return 0;
3783}
3784
3786{
3787 MXFContext *mxf = s->priv_data;
3788 AVIOContext *pb = s->pb;
3789 uint64_t pos = avio_tell(pb);
3790 int i;
3791
3793 klv_encode_ber_length(pb, 28 + 12LL*mxf->body_partitions_count);
3794
3795 if (mxf->edit_unit_byte_count && !IS_OPATOM(s))
3796 avio_wb32(pb, 1); // BodySID of header partition
3797 else
3798 avio_wb32(pb, 0);
3799 avio_wb64(pb, 0); // offset of header partition
3800
3801 for (i = 0; i < mxf->body_partitions_count; i++) {
3802 avio_wb32(pb, 1); // BodySID
3804 }
3805
3806 avio_wb32(pb, 0); // BodySID of footer partition
3808
3809 avio_wb32(pb, avio_tell(pb) - pos + 4);
3810}
3811
3813{
3814 MXFContext *mxf = s->priv_data;
3815 AVIOContext *pb = s->pb;
3816 int i, err;
3817
3818 if (!mxf->header_written ||
3819 (IS_OPATOM(s) && !mxf->body_partition_offset)) {
3820 /* reason could be invalid options/not supported codec/out of memory */
3821 return AVERROR_UNKNOWN;
3822 }
3823
3824 if (IS_OPATOM(s) && mxf->body_offset >= (UINT64_C(1) << 56)) {
3825 av_log(s, AV_LOG_ERROR, "MXF OPAtom essence exceeds the 8-byte BER length limit\n");
3826 return AVERROR(EFBIG);
3827 }
3828
3830
3833 if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) { // no need to repeat index
3834 if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)
3835 return err;
3836 } else {
3837 if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0)
3838 return err;
3841 if (err < 0)
3842 return err;
3843 }
3844
3847
3848 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
3849 if (IS_OPATOM(s)) {
3850 /* rewrite body partition to update lengths */
3851 avio_seek(pb, mxf->body_partition_offset[0], SEEK_SET);
3852 if ((err = mxf_write_opatom_body_partition(s)) < 0)
3853 return err;
3854 }
3855
3856 avio_seek(pb, 0, SEEK_SET);
3857 if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) {
3858 if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0)
3859 return err;
3862 if (err < 0)
3863 return err;
3864 } else {
3865 if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0)
3866 return err;
3867 }
3868 // update footer partition offset
3869 for (i = 0; i < mxf->body_partitions_count; i++) {
3870 avio_seek(pb, mxf->body_partition_offset[i]+44, SEEK_SET);
3872 }
3873 }
3874
3875 return 0;
3876}
3877
3879{
3880 MXFContext *mxf = s->priv_data;
3881
3882 av_freep(&mxf->index_entries);
3884 av_freep(&mxf->timecode_track);
3886 av_packet_free(&mxf->anc_pkt);
3887}
3888
3890{
3891 FFFormatContext *const si = ffformatcontext(s);
3892 int i, stream_count = 0;
3893
3894 for (i = 0; i < s->nb_streams; i++)
3895 stream_count += !!ffstream(s->streams[i])->last_in_packet_buffer;
3896
3897 if (stream_count && (s->nb_streams == stream_count || flush)) {
3899 if (s->nb_streams != stream_count) {
3900 PacketListEntry *last = NULL;
3901 // find last packet in edit unit
3902 while (pktl) {
3903 if (!stream_count || pktl->pkt.stream_index == 0)
3904 break;
3905 // update last packet in packet buffer
3906 if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer != pktl)
3907 ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer = pktl;
3908 last = pktl;
3909 pktl = pktl->next;
3910 stream_count--;
3911 }
3912 // purge packet queue
3913 while (pktl) {
3914 PacketListEntry *next = pktl->next;
3915 av_packet_unref(&pktl->pkt);
3916 av_freep(&pktl);
3917 pktl = next;
3918 }
3919 if (last)
3920 last->next = NULL;
3921 else {
3922 si->packet_buffer.head = NULL;
3923 si->packet_buffer.tail = NULL;
3924 goto out;
3925 }
3926 pktl = si->packet_buffer.head;
3927 }
3928
3929 if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer == pktl)
3932 av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", out->stream_index, out->dts);
3933 return 1;
3934 } else {
3935 out:
3936 return 0;
3937 }
3938}
3939
3941 const AVPacket *pkt)
3942{
3943 MXFStreamContext *sc = s->streams[pkt ->stream_index]->priv_data;
3944 MXFStreamContext *sc2 = s->streams[next->stream_index]->priv_data;
3945
3946 return next->dts > pkt->dts ||
3947 (next->dts == pkt->dts && sc->order < sc2->order);
3948}
3949
3950/**
3951 * Every edit unit needs an ANC element: the queued ANC packets go in the
3952 * edit unit of their pts, and the edit units without one get an empty one.
3953 */
3955{
3956 MXFContext *mxf = s->priv_data;
3957 AVStream *st = s->streams[s->nb_streams - 1];
3958 MXFStreamContext *sc = st->priv_data;
3959 MXFStreamContext *video_sc = s->streams[0]->priv_data;
3960 AVPacket *pkt = mxf->anc_pkt;
3961 int64_t max_delay = s->max_interleave_delta > 0 ?
3962 av_rescale_q(s->max_interleave_delta, AV_TIME_BASE_Q, mxf->time_base) : INT64_MAX;
3963 int ret;
3964
3965 // the first displayed frame is among the first video_delay + 1 packets
3966 if (!flush && video_sc->pkt_cnt <= s->streams[0]->codecpar->video_delay)
3967 return 0;
3968 if (mxf->start_pts == AV_NOPTS_VALUE)
3969 mxf->start_pts = 0;
3970
3971 while (sc->pkt_cnt < video_sc->pkt_cnt) {
3972 PacketListEntry *pktl = mxf->anc_queue.head;
3973
3974 if (pktl && (pktl->pkt.pts == AV_NOPTS_VALUE ||
3975 av_rescale_q(pktl->pkt.pts, st->time_base, mxf->time_base) - mxf->start_pts <= sc->pkt_cnt)) {
3977 } else if (pktl || flush || video_sc->pkt_cnt - sc->pkt_cnt > max_delay) {
3978 if ((ret = av_new_packet(pkt, 2)) < 0)
3979 return ret;
3980 AV_WB16(pkt->data, 0); // number of ANC packets
3981 pkt->stream_index = st->index;
3982 } else // the ANC packet of this edit unit may still come
3983 break;
3984 pkt->pts = pkt->dts = sc->pkt_cnt++;
3986 return ret;
3987 }
3988 return 0;
3989}
3990
3992 int flush, int has_packet)
3993{
3994 MXFContext *mxf = s->priv_data;
3995 MXFStreamContext *video_sc = s->streams[0]->priv_data;
3996 MXFStreamContext *anc_sc = s->streams[s->nb_streams - 1]->priv_data;
3997 int has_anc = s->nb_streams > 1 && anc_sc->index == INDEX_S436M;
3998 int ret;
3999
4000 if (has_packet) {
4001 MXFStreamContext *sc = s->streams[pkt->stream_index]->priv_data;
4002
4003 if (has_anc && sc == anc_sc) {
4004 if ((ret = ff_packet_list_put(&mxf->anc_queue, pkt, NULL, 0)) < 0) {
4006 return ret;
4007 }
4008 } else {
4009 if (sc == video_sc && sc->pkt_cnt <= s->streams[0]->codecpar->video_delay &&
4010 pkt->pts != AV_NOPTS_VALUE &&
4011 (mxf->start_pts == AV_NOPTS_VALUE || pkt->pts < mxf->start_pts))
4012 mxf->start_pts = pkt->pts;
4013 pkt->pts = pkt->dts = sc->pkt_cnt++;
4015 return ret;
4016 }
4017 }
4018 if (has_anc && (ret = mxf_interleave_anc(s, flush)) < 0)
4019 return ret;
4021}
4022
4024{
4025 if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
4026 if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
4027 AV_RB24(pkt->data) != 0x000001)
4028 return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
4029 }
4030 return 1;
4031}
4032
4033#define MXF_COMMON_OPTIONS \
4034 { "signal_standard", "Force/set Signal Standard",\
4035 offsetof(MXFContext, signal_standard), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
4036 { "bt601", "ITU-R BT.601 and BT.656, also SMPTE 125M (525 and 625 line interlaced)",\
4037 0, AV_OPT_TYPE_CONST, {.i64 = 1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
4038 { "bt1358", "ITU-R BT.1358 and ITU-R BT.799-3, also SMPTE 293M (525 and 625 line progressive)",\
4039 0, AV_OPT_TYPE_CONST, {.i64 = 2}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
4040 { "smpte347m", "SMPTE 347M (540 Mbps mappings)",\
4041 0, AV_OPT_TYPE_CONST, {.i64 = 3}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
4042 { "smpte274m", "SMPTE 274M (1125 line)",\
4043 0, AV_OPT_TYPE_CONST, {.i64 = 4}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
4044 { "smpte296m", "SMPTE 296M (750 line progressive)",\
4045 0, AV_OPT_TYPE_CONST, {.i64 = 5}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
4046 { "smpte349m", "SMPTE 349M (1485 Mbps mappings)",\
4047 0, AV_OPT_TYPE_CONST, {.i64 = 6}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},\
4048 { "smpte428", "SMPTE 428-1 DCDM",\
4049 0, AV_OPT_TYPE_CONST, {.i64 = 7}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, .unit = "signal_standard"},
4050
4051
4052
4053static const AVOption mxf_options[] = {
4055 { "store_user_comments", "",
4056 offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
4057 { NULL },
4058};
4059
4060static const AVClass mxf_muxer_class = {
4061 .class_name = "MXF muxer",
4062 .item_name = av_default_item_name,
4063 .option = mxf_options,
4064 .version = LIBAVUTIL_VERSION_INT,
4065};
4066
4067static const AVOption d10_options[] = {
4068 { "d10_channelcount", "Force/set channelcount in generic sound essence descriptor",
4069 offsetof(MXFContext, channel_count), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 8, AV_OPT_FLAG_ENCODING_PARAM},
4071 { "store_user_comments", "",
4072 offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
4073 { NULL },
4074};
4075
4077 .class_name = "MXF-D10 muxer",
4078 .item_name = av_default_item_name,
4079 .option = d10_options,
4080 .version = LIBAVUTIL_VERSION_INT,
4081};
4082
4083static const AVOption opatom_options[] = {
4084 { "mxf_audio_edit_rate", "Audio edit rate for timecode",
4085 offsetof(MXFContext, audio_edit_rate), AV_OPT_TYPE_RATIONAL, {.dbl=25}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
4087 { "store_user_comments", "",
4088 offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
4089 { NULL },
4090};
4091
4093 .class_name = "MXF-OPAtom muxer",
4094 .item_name = av_default_item_name,
4095 .option = opatom_options,
4096 .version = LIBAVUTIL_VERSION_INT,
4097};
4098
4100 .p.name = "mxf",
4101 .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format)"),
4102 .p.mime_type = "application/mxf",
4103 .p.extensions = "mxf",
4104 .priv_data_size = sizeof(MXFContext),
4105 .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
4106 .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
4107 .p.subtitle_codec = AV_CODEC_ID_EIA_608,
4108 .init = mxf_init,
4109 .write_packet = mxf_write_packet,
4110 .write_trailer = mxf_write_footer,
4111 .deinit = mxf_deinit,
4112 .p.flags = AVFMT_NOTIMESTAMPS,
4113 .interleave_packet = mxf_interleave,
4114 .p.priv_class = &mxf_muxer_class,
4115 .check_bitstream = mxf_check_bitstream,
4116};
4117
4119 .p.name = "mxf_d10",
4120 .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) D-10 Mapping"),
4121 .p.mime_type = "application/mxf",
4122 .priv_data_size = sizeof(MXFContext),
4123 .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
4124 .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
4125 .init = mxf_init,
4126 .write_packet = mxf_write_packet,
4127 .write_trailer = mxf_write_footer,
4128 .deinit = mxf_deinit,
4129 .p.flags = AVFMT_NOTIMESTAMPS,
4130 .interleave_packet = mxf_interleave,
4131 .p.priv_class = &mxf_d10_muxer_class,
4132};
4133
4135 .p.name = "mxf_opatom",
4136 .p.long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) Operational Pattern Atom"),
4137 .p.mime_type = "application/mxf",
4138 .p.extensions = "mxf",
4139 .priv_data_size = sizeof(MXFContext),
4140 .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
4141 .p.video_codec = AV_CODEC_ID_DNXHD,
4142 .init = mxf_init,
4143 .write_packet = mxf_write_packet,
4144 .write_trailer = mxf_write_footer,
4145 .deinit = mxf_deinit,
4146 .p.flags = AVFMT_NOTIMESTAMPS,
4147 .interleave_packet = mxf_interleave,
4148 .p.priv_class = &mxf_opatom_muxer_class,
4149 .check_bitstream = mxf_check_bitstream,
4150};
const FFOutputFormat ff_mxf_muxer
Definition mxfenc.c:4099
const FFOutputFormat ff_mxf_opatom_muxer
Definition mxfenc.c:4134
const FFOutputFormat ff_mxf_d10_muxer
Definition mxfenc.c:4118
#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 void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition bytestream.h:174
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
static int64_t duration
Definition ffplay.c:359
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
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
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_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:657
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
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
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ 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 AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
#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_RL32(p)
#define AV_RB32(p)
#define AV_WB64(p, v)
#define AV_RL16(p)
#define AV_WB16(p, v)
#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:812
static void write_metadata(AVFormatContext *s, unsigned int ts)
Definition flvenc.c:298
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:392
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
void ff_packet_list_free(PacketList *list)
Wipe the list and unref all the packets in it.
int ff_packet_list_put(PacketList *list, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
Definition packet_list.c:40
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:98
version
Definition libkvazaar.c:313
#define FFMIN(a, b)
Definition macros.h:49
#define MKBETAG(a, b, c, d)
Definition macros.h:56
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
uint32_t tag
Definition movenc.c:2234
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:139
const MXFCodecUL ff_mxf_color_trc_uls[]
Definition mxf.c:114
int ff_mxf_get_content_package_rate(AVRational time_base)
Definition mxf.c:226
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:369
static int64_t mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key)
Definition mxfenc.c:1796
static const UID mxf_d10_container_uls[]
Definition mxfenc.c:270
static const MXFCodecUL * mxf_get_codec_ul_by_id(const MXFCodecUL *uls, int id)
Definition mxfenc.c:724
static const uint8_t header_metadata_key[]
partial key for header metadata
Definition mxfenc.c:310
static unsigned mxf_element_size(unsigned payload)
Definition mxfenc.c:2070
static unsigned klv_fill_size(uint64_t size)
Definition mxfenc.c:2059
static const uint8_t footer_partition_key[]
Definition mxfenc.c:297
#define PLATFORM_IDENT
Definition mxfenc.c:897
static const uint8_t opatom_ul[]
Definition mxfenc.c:296
static void mxf_write_identification(AVFormatContext *s)
Definition mxfenc.c:898
static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:1106
static const struct @372336353377014153333003247272374275277155076241 mxf_dv_uls[]
static int mxf_compare_timestamps(AVFormatContext *s, const AVPacket *next, const AVPacket *pkt)
Definition mxfenc.c:3940
static int mxf_write_mpegvideo_local_tags(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1712
static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flush)
Definition mxfenc.c:3889
static const char * color_name(const char *name)
Definition mxfenc.c:1250
static int mxf_write_opatom_body_partition(AVFormatContext *s)
Definition mxfenc.c:3510
static const UID mxf_generic_sound_descriptor_key
Definition mxfenc.c:1234
static void mxf_write_essence_container_refs(AVFormatContext *s)
Definition mxfenc.c:738
static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2585
static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational tbc)
Definition mxfenc.c:3116
static unsigned mxf_index_header_size(AVFormatContext *s)
Definition mxfenc.c:2115
static void mxf_write_refs_count(AVIOContext *pb, int ref_count)
Definition mxfenc.c:526
#define IS_D10(s)
Definition mxfenc.c:75
static const uint8_t uuid_base[]
Definition mxfenc.c:289
static int mxf_interleave_anc(AVFormatContext *s, int flush)
Every edit unit needs an ANC element: the queued ANC packets go in the edit unit of their pts,...
Definition mxfenc.c:3954
static int mxf_index_entry_size(AVFormatContext *s)
Definition mxfenc.c:2085
static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2424
static const struct @225240156112102161247264322247151334121242040336 mxf_essence_mappings[]
static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:1079
uint8_t interlaced
Definition mxfenc.c:2478
static int mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1705
static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2906
static int mxf_index_delta_count(AVFormatContext *s)
Definition mxfenc.c:2096
static const uint8_t klv_fill_key[]
Definition mxfenc.c:302
static void mxf_write_local_tag_utf16(AVFormatContext *s, int tag, const char *value)
Definition mxfenc.c:867
static int mxf_write_essence_container_data(AVFormatContext *s)
Definition mxfenc.c:1985
UID codec_ul
Definition mxfenc.c:2414
#define FFV1_CONTEXT_SIZE
Definition mxfenc.c:2827
static void mxf_write_track(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:978
ULIndex
Definition mxfenc.c:153
@ INDEX_JPEG2000
Definition mxfenc.c:161
@ INDEX_AES3
Definition mxfenc.c:155
@ INDEX_DNXHD
Definition mxfenc.c:160
@ INDEX_H264
Definition mxfenc.c:162
@ INDEX_DV
Definition mxfenc.c:159
@ INDEX_S436M
Definition mxfenc.c:163
@ INDEX_D10_AUDIO
Definition mxfenc.c:158
@ INDEX_PRORES
Definition mxfenc.c:164
@ INDEX_WAV
Definition mxfenc.c:156
@ INDEX_FFV1
Definition mxfenc.c:165
@ INDEX_MPEG2
Definition mxfenc.c:154
@ INDEX_D10_VIDEO
Definition mxfenc.c:157
static int get_ffv1_unsigned_symbol(RangeCoder *c, uint8_t *state)
Definition mxfenc.c:2806
static const UID mxf_rgba_descriptor_key
Definition mxfenc.c:305
static const UID mxf_ffv1_codec_uls[]
Definition mxfenc.c:280
static int mxf_get_essence_container_ul_index(enum AVCodecID id)
Definition mxfenc.c:574
static int klv_encode_ber_length(AVIOContext *pb, uint64_t len)
Definition mxfenc.c:540
static int mxf_index_slice_count(AVFormatContext *s)
Number of slices minus 1.
Definition mxfenc.c:2079
static void mxf_write_content_storage(AVFormatContext *s, MXFPackage *packages, int package_count)
Definition mxfenc.c:951
static void mxf_write_tape_descriptor(AVFormatContext *s)
Definition mxfenc.c:1141
static int mxf_index_max_entries(AVFormatContext *s)
Definition mxfenc.c:2091
static const UID mxf_mpegvideo_descriptor_key
Definition mxfenc.c:1230
static const uint8_t product_uid[]
Definition mxfenc.c:288
static const UID mxf_jpeg2000_subdescriptor_key
Definition mxfenc.c:1238
#define EDIT_UNITS_PER_BODY
Definition mxfenc.c:78
static uint64_t mxf_parse_timestamp(int64_t timestamp64)
Definition mxfenc.c:3088
static int mxf_write_index_table_segment(AVFormatContext *s)
Definition mxfenc.c:2213
static int mxf_write_user_comments(AVFormatContext *s, const AVDictionary *m)
Definition mxfenc.c:1863
static int mxf_write_package(AVFormatContext *s, MXFPackage *package)
Definition mxfenc.c:1881
static const AVOption mxf_options[]
Definition mxfenc.c:4053
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:317
static int mxf_check_frame_offset(AVFormatContext *s, int offset)
Definition mxfenc.c:2102
static const uint8_t system_metadata_package_set_key[]
Definition mxfenc.c:3426
static void klv_encode_ber4_length(AVIOContext *pb, int len)
Definition mxfenc.c:560
static const UID mxf_mpeg2_codec_uls[]
Definition mxfenc.c:2978
static const uint8_t header_closed_partition_key[]
Definition mxfenc.c:301
static const uint8_t primer_pack_key[]
Definition mxfenc.c:298
static uint32_t rescale_mastering_luma(AVRational q)
Definition mxfenc.c:1245
static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, MXFIndexEntry *e)
Definition mxfenc.c:3011
static int mxf_interleave(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
Definition mxfenc.c:3991
static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value)
Definition mxfenc.c:510
static const struct @117203202152267247126110227165170060075114153320 mxf_prores_codec_uls[]
static void mxf_write_common_fields(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1026
static const UID mxf_avc_subdescriptor_key
Definition mxfenc.c:1236
static int mxf_utf16_local_tag_length(const char *utf8_str)
Definition mxfenc.c:848
static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:3478
static void mxf_write_system_item(AVFormatContext *s)
Definition mxfenc.c:3428
int profile
Definition mxfenc.c:2413
static int mxf_write_aes3_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1818
static uint64_t mxf_utf16len(const char *utf8_str)
Definition mxfenc.c:826
static void mxf_deinit(AVFormatContext *s)
Definition mxfenc.c:3878
static int mxf_write_tagged_value(AVFormatContext *s, const char *name, const char *value)
Definition mxfenc.c:1834
static const AVClass mxf_muxer_class
Definition mxfenc.c:4060
static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, MXFIndexEntry *e)
Definition mxfenc.c:2678
static const AVOption d10_options[]
Definition mxfenc.c:4067
static int mxf_write_header_metadata_sets(AVFormatContext *s)
Definition mxfenc.c:2007
static void mxf_write_fill(AVIOContext *pb, unsigned size)
Definition mxfenc.c:2196
#define MXF_NUM_TAGS
Definition mxfenc.c:472
static const uint8_t index_table_segment_key[]
Definition mxfenc.c:299
static void mxf_write_operational_pattern(AVFormatContext *s)
Definition mxfenc.c:760
static int64_t mxf_write_generic_picture_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1255
static void mxf_write_umid(AVFormatContext *s, int type)
Definition mxfenc.c:517
static const uint8_t header_open_partition_key[]
Definition mxfenc.c:300
static const AVOption opatom_options[]
Definition mxfenc.c:4083
static const struct @213176060366221100351007056114013075347222044276 mxf_h264_codec_uls[]
UID uid
Definition mxfenc.c:2647
static const UID mxf_wav_descriptor_key
Definition mxfenc.c:1231
static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition mxfenc.c:3628
static const UID mxf_ffv1_subdescriptor_key
Definition mxfenc.c:1237
static int mxf_write_cdci_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1661
#define IS_OPATOM(s)
Definition mxfenc.c:76
static const struct @120164275265124234064020245000334222001022363076 mxf_dnxhd_codec_uls[]
static void mxf_write_ffv1_subdesc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1676
static void mxf_write_sequence(AVFormatContext *s, AVStream *st, MXFPackage *package)
Definition mxfenc.c:1052
static int mxf_init(AVFormatContext *s)
Definition mxfenc.c:3167
static void mxf_write_index_table_segment_header(AVFormatContext *s, int64_t start, int duration)
Definition mxfenc.c:2120
static const MXFLocalTagPair * mxf_lookup_local_tag(int tag)
Definition mxfenc.c:583
static int mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1825
const UID container_ul
Definition mxfenc.c:2560
static void mxf_update_klv_size(AVIOContext *pb, int64_t pos)
Definition mxfenc.c:1570
static uint16_t rescale_mastering_chroma(AVRational q)
Definition mxfenc.c:1240
static const UID mxf_d10_codec_uls[]
Definition mxfenc.c:261
static const UID mxf_aes3_descriptor_key
Definition mxfenc.c:1232
#define KAG_SIZE
Definition mxfenc.c:79
static int mxf_write_wav_desc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1811
static void mxf_write_random_index_pack(AVFormatContext *s)
Definition mxfenc.c:3785
static int mxf_jp2_find_codestream(GetByteContext *g)
Definition mxfenc.c:2881
static int64_t mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const UID key)
Definition mxfenc.c:1191
static const uint8_t system_metadata_pack_key[]
Definition mxfenc.c:3425
static const uint8_t op1a_ul[]
complete key for operation pattern, partitions, and primer pack
Definition mxfenc.c:295
static const MXFContainerEssenceEntry mxf_essence_container_uls[]
Definition mxfenc.c:197
int8_t intra_only
Definition mxfenc.c:2651
static void mxf_mark_tag_unused(MXFContext *mxf, int tag)
Definition mxfenc.c:596
static void mxf_write_local_tag(AVFormatContext *s, int size, int tag)
Definition mxfenc.c:705
static enum AVChromaLocation choose_chroma_location(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:3140
static const uint8_t smpte_12m_timecode_track_data_ul[]
Definition mxfenc.c:1024
static void mxf_gen_umid(AVFormatContext *s)
Definition mxfenc.c:3104
static int mxf_write_jpeg2000_subdesc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1603
static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2503
static const UID * mxf_get_mpeg2_codec_ul(AVCodecParameters *par)
Definition mxfenc.c:2991
static int mxf_write_partition(AVFormatContext *s, int bodysid, int indexsid, const uint8_t *key, int write_metadata)
Definition mxfenc.c:2306
#define DESCRIPTOR_COUNT(essence_container_count)
Definition mxfenc.c:735
static void mxf_write_primer_pack(AVFormatContext *s)
Definition mxfenc.c:602
static void mxf_write_preface(AVFormatContext *s)
Definition mxfenc.c:774
static int64_t mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, const UID key)
Definition mxfenc.c:1747
static const AVClass mxf_opatom_muxer_class
Definition mxfenc.c:4092
static const UID mxf_s436m_anc_descriptor_key
Definition mxfenc.c:1229
static void mxf_write_metadata_key(AVIOContext *pb, unsigned int value)
Definition mxfenc.c:718
static void store_version(AVFormatContext *s)
Definition mxfenc.c:881
static void mxf_write_multi_descriptor(AVFormatContext *s)
Definition mxfenc.c:1154
static void klv_encode_ber8_length(AVIOContext *pb, uint64_t len)
Definition mxfenc.c:566
static void mxf_write_avc_subdesc(AVFormatContext *s, AVStream *st)
Definition mxfenc.c:1579
static int mxf_write_footer(AVFormatContext *s)
Definition mxfenc.c:3812
uint16_t cid
Definition mxfenc.c:2477
static int mxf_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
Definition mxfenc.c:4023
static const uint8_t multiple_desc_ul[]
Definition mxfenc.c:311
#define MXF_COMMON_OPTIONS
Definition mxfenc.c:4033
static void mxf_compute_edit_unit_byte_count(AVFormatContext *s)
Definition mxfenc.c:3603
static const uint8_t umid_ul[]
Definition mxfenc.c:290
static int klv_ber_length(uint64_t len)
Definition mxfenc.c:532
static int mxf_parse_ffv1_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mxfenc.c:2828
static int mxf_write_opatom_packet(AVFormatContext *s, AVPacket *pkt, MXFIndexEntry *ie)
Definition mxfenc.c:3571
static const UID mxf_cdci_descriptor_key
Definition mxfenc.c:1233
static const uint8_t body_partition_key[]
Definition mxfenc.c:303
static void mxf_write_klv_fill(AVFormatContext *s)
Definition mxfenc.c:2204
static int mxf_opatom_clip_wrap(AVFormatContext *s)
OPAtom essence is written as a single clip wrapped KLV, use the clip wrapping essence container label...
Definition mxfenc.c:3536
static const AVClass mxf_d10_muxer_class
Definition mxfenc.c:4076
const uint8_t * ff_nal_find_startcode(const uint8_t *p, const uint8_t *end)
Definition nal.c:68
AVOptions.
const char * av_color_space_name(enum AVColorSpace space)
Definition pixdesc.c:3884
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition pixdesc.c:3851
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition pixdesc.c:3818
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
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
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
AVColorRange
Visual content value range.
Definition pixfmt.h:757
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:775
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:758
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:792
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:647
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:650
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition pixfmt.h:658
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:677
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition pixfmt.h:684
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition pixfmt.h:693
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition pixfmt.h:692
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:680
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:679
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:711
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:713
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition pixfmt.h:723
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:712
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition pixfmt.h:722
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
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
static int time_code(const uint8_t *tc)
Definition sacddec.c:177
#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 pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition packet.h:603
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:143
int64_t footer_partition_offset
Definition mxfenc.c:476
uint32_t tagged_value_count
Definition mxfenc.c:498
int last_indexed_edit_unit
Definition mxfenc.c:483
uint64_t * body_partition_offset
Definition mxfenc.c:484
uint8_t unused_tags[MXF_NUM_TAGS]
local tags that we know will not be used
Definition mxfenc.c:503
int store_user_comments
Definition mxfenc.c:500
uint64_t duration
Definition mxfenc.c:487
AVPacket * anc_pkt
Definition mxfenc.c:506
int signal_standard
Definition mxfenc.c:497
unsigned body_partitions_count
Definition mxfenc.c:485
AVClass * av_class
Definition mxfenc.c:475
AVStream * timecode_track
Definition mxfenc.c:489
MXFIndexEntry * index_entries
Definition mxfenc.c:480
AVRational audio_edit_rate
Definition mxfenc.c:499
int cbr_index
use a constant bitrate index
Definition mxfenc.c:502
uint32_t instance_number
Definition mxfenc.c:494
AVRational time_base
Definition mxfenc.c:478
AVTimecode tc
timecode context
Definition mxfenc.c:488
int edit_unit_byte_count
fixed edit unit byte count
Definition mxfenc.c:491
int track_instance_count
Definition mxfenc.c:501
uint64_t body_offset
Definition mxfenc.c:493
int timecode_base
rounded time code base (25 or 30)
Definition mxfenc.c:490
int content_package_rate
content package rate in system element, see SMPTE 326M
Definition mxfenc.c:492
uint8_t umid[16]
unique material identifier
Definition mxfenc.c:495
int header_written
Definition mxfenc.c:479
PacketList anc_queue
ANC packets not yet assigned to an edit unit.
Definition mxfenc.c:505
int channel_count
Definition mxfenc.c:496
uint64_t timestamp
timestamp, as year(16),month(8),day(8),hour(8),minutes(8),msec/4(8)
Definition mxfenc.c:482
int last_key_index
index of last key frame
Definition mxfenc.c:486
unsigned edit_units_count
Definition mxfenc.c:481
int essence_container_count
Definition mxfenc.c:477
MXFStreamContext timecode_track_priv
Definition mxfenc.c:504
int64_t start_pts
pts of the first displayed video frame
Definition mxfenc.c:507
unsigned slice_offset
offset of audio slice
Definition mxfenc.c:83
uint64_t offset
Definition mxfenc.c:82
uint8_t flags
Definition mxfenc.c:85
uint16_t temporal_ref
Definition mxfenc.c:84
struct MXFPackage * ref
Definition mxfenc.c:150
enum MXFMetadataSetType type
Definition mxfenc.c:148
int instance
Definition mxfenc.c:149
char * name
Definition mxfdec.c:289
int max_gop
maximum gop size, used by mpeg-2 descriptor
Definition mxfenc.c:122
int temporal_reordering
Definition mxfenc.c:114
enum MXFMetadataSetType sub_descriptor
Definition mxfenc.c:128
UID clip_container_ul
clip wrapping essence container ul, used by OPAtom
Definition mxfenc.c:108
int version
format version, used in ffv1 descriptor
Definition mxfenc.c:125
enum AVColorRange color_range
Definition mxfenc.c:136
int cid
compression id, used by dnxhd
Definition mxfenc.c:130
int index
index in mxf_essence_container_uls table
Definition mxfenc.c:105
int closed_gop
gop is closed, used in mpeg-2 frame parsing
Definition mxfenc.c:116
int element_size
KAG aligned element size, constant for PCM and CBE.
Definition mxfenc.c:120
UID track_essence_element_key
Definition mxfenc.c:104
const UID * codec_ul
Definition mxfenc.c:106
int field_dominance
first field in temporal order, 1 or 2
Definition mxfenc.c:111
int low_delay
low delay, used in mpeg-2 descriptor
Definition mxfenc.c:124
int micro_version
format micro_version, used in ffv1 descriptor
Definition mxfenc.c:126
int frame_size
frame size in bytes
Definition mxfenc.c:119
AVRational aspect_ratio
display aspect ratio
Definition mxfenc.c:115
enum AVColorSpace color_space
Definition mxfenc.c:135
int seq_closed_gop
all gops in sequence are closed, used in mpeg-2 descriptor
Definition mxfenc.c:121
int order
interleaving order if dts are equal
Definition mxfenc.c:109
enum AVColorTransferCharacteristic color_trc
Definition mxfenc.c:134
int64_t pkt_cnt
pkt counter for muxed packets
Definition mxfenc.c:103
int interlaced
whether picture is interlaced
Definition mxfenc.c:110
j2k_info_t j2k_info
Definition mxfenc.c:127
const UID * picture_descriptor_key
Definition mxfenc.c:129
int signal_standard
Definition mxfenc.c:113
enum AVColorPrimaries color_primaries
Definition mxfenc.c:133
int color_warned
unsupported color properties have been reported
Definition mxfenc.c:131
int display_f2_offset
DisplayF2Offset, 0 or -1.
Definition mxfenc.c:112
int b_picture_count
maximum number of consecutive b pictures, used in mpeg-2 descriptor
Definition mxfenc.c:123
const UID * container_ul
Definition mxfenc.c:107
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:99
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_csiz
number of coded components (Csiz)
Definition mxfenc.c:98
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
Definition rpzaenc.c:60
#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]