62 #define MXF_MAX_CHUNK_SIZE (32 << 20)
196 #define MXF_FIELD_DOMINANCE_DEFAULT 0
197 #define MXF_FIELD_DOMINANCE_FF 1
198 #define MXF_FIELD_DOMINANCE_FL 2
319 static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
320 static const uint8_t mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 };
321 static const uint8_t mxf_avid_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0e,0x04,0x03,0x01 };
322 static const uint8_t mxf_canopus_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x0a,0x0e,0x0f,0x03,0x01 };
323 static const uint8_t mxf_system_item_key_cp[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x03,0x01,0x04 };
324 static const uint8_t mxf_system_item_key_gc[] = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x03,0x01,0x14 };
326 static const uint8_t mxf_apple_coll_prefix[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01 };
328 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 };
329 static const uint8_t mxf_encrypted_triplet_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 };
330 static const uint8_t mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 };
331 static const uint8_t mxf_sony_mpeg4_extradata[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 };
332 static const uint8_t mxf_avid_project_name[] = { 0xa5,0xfb,0x7b,0x25,0xf6,0x15,0x94,0xb9,0x62,0xfc,0x37,0x17,0x49,0x2d,0x42,0xbf };
333 static const uint8_t mxf_jp2k_rsiz[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 };
334 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 };
335 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 };
336 static const uint8_t mxf_apple_coll_max_cll[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01,0x01 };
337 static const uint8_t mxf_apple_coll_max_fall[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01,0x02 };
347 #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
352 switch ((*ctx)->type) {
396 int bytes_num =
size & 0x7f;
404 if (
size > INT64_MAX)
416 else if (
b !=
key[
i])
435 if (
pos > INT64_MAX - length)
445 for (
i = 0;
i <
s->nb_streams;
i++) {
452 return s->nb_streams == 1 &&
s->streams[0]->priv_data ? 0 : -1;
481 int cdp_identifier, cdp_length, cdp_footer_id, ccdata_id, cc_count;
482 int line_num, sample_coding, sample_count;
483 int did, sdid, data_length;
489 for (
i = 0;
i < count;
i++) {
498 length -= 6 + 8 + sample_count;
499 if (line_num != 9 && line_num != 11)
501 if (sample_coding == 7 || sample_coding == 8 || sample_coding == 9) {
513 if (did != 0x61 || sdid != 1) {
518 if (cdp_identifier != 0x9669) {
527 if (ccdata_id != 0x72) {
535 if (cdp_length - 9 - 4 < cc_count * 3) {
539 avio_skip(
s->pb, data_length - 9 - 4 - cc_count * 3);
541 if (cdp_footer_id != 0x74) {
556 const uint8_t *buf_ptr, *end_ptr;
574 uint32_t
sample = bytestream_get_le32(&buf_ptr);
576 bytestream_put_le24(&data_ptr, (
sample >> 4) & 0xffffff);
578 bytestream_put_le16(&data_ptr, (
sample >> 12) & 0xffff);
588 static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b};
594 uint64_t plaintext_size;
600 if (!mxf->
aesc &&
s->key &&
s->keylen == 16) {
627 if (orig_size < plaintext_size)
631 if (
size < 32 ||
size - 32 < orig_size || (
int)orig_size != orig_size)
637 if (memcmp(tmpbuf, checkv, 16))
643 else if (
size < plaintext_size)
645 size -= plaintext_size;
661 if (item_len != 18) {
665 if (item_num > 65536 || item_num < 0) {
687 uint64_t footer_partition;
688 uint32_t nb_essence_containers;
710 memset(partition, 0,
sizeof(*partition));
758 "PreviousPartition equal to ThisPartition %"PRIx64
"\n",
771 "Overriding PreviousPartition with %"PRIx64
"\n",
776 if (footer_partition) {
779 "inconsistent FooterPartition value: %"PRIu64
" != %"PRIu64
"\n",
787 "PartitionPack: ThisPartition = 0x%"PRIX64
788 ", PreviousPartition = 0x%"PRIX64
", "
789 "FooterPartition = 0x%"PRIX64
", IndexSID = %i, BodySID = %i\n",
799 "PreviousPartition points to this partition or forward\n");
803 if (
op[12] == 1 &&
op[13] == 1) mxf->
op =
OP1a;
804 else if (
op[12] == 1 &&
op[13] == 2) mxf->
op =
OP1b;
805 else if (
op[12] == 1 &&
op[13] == 3) mxf->
op =
OP1c;
806 else if (
op[12] == 2 &&
op[13] == 1) mxf->
op =
OP2a;
807 else if (
op[12] == 2 &&
op[13] == 2) mxf->
op =
OP2b;
808 else if (
op[12] == 2 &&
op[13] == 3) mxf->
op =
OP2c;
809 else if (
op[12] == 3 &&
op[13] == 1) mxf->
op =
OP3a;
810 else if (
op[12] == 3 &&
op[13] == 2) mxf->
op =
OP3b;
811 else if (
op[12] == 3 &&
op[13] == 3) mxf->
op =
OP3c;
813 else if (
op[12] == 0x10) {
818 if (nb_essence_containers != 1) {
824 "\"OPAtom\" with %"PRIu32
" ECs - assuming %s\n",
825 nb_essence_containers,
826 op ==
OP1a ?
"OP1a" :
"OPAtom");
882 if (
c > INT_MAX /
sizeof(
UID))
894 if (
ret != *count *
sizeof(
UID)) {
895 *count =
ret < 0 ? 0 :
ret /
sizeof(
UID);
907 if (size < 0 || size > INT_MAX/2)
929 #define READ_STR16(type, big_endian) \
930 static int mxf_read_utf16 ## type ##_string(AVIOContext *pb, int size, char** str) \
932 return mxf_read_utf16_string(pb, size, str, big_endian); \
1013 mxf_read_utf16be_string(pb,
size, &track->
name);
1066 &package->tracks_count);
1070 avio_read(pb, package->package_uid, 16);
1073 avio_read(pb, package->descriptor_ref, 16);
1076 return mxf_read_utf16be_string(pb,
size, &package->name);
1079 &package->comment_count);
1107 if (
segment->temporal_offset_entries)
1113 if(
segment->nb_index_entries && length < 11)
1124 for (
i = 0;
i <
segment->nb_index_entries;
i++) {
1159 segment->index_edit_rate.den);
1188 }
while (
code != 0);
1196 int entry_count, entry_size;
1229 if (entry_size == 4) {
1230 if (entry_count > 0)
1234 if (entry_count > 1)
1317 for (
int i = 0;
i < 3;
i++) {
1347 if (!descriptor->
coll) {
1349 if (!descriptor->
coll)
1375 return mxf_read_utf16le_string(pb,
size - 17, &tagged_value->
value);
1377 return mxf_read_utf16be_string(pb,
size - 17, &tagged_value->
value);
1387 return mxf_read_utf16be_string(pb,
size, &tagged_value->
name);
1401 for (
i = 0;
i <
len;
i++) {
1410 while (uls->
uid[0]) {
1435 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c,0x01,0x00 }, 14,
AV_CODEC_ID_JPEG2000,
NULL, 14 },
1436 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x10,0x60,0x01 }, 14,
AV_CODEC_ID_H264,
NULL, 15 },
1437 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 }, 14,
AV_CODEC_ID_DNXHD,
NULL, 14 },
1438 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x12,0x01,0x00 }, 14,
AV_CODEC_ID_VC1,
NULL, 14 },
1439 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x14,0x01,0x00 }, 14,
AV_CODEC_ID_TIFF,
NULL, 14 },
1440 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x15,0x01,0x00 }, 14,
AV_CODEC_ID_DIRAC,
NULL, 14 },
1441 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x1b,0x01,0x00 }, 14,
AV_CODEC_ID_CFHD,
NULL, 14 },
1442 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x1c,0x01,0x00 }, 14,
AV_CODEC_ID_PRORES,
NULL, 14 },
1443 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, 14,
AV_CODEC_ID_MPEG2VIDEO,
NULL, 15 },
1444 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, 14,
AV_CODEC_ID_MPEG2VIDEO,
NULL, 15,
D10D11Wrap },
1445 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, 14,
AV_CODEC_ID_DVVIDEO,
NULL, 15 },
1446 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x05,0x00,0x00 }, 14,
AV_CODEC_ID_RAWVIDEO,
NULL, 15,
RawVWrap },
1447 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0a,0x0e,0x0f,0x03,0x01,0x02,0x20,0x01,0x01 }, 15,
AV_CODEC_ID_HQ_HQA },
1448 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0a,0x0e,0x0f,0x03,0x01,0x02,0x20,0x02,0x01 }, 15,
AV_CODEC_ID_HQX },
1449 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0a,0x0e,0x15,0x00,0x04,0x02,0x10,0x00,0x01 }, 16,
AV_CODEC_ID_HEVC,
NULL, 15 },
1450 { { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0xff,0x4b,0x46,0x41,0x41,0x00,0x0d,0x4d,0x4f }, 14,
AV_CODEC_ID_RAWVIDEO },
1451 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1456 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x00,0x00 }, 14,
AV_CODEC_ID_MPEG2VIDEO },
1457 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1462 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14,
AV_CODEC_ID_H264 },
1463 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, 14,
AV_CODEC_ID_JPEG2000 },
1464 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1469 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x01 }, 16, 1440 },
1470 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x02 }, 16, 1440 },
1471 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x03 }, 16, 1440 },
1472 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x04 }, 16, 1440 },
1473 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, 0 },
1478 { { 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 },
1479 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, 14,
AV_CODEC_ID_MP2,
NULL, 15 },
1480 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, 14,
AV_CODEC_ID_PCM_S16LE,
NULL, 13 },
1481 { { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0xff,0x4b,0x46,0x41,0x41,0x00,0x0d,0x4d,0x4F }, 14,
AV_CODEC_ID_PCM_S16LE },
1482 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x03,0x04,0x02,0x02,0x02,0x03,0x03,0x01,0x00 }, 14,
AV_CODEC_ID_AAC },
1483 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1487 { { 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 },
1488 { { 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 },
1489 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x09,0x0d,0x01,0x03,0x01,0x02,0x13,0x01,0x01 }, 16,
AV_CODEC_ID_TTML },
1490 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0,
AV_CODEC_ID_NONE },
1506 val = (*essence_container_ul)[
codec_ul->wrapping_indicator_pos];
1507 switch (
codec_ul->wrapping_indicator_type) {
1512 if (
val == 0x03 ||
val == 0x04)
1529 int i, j, nb_segments = 0;
1531 int last_body_sid = -1, last_index_sid = -1, last_index_start = -1;
1541 if (!(unsorted_segments =
av_calloc(nb_segments,
sizeof(*unsorted_segments))) ||
1542 !(*sorted_segments =
av_calloc(nb_segments,
sizeof(**sorted_segments)))) {
1551 if (
s->edit_unit_byte_count ||
s->nb_index_entries)
1552 unsorted_segments[nb_segments++] =
s;
1554 av_log(mxf->
fc,
AV_LOG_WARNING,
"IndexSID %i segment at %"PRId64
" missing EditUnitByteCount and IndexEntryArray\n",
1555 s->index_sid,
s->index_start_position);
1565 *nb_sorted_segments = 0;
1568 for (
i = 0;
i < nb_segments;
i++) {
1569 int best = -1, best_body_sid = -1, best_index_sid = -1, best_index_start = -1;
1570 uint64_t best_index_duration = 0;
1572 for (j = 0; j < nb_segments; j++) {
1580 s->body_sid > last_body_sid ||
1581 s->body_sid == last_body_sid &&
s->index_sid > last_index_sid ||
1582 s->body_sid == last_body_sid &&
s->index_sid == last_index_sid &&
s->index_start_position > last_index_start) &&
1584 s->body_sid < best_body_sid ||
1585 s->body_sid == best_body_sid &&
s->index_sid < best_index_sid ||
1586 s->body_sid == best_body_sid &&
s->index_sid == best_index_sid &&
s->index_start_position < best_index_start ||
1587 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)) {
1589 best_body_sid =
s->body_sid;
1590 best_index_sid =
s->index_sid;
1591 best_index_start =
s->index_start_position;
1592 best_index_duration =
s->index_duration;
1600 (*sorted_segments)[(*nb_sorted_segments)++] = unsorted_segments[best];
1601 last_body_sid = best_body_sid;
1602 last_index_sid = best_index_sid;
1603 last_index_start = best_index_start;
1626 m0 = m = (
a +
b) >> 1;
1628 while (m < b && mxf->partitions[m].body_sid != body_sid)
1631 if (m < b && mxf->partitions[m].body_offset <=
offset)
1643 *partition_out = last_p;
1648 "failed to find absolute offset of %"PRIX64
" in BodySID %i - partial file?\n",
1678 int64_t offset_temp = 0;
1685 edit_unit =
FFMAX(edit_unit,
s->index_start_position);
1687 if (edit_unit < s->index_start_position +
s->index_duration) {
1688 int64_t
index = edit_unit -
s->index_start_position;
1690 if (
s->edit_unit_byte_count)
1691 offset_temp +=
s->edit_unit_byte_count *
index;
1693 if (
s->nb_index_entries == 2 *
s->index_duration + 1)
1696 if (index < 0 || index >=
s->nb_index_entries) {
1702 offset_temp =
s->stream_offset_entries[
index];
1706 *edit_unit_out =
av_rescale_q(edit_unit, edit_rate,
s->index_edit_rate);
1711 offset_temp +=
s->edit_unit_byte_count *
s->index_duration;
1724 int8_t max_temporal_offset = -128;
1731 if (!
s->nb_index_entries) {
1736 if (
s->index_duration > INT_MAX -
index_table->nb_ptses) {
1793 int index_delta = 1;
1794 int n =
s->nb_index_entries;
1796 if (
s->nb_index_entries == 2 *
s->index_duration + 1) {
1802 for (j = 0; j < n; j += index_delta, x++) {
1803 int offset =
s->temporal_offset_entries[j] / index_delta;
1808 "x >= nb_ptses - IndexEntryCount %i < IndexDuration %"PRId64
"?\n",
1809 s->nb_index_entries,
s->index_duration);
1815 if (index < 0 || index >=
index_table->nb_ptses) {
1817 "index entry %i + TemporalOffset %i = %i, which is out of bounds\n",
1824 max_temporal_offset =
FFMAX(max_temporal_offset,
offset);
1847 int i, j, k,
ret, nb_sorted_segments;
1851 nb_sorted_segments <= 0) {
1857 for (
i = 0;
i < nb_sorted_segments;
i++) {
1858 if (
i == 0 || sorted_segments[
i-1]->index_sid != sorted_segments[
i]->index_sid)
1860 else if (sorted_segments[
i-1]->body_sid != sorted_segments[
i]->body_sid) {
1863 goto finish_decoding_index;
1872 goto finish_decoding_index;
1876 for (
i = j = 0;
i < nb_sorted_segments;
i++) {
1877 if (
i != 0 && sorted_segments[
i-1]->index_sid != sorted_segments[
i]->index_sid) {
1894 " pointer array\n");
1896 goto finish_decoding_index;
1899 if (sorted_segments[
i]->index_start_position)
1900 av_log(mxf->
fc,
AV_LOG_WARNING,
"IndexSID %i starts at EditUnit %"PRId64
" - seeking may not work as expected\n",
1908 goto finish_decoding_index;
1931 av_log(mxf->
fc,
AV_LOG_WARNING,
"IndexSID %i segment %i has zero IndexDuration and there's more than one segment\n",
1948 finish_decoding_index:
1968 for (
i = 0;
i <
sizeof(
UID);
i++) {
1971 if (
i == 3 ||
i == 5 ||
i == 7 ||
i == 9) {
1988 for (
i = 0;
i <
sizeof(
UID);
i++) {
1993 for (
i = 0;
i <
sizeof(
UID);
i++) {
2001 uint16_t patch, uint16_t release,
char **
str)
2038 switch (component->
type) {
2056 package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[i], SourcePackage);
2060 if (!memcmp(package->package_ul, package_ul, 16) && !memcmp(package->package_uid, package_uid, 16))
2078 if (!sub_descriptor) {
2083 return sub_descriptor;
2126 switch (component->
type) {
2166 int64_t start_position;
2179 if (physical_package->
name && physical_package->
name[0])
2199 "Invalid edit rate (%d/%d) found on structural"
2200 " component #%d, defaulting to 25/1\n",
2298 if (material_package)
break;
2300 if (!material_package) {
2306 if (material_package->
name && material_package->
name[0])
2318 UID *essence_container_ul =
NULL;
2368 if (!source_package) {
2379 source_track = temp_track;
2383 if (!source_track) {
2402 if(source_track && component)
2405 if (!source_track || !component || !source_package) {
2449 "Invalid edit rate (%d/%d) found on stream #%d, "
2450 "defaulting to 25/1\n",
2482 essence_container_ul = &((
MXFCryptoContext *)metadata)->source_container_ul;
2498 for (k = 0; k < 16; k++) {
2501 if (!(k+1 & 19) || k == 5)
2507 if (source_package->
name && source_package->
name[0])
2509 if (material_track->
name && material_track->
name[0])
2557 "Field dominance %d support",
2571 "Field dominance %d support",
2636 if (descriptor->
coll) {
2656 "found for stream #%d, time base forced to 1/48000\n",
2730 "with different wrapping\n",
i, j, track1->
body_sid);
2743 struct tm time = { 0 };
2745 time.tm_year = (timestamp >> 48) - 1900;
2746 time.tm_mon = (timestamp >> 40 & 0xFF) - 1;
2747 time.tm_mday = (timestamp >> 32 & 0xFF);
2748 time.tm_hour = (timestamp >> 24 & 0xFF);
2749 time.tm_min = (timestamp >> 16 & 0xFF);
2750 time.tm_sec = (timestamp >> 8 & 0xFF);
2751 msecs = (timestamp & 0xFF) * 4;
2754 time.tm_mon =
av_clip(time.tm_mon, 0, 11);
2755 time.tm_mday =
av_clip(time.tm_mday, 1, 31);
2756 time.tm_hour =
av_clip(time.tm_hour, 0, 23);
2757 time.tm_min =
av_clip(time.tm_min, 0, 59);
2758 time.tm_sec =
av_clip(time.tm_sec, 0, 59);
2759 msecs =
av_clip(msecs, 0, 999);
2761 return (int64_t)
av_timegm(&time) * 1000000 + msecs * 1000;
2764 #define SET_STR_METADATA(pb, name, str) do { \
2765 if ((ret = mxf_read_utf16be_string(pb, size, &str)) < 0) \
2767 av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
2770 #define SET_VERSION_METADATA(pb, name, major, minor, tertiary, patch, release, str) do { \
2771 major = avio_rb16(pb); \
2772 minor = avio_rb16(pb); \
2773 tertiary = avio_rb16(pb); \
2774 patch = avio_rb16(pb); \
2775 release = avio_rb16(pb); \
2776 if ((ret = mxf_version_to_str(major, minor, tertiary, patch, release, &str)) < 0) \
2778 av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
2781 #define SET_UID_METADATA(pb, name, var, str) do { \
2782 avio_read(pb, var, 16); \
2783 if ((ret = mxf_uid_to_str(var, &str)) < 0) \
2785 av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
2788 #define SET_TS_METADATA(pb, name, var, str) do { \
2789 var = avio_rb64(pb); \
2790 if (var && (ret = avpriv_dict_set_timestamp(&s->metadata, name, mxf_timestamp_to_int64(var))) < 0) \
2802 uint16_t
major,
minor, tertiary, patch, release;
2852 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 },
mxf_read_primer_pack },
2853 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 },
mxf_read_partition_pack },
2854 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x02,0x00 },
mxf_read_partition_pack },
2855 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x03,0x00 },
mxf_read_partition_pack },
2856 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x04,0x00 },
mxf_read_partition_pack },
2857 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x01,0x00 },
mxf_read_partition_pack },
2858 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x02,0x00 },
mxf_read_partition_pack },
2859 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x03,0x00 },
mxf_read_partition_pack },
2860 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x04,0x00 },
mxf_read_partition_pack },
2861 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x02,0x00 },
mxf_read_partition_pack },
2862 { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x04,0x00 },
mxf_read_partition_pack },
2863 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2f,0x00 },
mxf_read_preface_metadata },
2864 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x30,0x00 },
mxf_read_identification_metadata },
2865 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 },
mxf_read_content_storage, 0,
AnyType },
2866 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 },
mxf_read_package,
sizeof(
MXFPackage),
SourcePackage },
2867 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 },
mxf_read_package,
sizeof(
MXFPackage),
MaterialPackage },
2868 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0f,0x00 },
mxf_read_sequence,
sizeof(
MXFSequence),
Sequence },
2869 { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01,0x05,0x00 },
mxf_read_essence_group,
sizeof(
MXFEssenceGroup),
EssenceGroup},
2870 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 },
mxf_read_source_clip,
sizeof(
MXFStructuralComponent),
SourceClip },
2871 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3f,0x00 },
mxf_read_tagged_value,
sizeof(
MXFTaggedValue),
TaggedValue },
2872 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
MultipleDescriptor },
2873 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2874 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2875 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2876 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2877 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2878 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2879 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5b,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2880 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2881 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5e,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2882 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x64,0x00 },
mxf_read_generic_descriptor,
sizeof(
MXFDescriptor),
Descriptor },
2883 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 },
mxf_read_track,
sizeof(
MXFTrack),
Track },
2884 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 },
mxf_read_track,
sizeof(
MXFTrack),
Track },
2885 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x14,0x00 },
mxf_read_timecode_component,
sizeof(
MXFTimecodeComponent),
TimecodeComponent },
2886 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0c,0x00 },
mxf_read_pulldown_component,
sizeof(
MXFPulldownComponent),
PulldownComponent },
2887 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x04,0x01,0x02,0x02,0x00,0x00 },
mxf_read_cryptographic_context,
sizeof(
MXFCryptoContext),
CryptoContext },
2888 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 },
mxf_read_index_table_segment,
sizeof(
MXFIndexTableSegment),
IndexTableSegment },
2889 { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x23,0x00 },
mxf_read_essence_container_data,
sizeof(
MXFEssenceContainerData),
EssenceContainerData },
2890 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
NULL, 0,
AnyType },
2931 if (next < 0 || next > INT64_MAX -
size) {
2948 if (local_tag ==
tag) {
2955 if (meta &&
tag == 0x3C0A) {
2972 "local tag %#04x extends past end of local set @ %#"PRIx64
"\n",
2992 key[13] >= 2 &&
key[13] <= 4;
3004 if (klv.
key[5] == 0x53) {
3034 int64_t current_partition_ofs;
3065 if (klv.
offset >= current_partition_ofs) {
3067 PRIx64
" indirectly points to itself\n", current_partition_ofs);
3107 "failed to seek to FooterPartition @ 0x%" PRIx64
3108 " (%"PRId64
") - partial file?\n",
3131 for (
int i = 0;
i <
s->nb_streams;
i++) {
3167 if (x < mxf->partitions_count - 1)
3174 "partition %i: bad ThisPartition = %"PRIX64
"\n",
3237 int essence_partition_count = 0;
3238 int edit_unit_byte_count = 0;
3260 essence_partition_count++;
3264 if (essence_partition_count != 1)
3273 if (edit_unit_byte_count <= 0)
3291 segment->edit_unit_byte_count = edit_unit_byte_count;
3292 segment->index_start_position = 0;
3304 int64_t file_size, max_rip_length, min_rip_length;
3320 max_rip_length = ((file_size - mxf->
run_in) / 105) * 12 + 28;
3321 max_rip_length =
FFMIN(max_rip_length, INT_MAX);
3324 min_rip_length = 16+1+24+4;
3330 if (length < min_rip_length || length > max_rip_length)
3332 avio_seek(
s->pb, file_size - length, SEEK_SET);
3358 int64_t essence_offset = 0;
3403 if (!essence_offset)
3404 essence_offset = klv.
offset;
3426 if (!metadata->
read) {
3433 if (!essence_offset) {
3445 for (
int i = 0;
i <
s->nb_streams;
i++)
3453 av_log(mxf->
fc,
AV_LOG_INFO,
"got %i index tables - only the first one (IndexSID %i) will be used\n",
3463 for (
int i = 0;
i <
s->nb_streams;
i++)
3489 if (
offset < current_offset)
3518 "seeking detected on stream #%d with time base (%d/%d) and "
3519 "sample rate (%d/%d), audio pts won't be accurate.\n",
3533 int64_t next_ofs = -1;
3536 int64_t new_edit_unit;
3549 if (next_ofs > current_offset)
3564 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);
3576 if (!bits_per_sample)
3582 || bits_per_sample <= 0
3583 || par->
channels * (int64_t)bits_per_sample < 8)
3628 int64_t max_data_size;
3636 max_data_size = klv.
length;
3663 "error getting stream index %"PRIu32
"\n",
3679 if (next_ofs <= 0) {
3687 if ((
size = next_ofs -
pos) <= 0) {
3693 if (
size > max_data_size)
3694 size = max_data_size;
3704 if (klv.
key[12] == 0x06 && klv.
key[13] == 0x01 && klv.
key[14] == 0x10) {
3756 for (
i = 0;
i <
s->nb_streams;
i++)
3757 s->streams[
i]->priv_data =
NULL;
3791 for (; bufp < end;) {
3792 if (!((bufp[13] - 1) & 0xF2)){
3810 AVStream *st =
s->streams[stream_index];
3829 if (sample_time < 0)
3833 seekpos =
avio_seek(
s->pb, (
s->bit_rate * seconds) >> 3, SEEK_SET);
3845 for (
i = 0;
i <
s->nb_streams;
i++) {
3846 MXFTrack *new_source_track =
s->streams[
i]->priv_data;
3849 source_track = new_source_track;
3854 if (
i ==
s->nb_streams)
3860 sample_time =
FFMAX(sample_time, 0);
3869 sample_time < t->ptses[0] &&
3871 sample_time = t->
ptses[0];
3877 sample_time += t->
offsets[sample_time];
3893 if (seekpos < klv.next_klv - klv.length || seekpos >= klv.
next_klv) {
3905 for (
i = 0;
i <
s->nb_streams;
i++) {
3909 int64_t track_edit_unit = sample_time;
3919 {
"eia608_extract",
"extract eia 608 captions from s436m track",