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