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