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