60 #define MXF_MAX_CHUNK_SIZE (32 << 20)
194 #define MXF_FIELD_DOMINANCE_DEFAULT 0
195 #define MXF_FIELD_DOMINANCE_FF 1
196 #define MXF_FIELD_DOMINANCE_FL 2
308 static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
309 static const uint8_t mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 };
310 static const uint8_t mxf_avid_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0e,0x04,0x03,0x01 };
311 static const uint8_t mxf_canopus_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x0a,0x0e,0x0f,0x03,0x01 };
312 static const uint8_t mxf_system_item_key_cp[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x03,0x01,0x04 };
313 static const uint8_t mxf_system_item_key_gc[] = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x03,0x01,0x14 };
316 static const uint8_t mxf_crypto_source_container_ul[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 };
317 static const uint8_t mxf_encrypted_triplet_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 };
318 static const uint8_t mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 };
319 static const uint8_t mxf_random_index_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x11,0x01,0x00 };
320 static const uint8_t mxf_sony_mpeg4_extradata[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 };
321 static const uint8_t mxf_avid_project_name[] = { 0xa5,0xfb,0x7b,0x25,0xf6,0x15,0x94,0xb9,0x62,0xfc,0x37,0x17,0x49,0x2d,0x42,0xbf };
322 static const uint8_t mxf_jp2k_rsiz[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 };
323 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 };
324 static const uint8_t mxf_indirect_value_utf16be[] = { 0x42,0x01,0x10,0x02,0x00,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 };
326 #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
331 switch ((*ctx)->type) {
374 int bytes_num =
size & 0x7f;
382 if (
size > INT64_MAX)
394 else if (
b !=
key[
i])
413 if (
pos > INT64_MAX - length)
423 for (
i = 0;
i <
s->nb_streams;
i++) {
430 return s->nb_streams == 1 &&
s->streams[0]->priv_data ? 0 : -1;
459 int cdp_identifier, cdp_length, cdp_footer_id, ccdata_id, cc_count;
460 int line_num, sample_coding, sample_count;
461 int did, sdid, data_length;
467 for (
i = 0;
i < count;
i++) {
476 length -= 6 + 8 + sample_count;
477 if (line_num != 9 && line_num != 11)
479 if (sample_coding == 7 || sample_coding == 8 || sample_coding == 9) {
491 if (did != 0x61 || sdid != 1) {
496 if (cdp_identifier != 0x9669) {
505 if (ccdata_id != 0x72) {
513 if (cdp_length - 9 - 4 < cc_count * 3) {
517 avio_skip(
s->pb, data_length - 9 - 4 - cc_count * 3);
519 if (cdp_footer_id != 0x74) {
534 const uint8_t *buf_ptr, *end_ptr;
548 uint32_t
sample = bytestream_get_le32(&buf_ptr);
550 bytestream_put_le24(&data_ptr, (
sample >> 4) & 0xffffff);
552 bytestream_put_le16(&data_ptr, (
sample >> 12) & 0xffff);
562 static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b};
568 uint64_t plaintext_size;
574 if (!mxf->
aesc &&
s->key &&
s->keylen == 16) {
601 if (orig_size < plaintext_size)
605 if (
size < 32 ||
size - 32 < orig_size)
611 if (memcmp(tmpbuf, checkv, 16))
617 else if (
size < plaintext_size)
619 size -= plaintext_size;
635 if (item_len != 18) {
639 if (item_num > 65536 || item_num < 0) {
661 uint64_t footer_partition;
662 uint32_t nb_essence_containers;
684 memset(partition, 0,
sizeof(*partition));
732 "PreviousPartition equal to ThisPartition %"PRIx64
"\n",
745 "Overriding PreviousPartition with %"PRIx64
"\n",
750 if (footer_partition) {
753 "inconsistent FooterPartition value: %"PRIu64
" != %"PRIu64
"\n",
761 "PartitionPack: ThisPartition = 0x%"PRIX64
762 ", PreviousPartition = 0x%"PRIX64
", "
763 "FooterPartition = 0x%"PRIX64
", IndexSID = %i, BodySID = %i\n",
773 "PreviousPartition points to this partition or forward\n");
777 if (
op[12] == 1 &&
op[13] == 1) mxf->
op =
OP1a;
778 else if (
op[12] == 1 &&
op[13] == 2) mxf->
op =
OP1b;
779 else if (
op[12] == 1 &&
op[13] == 3) mxf->
op =
OP1c;
780 else if (
op[12] == 2 &&
op[13] == 1) mxf->
op =
OP2a;
781 else if (
op[12] == 2 &&
op[13] == 2) mxf->
op =
OP2b;
782 else if (
op[12] == 2 &&
op[13] == 3) mxf->
op =
OP2c;
783 else if (
op[12] == 3 &&
op[13] == 1) mxf->
op =
OP3a;
784 else if (
op[12] == 3 &&
op[13] == 2) mxf->
op =
OP3b;
785 else if (
op[12] == 3 &&
op[13] == 3) mxf->
op =
OP3c;
787 else if (
op[12] == 0x10) {
792 if (nb_essence_containers != 1) {
798 "\"OPAtom\" with %"PRIu32
" ECs - assuming %s\n",
799 nb_essence_containers,
800 op ==
OP1a ?
"OP1a" :
"OPAtom");
866 if (size < 0 || size > INT_MAX/2)
888 #define READ_STR16(type, big_endian) \
889 static int mxf_read_utf16 ## type ##_string(AVIOContext *pb, int size, char** str) \
891 return mxf_read_utf16_string(pb, size, str, big_endian); \
974 mxf_read_utf16be_string(pb,
size, &track->
name);
1027 &package->tracks_count);
1031 avio_read(pb, package->package_uid, 16);
1034 avio_read(pb, package->descriptor_ref, 16);
1037 return mxf_read_utf16be_string(pb,
size, &package->name);
1040 &package->comment_count);
1071 if(
segment->nb_index_entries && length < 11)
1082 for (
i = 0;
i <
segment->nb_index_entries;
i++) {
1117 segment->index_edit_rate.den);
1146 }
while (
code != 0);
1154 int entry_count, entry_size;
1187 if (entry_size == 4) {
1188 if (entry_count > 0)
1192 if (entry_count > 1)
1266 return mxf_read_utf16le_string(pb,
size - 17, &tagged_value->
value);
1268 return mxf_read_utf16be_string(pb,
size - 17, &tagged_value->
value);
1278 return mxf_read_utf16be_string(pb,
size, &tagged_value->
name);
1292 for (
i = 0;
i <
len;
i++) {
1301 while (uls->
uid[0]) {
1326 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c,0x01,0x00 }, 14,
AV_CODEC_ID_JPEG2000,
NULL, 14 },
1327 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x10,0x60,0x01 }, 14,
AV_CODEC_ID_H264,
NULL, 15 },
1328 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 }, 14,
AV_CODEC_ID_DNXHD,
NULL, 14 },
1329 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x12,0x01,0x00 }, 14,
AV_CODEC_ID_VC1,
NULL, 14 },
1330 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x14,0x01,0x00 }, 14,
AV_CODEC_ID_TIFF,
NULL, 14 },
1331 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x15,0x01,0x00 }, 14,
AV_CODEC_ID_DIRAC,
NULL, 14 },
1332 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x1b,0x01,0x00 }, 14,
AV_CODEC_ID_CFHD,
NULL, 14 },
1333 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x1c,0x01,0x00 }, 14,
AV_CODEC_ID_PRORES,
NULL, 14 },
1334 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, 14,
AV_CODEC_ID_MPEG2VIDEO,
NULL, 15 },
1335 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, 14,
AV_CODEC_ID_MPEG2VIDEO,
NULL, 15,
D10D11Wrap },
1336 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, 14,
AV_CODEC_ID_DVVIDEO,
NULL, 15 },
1337 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x05,0x00,0x00 }, 14,
AV_CODEC_ID_RAWVIDEO,
NULL, 15,
RawVWrap },
1338 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0a,0x0e,0x0f,0x03,0x01,0x02,0x20,0x01,0x01 }, 15,
AV_CODEC_ID_HQ_HQA },
1339 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0a,0x0e,0x0f,0x03,0x01,0x02,0x20,0x02,0x01 }, 15,
AV_CODEC_ID_HQX },
1340 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0a,0x0e,0x15,0x00,0x04,0x02,0x10,0x00,0x01 }, 16,
AV_CODEC_ID_HEVC,
NULL, 15 },
1341 { { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0xff,0x4b,0x46,0x41,0x41,0x00,0x0d,0x4d,0x4f }, 14,
AV_CODEC_ID_RAWVIDEO },
1342 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1347 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x00,0x00 }, 14,
AV_CODEC_ID_MPEG2VIDEO },
1348 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1353 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14,
AV_CODEC_ID_H264 },
1354 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, 14,
AV_CODEC_ID_JPEG2000 },
1355 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1360 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x01 }, 16, 1440 },
1361 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x02 }, 16, 1440 },
1362 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x03 }, 16, 1440 },
1363 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x04 }, 16, 1440 },
1364 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, 0 },
1369 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, 14,
AV_CODEC_ID_PCM_S16LE,
NULL, 14,
RawAWrap },
1370 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, 14,
AV_CODEC_ID_MP2,
NULL, 15 },
1371 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, 14,
AV_CODEC_ID_PCM_S16LE,
NULL, 13 },
1372 { { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0xff,0x4b,0x46,0x41,0x41,0x00,0x0d,0x4d,0x4F }, 14,
AV_CODEC_ID_PCM_S16LE },
1373 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x03,0x04,0x02,0x02,0x02,0x03,0x03,0x01,0x00 }, 14,
AV_CODEC_ID_AAC },
1374 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1378 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x09,0x0d,0x01,0x03,0x01,0x02,0x0d,0x00,0x00 }, 16,
AV_CODEC_ID_NONE,
"vbi_smpte_436M", 11 },
1379 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x09,0x0d,0x01,0x03,0x01,0x02,0x0e,0x00,0x00 }, 16,
AV_CODEC_ID_NONE,
"vbi_vanc_smpte_436M", 11 },
1380 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x09,0x0d,0x01,0x03,0x01,0x02,0x13,0x01,0x01 }, 16,
AV_CODEC_ID_TTML },
1381 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1397 val = (*essence_container_ul)[
codec_ul->wrapping_indicator_pos];
1398 switch (
codec_ul->wrapping_indicator_type) {
1403 if (
val == 0x03 ||
val == 0x04)
1420 int i, j, nb_segments = 0;
1422 int last_body_sid = -1, last_index_sid = -1, last_index_start = -1;
1432 if (!(unsorted_segments =
av_calloc(nb_segments,
sizeof(*unsorted_segments))) ||
1433 !(*sorted_segments =
av_calloc(nb_segments,
sizeof(**sorted_segments)))) {
1442 if (
s->edit_unit_byte_count ||
s->nb_index_entries)
1443 unsorted_segments[nb_segments++] =
s;
1445 av_log(mxf->
fc,
AV_LOG_WARNING,
"IndexSID %i segment at %"PRId64
" missing EditUnitByteCount and IndexEntryArray\n",
1446 s->index_sid,
s->index_start_position);
1456 *nb_sorted_segments = 0;
1459 for (
i = 0;
i < nb_segments;
i++) {
1460 int best = -1, best_body_sid = -1, best_index_sid = -1, best_index_start = -1;
1461 uint64_t best_index_duration = 0;
1463 for (j = 0; j < nb_segments; j++) {
1471 s->body_sid > last_body_sid ||
1472 s->body_sid == last_body_sid &&
s->index_sid > last_index_sid ||
1473 s->body_sid == last_body_sid &&
s->index_sid == last_index_sid &&
s->index_start_position > last_index_start) &&
1475 s->body_sid < best_body_sid ||
1476 s->body_sid == best_body_sid &&
s->index_sid < best_index_sid ||
1477 s->body_sid == best_body_sid &&
s->index_sid == best_index_sid &&
s->index_start_position < best_index_start ||
1478 s->body_sid == best_body_sid &&
s->index_sid == best_index_sid &&
s->index_start_position == best_index_start &&
s->index_duration > best_index_duration)) {
1480 best_body_sid =
s->body_sid;
1481 best_index_sid =
s->index_sid;
1482 best_index_start =
s->index_start_position;
1483 best_index_duration =
s->index_duration;
1491 (*sorted_segments)[(*nb_sorted_segments)++] = unsorted_segments[best];
1492 last_body_sid = best_body_sid;
1493 last_index_sid = best_index_sid;
1494 last_index_start = best_index_start;
1517 m0 = m = (
a +
b) >> 1;
1519 while (m < b && mxf->partitions[m].body_sid != body_sid)
1522 if (m < b && mxf->partitions[m].body_offset <=
offset)
1534 *partition_out = last_p;
1539 "failed to find absolute offset of %"PRIX64
" in BodySID %i - partial file?\n",
1569 int64_t offset_temp = 0;
1576 edit_unit =
FFMAX(edit_unit,
s->index_start_position);
1578 if (edit_unit < s->index_start_position +
s->index_duration) {
1579 int64_t
index = edit_unit -
s->index_start_position;
1581 if (
s->edit_unit_byte_count)
1582 offset_temp +=
s->edit_unit_byte_count *
index;
1584 if (
s->nb_index_entries == 2 *
s->index_duration + 1)
1587 if (index < 0 || index >=
s->nb_index_entries) {
1593 offset_temp =
s->stream_offset_entries[
index];
1597 *edit_unit_out =
av_rescale_q(edit_unit, edit_rate,
s->index_edit_rate);
1602 offset_temp +=
s->edit_unit_byte_count *
s->index_duration;
1615 int8_t max_temporal_offset = -128;
1622 if (!
s->nb_index_entries) {
1627 if (
s->index_duration > INT_MAX -
index_table->nb_ptses) {
1684 int index_delta = 1;
1685 int n =
s->nb_index_entries;
1687 if (
s->nb_index_entries == 2 *
s->index_duration + 1) {
1693 for (j = 0; j < n; j += index_delta,
x++) {
1694 int offset =
s->temporal_offset_entries[j] / index_delta;
1699 "x >= nb_ptses - IndexEntryCount %i < IndexDuration %"PRId64
"?\n",
1700 s->nb_index_entries,
s->index_duration);
1706 if (index < 0 || index >=
index_table->nb_ptses) {
1708 "index entry %i + TemporalOffset %i = %i, which is out of bounds\n",
1715 max_temporal_offset =
FFMAX(max_temporal_offset,
offset);
1738 int i, j, k,
ret, nb_sorted_segments;
1742 nb_sorted_segments <= 0) {
1748 for (
i = 0;
i < nb_sorted_segments;
i++) {
1749 if (
i == 0 || sorted_segments[
i-1]->index_sid != sorted_segments[
i]->index_sid)
1751 else if (sorted_segments[
i-1]->body_sid != sorted_segments[
i]->body_sid) {
1754 goto finish_decoding_index;
1763 goto finish_decoding_index;
1767 for (
i = j = 0;
i < nb_sorted_segments;
i++) {
1768 if (
i != 0 && sorted_segments[
i-1]->index_sid != sorted_segments[
i]->index_sid) {
1785 " pointer array\n");
1787 goto finish_decoding_index;
1790 if (sorted_segments[
i]->index_start_position)
1791 av_log(mxf->
fc,
AV_LOG_WARNING,
"IndexSID %i starts at EditUnit %"PRId64
" - seeking may not work as expected\n",
1799 goto finish_decoding_index;
1822 av_log(mxf->
fc,
AV_LOG_WARNING,
"IndexSID %i segment %i has zero IndexDuration and there's more than one segment\n",
1839 finish_decoding_index:
1859 for (
i = 0;
i <
sizeof(
UID);
i++) {
1862 if (
i == 3 ||
i == 5 ||
i == 7 ||
i == 9) {
1879 for (
i = 0;
i <
sizeof(
UID);
i++) {
1884 for (
i = 0;
i <
sizeof(
UID);
i++) {
1920 switch (component->
type) {
1938 package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[i], SourcePackage);
1942 if (!memcmp(package->package_ul, package_ul, 16) && !memcmp(package->package_uid, package_uid, 16))
1960 if (!sub_descriptor) {
1965 return sub_descriptor;
2008 switch (component->
type) {
2048 int64_t start_position;
2061 if (physical_package->
name && physical_package->
name[0])
2081 "Invalid edit rate (%d/%d) found on structural"
2082 " component #%d, defaulting to 25/1\n",
2156 if (material_package)
break;
2158 if (!material_package) {
2164 if (material_package->
name && material_package->
name[0])
2176 UID *essence_container_ul =
NULL;
2226 if (!source_package) {
2237 source_track = temp_track;
2241 if (!source_track) {
2260 if(source_track && component)
2263 if (!source_track || !component || !source_package) {
2307 "Invalid edit rate (%d/%d) found on stream #%d, "
2308 "defaulting to 25/1\n",
2340 essence_container_ul = &((
MXFCryptoContext *)metadata)->source_container_ul;
2356 for (k = 0; k < 16; k++) {
2359 if (!(k+1 & 19) || k == 5)
2365 if (source_package->
name && source_package->
name[0])
2367 if (material_track->
name && material_track->
name[0])
2415 "Field dominance %d support",
2429 "Field dominance %d support",
2494 "found for stream #%d, time base forced to 1/48000\n",
2568 "with different wrapping\n",
i, j, track1->
body_sid);
2581 struct tm time = { 0 };
2583 time.tm_year = (timestamp >> 48) - 1900;
2584 time.tm_mon = (timestamp >> 40 & 0xFF) - 1;
2585 time.tm_mday = (timestamp >> 32 & 0xFF);
2586 time.tm_hour = (timestamp >> 24 & 0xFF);
2587 time.tm_min = (timestamp >> 16 & 0xFF);
2588 time.tm_sec = (timestamp >> 8 & 0xFF);
2589 msecs = (timestamp & 0xFF) * 4;
2592 time.tm_mon = av_clip(time.tm_mon, 0, 11);
2593 time.tm_mday = av_clip(time.tm_mday, 1, 31);
2594 time.tm_hour = av_clip(time.tm_hour, 0, 23);
2595 time.tm_min = av_clip(time.tm_min, 0, 59);
2596 time.tm_sec = av_clip(time.tm_sec, 0, 59);
2597 msecs = av_clip(msecs, 0, 999);
2599 return (int64_t)
av_timegm(&time) * 1000000 + msecs * 1000;
2602 #define SET_STR_METADATA(pb, name, str) do { \
2603 if ((ret = mxf_read_utf16be_string(pb, size, &str)) < 0) \
2605 av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
2608 #define SET_UID_METADATA(pb, name, var, str) do { \
2609 avio_read(pb, var, 16); \
2610 if ((ret = mxf_uid_to_str(var, &str)) < 0) \
2612 av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
2615 #define SET_TS_METADATA(pb, name, var, str) do { \
2616 var = avio_rb64(pb); \
2617 if (var && (ret = avpriv_dict_set_timestamp(&s->metadata, name, mxf_timestamp_to_int64(var))) < 0) \
2672 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 },
mxf_read_primer_pack },
2673 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 },
mxf_read_partition_pack },
2674 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x02,0x00 },
mxf_read_partition_pack },
2675 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x03,0x00 },
mxf_read_partition_pack },
2676 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x04,0x00 },
mxf_read_partition_pack },
2677 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x01,0x00 },
mxf_read_partition_pack },
2678 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x02,0x00 },
mxf_read_partition_pack },
2679 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x03,0x00 },
mxf_read_partition_pack },
2680 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x04,0x00 },
mxf_read_partition_pack },
2681 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x02,0x00 },
mxf_read_partition_pack },
2682 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x04,0x00 },
mxf_read_partition_pack },
2683 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2f,0x00 },
mxf_read_preface_metadata },
2684 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x30,0x00 },
mxf_read_identification_metadata },
2685 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 },
mxf_read_content_storage, 0,
AnyType },
2686 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 },
mxf_read_package,
sizeof(
MXFPackage),
SourcePackage },
2687 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 },
mxf_read_package,
sizeof(
MXFPackage),
MaterialPackage },
2688 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0f,0x00 },
mxf_read_sequence,
sizeof(
MXFSequence),
Sequence },
2689 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x05,0x00 },
mxf_read_essence_group,
sizeof(
MXFEssenceGroup),
EssenceGroup},
2690 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 },
mxf_read_source_clip,
sizeof(
MXFStructuralComponent),
SourceClip },
2691 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3f,0x00 },
mxf_read_tagged_value,
sizeof(
MXFTaggedValue),
TaggedValue },
2692 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
MultipleDescriptor },
2693 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2694 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2695 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2696 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2697 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2698 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2699 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5b,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2700 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2701 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5e,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2702 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x64,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2703 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 },
mxf_read_track,
sizeof(
MXFTrack),
Track },
2704 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 },
mxf_read_track,
sizeof(
MXFTrack),
Track },
2705 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x14,0x00 },
mxf_read_timecode_component,
sizeof(
MXFTimecodeComponent),
TimecodeComponent },
2706 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0c,0x00 },
mxf_read_pulldown_component,
sizeof(
MXFPulldownComponent),
PulldownComponent },
2707 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x04,0x01,0x02,0x02,0x00,0x00 },
mxf_read_cryptographic_context,
sizeof(
MXFCryptoContext),
CryptoContext },
2708 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 },
mxf_read_index_table_segment,
sizeof(
MXFIndexTableSegment),
IndexTableSegment },
2709 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x23,0x00 },
mxf_read_essence_container_data,
sizeof(
MXFEssenceContainerData),
EssenceContainerData },
2710 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
NULL, 0,
AnyType },
2752 if (local_tag ==
tag) {
2759 if (ctx_size &&
tag == 0x3C0A) {
2776 "local tag %#04x extends past end of local set @ %#"PRIx64
"\n",
2782 if (ctx_size)
ctx->type =
type;
2797 key[13] >= 2 &&
key[13] <= 4;
2809 if (klv.
key[5] == 0x53) {
2839 int64_t current_partition_ofs;
2870 if (klv.
offset >= current_partition_ofs) {
2872 PRIx64
" indirectly points to itself\n", current_partition_ofs);
2912 "failed to seek to FooterPartition @ 0x%" PRIx64
2913 " (%"PRId64
") - partial file?\n",
2936 for (
int i = 0;
i <
s->nb_streams;
i++) {
2972 if (x < mxf->partitions_count - 1)
2979 "partition %i: bad ThisPartition = %"PRIX64
"\n",
3042 int essence_partition_count = 0;
3043 int edit_unit_byte_count = 0;
3065 essence_partition_count++;
3069 if (essence_partition_count != 1)
3078 if (edit_unit_byte_count <= 0)
3098 segment->edit_unit_byte_count = edit_unit_byte_count;
3099 segment->index_start_position = 0;
3111 int64_t file_size, max_rip_length, min_rip_length;
3127 max_rip_length = ((file_size - mxf->
run_in) / 105) * 12 + 28;
3128 max_rip_length =
FFMIN(max_rip_length, INT_MAX);
3131 min_rip_length = 16+1+24+4;
3137 if (length < min_rip_length || length > max_rip_length)
3139 avio_seek(
s->pb, file_size - length, SEEK_SET);
3165 int64_t essence_offset = 0;
3210 if (!essence_offset)
3211 essence_offset = klv.
offset;
3233 if (!metadata->
read) {
3240 if (!essence_offset) {
3252 for (
int i = 0;
i <
s->nb_streams;
i++)
3260 av_log(mxf->
fc,
AV_LOG_INFO,
"got %i index tables - only the first one (IndexSID %i) will be used\n",
3270 for (
int i = 0;
i <
s->nb_streams;
i++)
3296 if (
offset < current_offset)
3325 "seeking detected on stream #%d with time base (%d/%d) and "
3326 "sample rate (%d/%d), audio pts won't be accurate.\n",
3340 int64_t next_ofs = -1;
3343 int64_t new_edit_unit;
3356 if (next_ofs > current_offset)
3371 av_log(mxf->
fc,
AV_LOG_WARNING,
"edit unit sync lost on stream %d, jumping from %"PRId64
" to %"PRId64
"\n", st->
index, edit_unit, new_edit_unit);
3383 if (!bits_per_sample)
3389 || bits_per_sample <= 0
3390 || par->
channels * (int64_t)bits_per_sample < 8)
3435 int64_t max_data_size;
3443 max_data_size = klv.
length;
3470 "error getting stream index %"PRIu32
"\n",
3486 if (next_ofs <= 0) {
3494 if ((
size = next_ofs -
pos) <= 0) {
3500 if (
size > max_data_size)
3501 size = max_data_size;
3511 if (klv.
key[12] == 0x06 && klv.
key[13] == 0x01 && klv.
key[14] == 0x10) {
3563 for (
i = 0;
i <
s->nb_streams;
i++)
3564 s->streams[
i]->priv_data =
NULL;
3598 for (; bufp <
end;) {
3599 if (!((bufp[13] - 1) & 0xF2)){
3617 AVStream *st =
s->streams[stream_index];
3636 if (sample_time < 0)
3640 seekpos =
avio_seek(
s->pb, (
s->bit_rate * seconds) >> 3, SEEK_SET);
3652 for (
i = 0;
i <
s->nb_streams;
i++) {
3653 MXFTrack *new_source_track =
s->streams[
i]->priv_data;
3656 source_track = new_source_track;
3661 if (
i ==
s->nb_streams)
3667 sample_time =
FFMAX(sample_time, 0);
3676 sample_time < t->ptses[0] &&
3678 sample_time = t->
ptses[0];
3684 sample_time += t->
offsets[sample_time];
3700 if (seekpos < klv.next_klv - klv.length || seekpos >= klv.
next_klv) {
3712 for (
i = 0;
i <
s->nb_streams;
i++) {
3716 int64_t track_edit_unit = sample_time;
3726 {
"eia608_extract",
"extract eia 608 captions from s436m track",