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