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