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