Ticket #6759: 0001-Sony-XDCAM-Fix.patch
| File 0001-Sony-XDCAM-Fix.patch, 22.3 KB (added by , 9 years ago) |
|---|
-
libavformat/mxfenc.c
From 5df395dc89727211600660d2cfe4c21f2989886e Mon Sep 17 00:00:00 2001 From: "Axel Technology" <development@axeltechnology.com> Date: Fri, 20 Oct 2017 12:27:05 +0200 Subject: [PATCH] Sony XDCAM Fix --- libavformat/mxfenc.c | 167 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 136 insertions(+), 31 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 7733ef8..91d617b 100644
a b typedef struct MXFStreamContext { 89 89 int h_chroma_sub_sample; 90 90 int temporal_reordering; 91 91 AVRational aspect_ratio; ///< display aspect ratio 92 int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing 92 // XDCAM remarked 93 //int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing 93 94 int video_bit_rate; 94 } MXFStreamContext; 95 // XDCAM start added 96 int seq_closed_gop; ///< all gops in sequence are closed, used in mpeg-2 descriptor 97 int closed_gop; ///< previous gop was closed, used in mpeg-2 frame parsing 98 int max_gop; ///< maximum gop size, used by mpeg-2 descriptor 99 int b_picture_count; ///< maximum number of consecutive b pictures, used in mpeg-2 descriptor 100 int low_delay; ///< low delay, used in mpeg-2 descriptor 101 // XDCAM end added 102 } MXFStreamContext; 95 103 96 104 typedef struct MXFContainerEssenceEntry { 97 105 UID container_ul; … … static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02, 341 349 static const uint8_t random_index_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x11,0x01,0x00 }; 342 350 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 343 351 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 344 static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 }; 352 // XDCAM Changed line 353 //static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 }; 354 static const uint8_t klv_fill_key[] = { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x01,0x02,0x10,0x01,0x00,0x00,0x00 };// XDCAM 345 355 static const uint8_t body_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }; // ClosedComplete 346 356 347 357 /** … … static const uint8_t multiple_desc_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x 352 362 353 363 /** 354 364 * SMPTE RP210 http://www.smpte-ra.org/mdd/index.html 355 * https://smpte-ra.org/sites/default/files/Labels.xml356 365 */ 357 366 static const MXFLocalTagPair mxf_local_tag_batch[] = { 358 367 // preface set … … static const MXFLocalTagPair mxf_local_tag_batch[] = { 409 418 { 0x3002, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x06,0x01,0x02,0x00,0x00,0x00,0x00}}, /* ContainerDuration */ 410 419 { 0x3004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x01,0x02,0x00,0x00}}, /* Essence Container */ 411 420 // Generic Picture Essence Descriptor 421 // XDCAM ADDED 422 { 0x320A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0D,0x00,0x00,0x00}}, /* DisplayXOffset XDCAM*/ 423 { 0x320B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0E,0x00,0x00,0x00}}, /* DisplayYOffset XDCAM */ 424 // XDCAM end added 412 425 { 0x320C, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Frame Layout */ 413 { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */ 414 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */ 426 // XDCAM changed 427 //{ 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map */ 428 { 0x320D, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x02,0x05,0x00,0x00,0x00}}, /* Video Line Map XDCAM */ 429 // XDCAM ADDED 430 { 0x3205, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x08,0x00,0x00,0x00}}, /* Sampled Width XDCAM*/ 431 { 0x3204, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x07,0x00,0x00,0x00}}, /* Sampled Height XDCAM*/ 432 // XDCAM end added 433 { 0x3203, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x02,0x00,0x00,0x00}}, /* Stored Width */ 415 434 { 0x3202, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x02,0x01,0x00,0x00,0x00}}, /* Stored Height */ 416 435 { 0x3209, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0C,0x00,0x00,0x00}}, /* Display Width */ 417 436 { 0x3208, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0B,0x00,0x00,0x00}}, /* Display Height */ … … static const MXFLocalTagPair mxf_local_tag_batch[] = { 419 438 { 0x320E, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x00,0x00,0x00}}, /* Aspect Ratio */ 420 439 { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */ 421 440 { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */ 422 { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard */ 441 // XDCAM changed 442 { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard XDCAM*/ 423 443 // CDCI Picture Essence Descriptor 424 444 { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */ 425 445 { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */ 426 { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */ 446 // XDCAM added 447 { 0x3308, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x01,0x10,0x00,0x00,0x00}}, /* Vertical Subsampling XDCAM */ 448 // XDCAM end added 449 { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */ 427 450 // Generic Sound Essence Descriptor 428 451 { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */ 429 452 { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */ … … static const MXFLocalTagPair mxf_local_tag_batch[] = { 439 462 { 0x3F08, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x04,0x04,0x01,0x01,0x00,0x00,0x00}}, /* Slice Count */ 440 463 { 0x3F09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x01,0x06,0x00,0x00,0x00}}, /* Delta Entry Array */ 441 464 { 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */ 442 // MPEG video Descriptor 443 { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */ 444 { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */ 465 // XDCAM REMMED MPEG video Descriptor 466 //{ 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */ 467 //{ 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */ 468 // XDCAM new MPEG video Descriptor section 469 { 0x8003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x05,0x00,0x00}}, /* LowDelay */ 470 { 0x8004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x06,0x00,0x00}}, /* ClosedGOP */ 471 { 0x8006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x08,0x00,0x00}}, /* MaxGOP */ 472 { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x09,0x00,0x00}}, /* BPictureCount */ 473 { 0x8008, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel*/ 474 { 0x8009, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */ 445 475 // Wave Audio Essence Descriptor 446 476 { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */ 447 477 { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */ … … static int klv_ber_length(uint64_t len) 483 513 return (av_log2(len) >> 3) + 2; 484 514 } 485 515 516 // XDCAM remmed function 517 #if 0 486 518 static int klv_encode_ber_length(AVIOContext *pb, uint64_t len) 487 519 { 488 520 // Determine the best BER size … … static int klv_encode_ber_length(AVIOContext *pb, uint64_t len) 503 535 } 504 536 return 0; 505 537 } 538 #endif 506 539 507 540 static void klv_encode_ber4_length(AVIOContext *pb, int len) 508 541 { … … static void mxf_write_primer_pack(AVFormatContext *s) 538 571 local_tag_number += mxf->store_user_comments * FF_ARRAY_ELEMS(mxf_user_comments_local_tag); 539 572 540 573 avio_write(pb, primer_pack_key, 16); 541 klv_encode_ber_length(pb, local_tag_number * 18 + 8); 574 // XDCAM ber4 575 klv_encode_ber4_length(pb, local_tag_number * 18 + 8); 542 576 543 577 avio_wb32(pb, local_tag_number); // local_tag num 544 578 avio_wb32(pb, 18); // item size, always 18 according to the specs … … static void mxf_write_preface(AVFormatContext *s) 615 649 616 650 mxf_write_metadata_key(pb, 0x012f00); 617 651 PRINT_KEY(s, "preface key", pb->buf_ptr - 16); 618 klv_encode_ber_length(pb, 130 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count)); 652 // XDCAM ber4 653 klv_encode_ber4_length(pb, 130 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count)); 619 654 620 655 // write preface set uid 621 656 mxf_write_local_tag(pb, 16, 0x3C0A); … … static void mxf_write_identification(AVFormatContext *s) 730 765 length = 72 + mxf_utf16_local_tag_length(company) + 731 766 mxf_utf16_local_tag_length(product) + 732 767 mxf_utf16_local_tag_length(version); 733 klv_encode_ber_length(pb, length); 768 // XDCAM ber4 769 klv_encode_ber4_length(pb, length); 734 770 735 771 // write uid 736 772 mxf_write_local_tag(pb, 16, 0x3C0A); … … static void mxf_write_content_storage(AVFormatContext *s) 759 795 760 796 mxf_write_metadata_key(pb, 0x011800); 761 797 PRINT_KEY(s, "content storage key", pb->buf_ptr - 16); 762 klv_encode_ber_length(pb, 92); 798 // XDCAM ber4 799 klv_encode_ber4_length(pb, 92); 763 800 764 801 // write uid 765 802 mxf_write_local_tag(pb, 16, 0x3C0A); … … static void mxf_write_track(AVFormatContext *s, AVStream *st, enum MXFMetadataSe 786 823 787 824 mxf_write_metadata_key(pb, 0x013b00); 788 825 PRINT_KEY(s, "track key", pb->buf_ptr - 16); 789 klv_encode_ber_length(pb, 80); 826 // XDCAM ber4 827 klv_encode_ber4_length(pb, 80); 790 828 791 829 // write track uid 792 830 mxf_write_local_tag(pb, 16, 0x3C0A); … … static void mxf_write_sequence(AVFormatContext *s, AVStream *st, enum MXFMetadat 857 895 858 896 mxf_write_metadata_key(pb, 0x010f00); 859 897 PRINT_KEY(s, "sequence key", pb->buf_ptr - 16); 860 klv_encode_ber_length(pb, 80); 898 // XDCAM ber4 899 klv_encode_ber4_length(pb, 80); 861 900 862 901 mxf_write_local_tag(pb, 16, 0x3C0A); 863 902 mxf_write_uuid(pb, type == MaterialPackage ? Sequence: Sequence + TypeBottom, st->index); … … static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum 883 922 AVIOContext *pb = s->pb; 884 923 885 924 mxf_write_metadata_key(pb, 0x011400); 886 klv_encode_ber_length(pb, 75); 925 // XDCAM ber4 926 klv_encode_ber4_length(pb, 75); 887 927 888 928 // UID 889 929 mxf_write_local_tag(pb, 16, 0x3C0A); … … static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, enu 912 952 913 953 mxf_write_metadata_key(pb, 0x011100); 914 954 PRINT_KEY(s, "sturctural component key", pb->buf_ptr - 16); 915 klv_encode_ber_length(pb, 108); 955 // XDCAM ber4 956 klv_encode_ber4_length(pb, 108); 916 957 917 958 // write uid 918 959 mxf_write_local_tag(pb, 16, 0x3C0A); … … static void mxf_write_multi_descriptor(AVFormatContext *s) 950 991 951 992 mxf_write_metadata_key(pb, 0x014400); 952 993 PRINT_KEY(s, "multiple descriptor key", pb->buf_ptr - 16); 953 klv_encode_ber_length(pb, 64 + 16LL * s->nb_streams); 994 // XDCAM ber4 995 klv_encode_ber4_length(pb, 64 + 16LL * s->nb_streams); 954 996 955 997 mxf_write_local_tag(pb, 16, 0x3C0A); 956 998 mxf_write_uuid(pb, MultipleDescriptor, 0); … … static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke 1014 1056 int stored_height = (st->codecpar->height+15)/16*16; 1015 1057 int display_height; 1016 1058 int f1, f2; 1017 unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5; 1059 // XDCAM added sc-.interlaced 1060 unsigned desc_size = size+8+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20+5; // XDCAM 1018 1061 if (sc->interlaced && sc->field_dominance) 1019 1062 desc_size += 5; 1020 1063 if (sc->signal_standard) … … static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke 1041 1084 mxf_write_local_tag(pb, 4, 0x3208); 1042 1085 avio_wb32(pb, display_height>>sc->interlaced); 1043 1086 1087 // XDCAM added 1088 // signal standard +5 XDCAM 1089 mxf_write_local_tag(pb, 1, 0x3215); 1090 if (display_height == 1080) 1091 avio_w8(pb, 4); // SMPTE 274M 1092 else if (display_height == 720) 1093 avio_w8(pb, 5); // SMPTE 296M 1094 else if (st->codec->width == 720) { 1095 if (sc->interlaced) 1096 avio_w8(pb, 1); // SMPTE 125M ITU-R BT.601 1097 else 1098 avio_w8(pb, 2); // SMPTE 293M ITU-R BT.1358 1099 } else 1100 avio_w8(pb, 0); // unknown 1101 // XDCAM end added 1044 1102 // presentation Y offset 1045 1103 mxf_write_local_tag(pb, 4, 0x320B); 1046 1104 avio_wb32(pb, (st->codecpar->height - display_height)>>sc->interlaced); … … static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke 1049 1107 mxf_write_local_tag(pb, 4, 0x3301); 1050 1108 avio_wb32(pb, sc->component_depth); 1051 1109 1110 // XDCAM added vertical subsampling 1111 mxf_write_local_tag(pb, 4, 0x3308); 1112 if (st->codec->pix_fmt == AV_PIX_FMT_YUV420P) 1113 avio_wb32(pb, 2); 1114 else 1115 avio_wb32(pb, 1); 1116 // XDCAM end added 1052 1117 // horizontal subsampling 1053 1118 mxf_write_local_tag(pb, 4, 0x3302); 1054 1119 avio_wb32(pb, sc->h_chroma_sub_sample); … … static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) 1116 1181 1117 1182 if (st->codecpar->codec_id != AV_CODEC_ID_H264) { 1118 1183 mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5); 1119 1184 1120 1185 // bit rate 1121 1186 mxf_write_local_tag(pb, 4, 0x8000); 1122 1187 avio_wb32(pb, sc->video_bit_rate); … … static int mxf_write_tagged_value(AVFormatContext *s, const char* name, const ch 1220 1285 return 1; 1221 1286 1222 1287 mxf_write_metadata_key(pb, 0x013f00); 1223 klv_encode_ber_length(pb, 24 + name_size + indirect_value_size); 1288 // XDCAM ber4 1289 klv_encode_ber4_length(pb, 24 + name_size + indirect_value_size); 1224 1290 1225 1291 // write instance UID 1226 1292 mxf_write_local_tag(pb, 16, 0x3C0A); … … static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type, 1269 1335 user_comment_count = mxf_write_user_comments(s, s->metadata); 1270 1336 mxf_write_metadata_key(pb, 0x013600); 1271 1337 PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16); 1272 klv_encode_ber_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12LL*mxf->store_user_comments); 1338 // XDCAM ber4 1339 klv_encode_ber4_length(pb, 92 + name_size + (16*track_count) + (16*user_comment_count) + 12LL*mxf->store_user_comments); 1273 1340 } else { 1274 1341 mxf_write_metadata_key(pb, 0x013700); 1275 1342 PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16); 1276 klv_encode_ber_length(pb, 112 + name_size + (16*track_count) + 12LL*mxf->store_user_comments); // 20 bytes length for descriptor reference 1343 // XDCAM ber4 1344 klv_encode_ber4_length(pb, 112 + name_size + (16*track_count) + 12LL*mxf->store_user_comments); // 20 bytes length for descriptor reference 1277 1345 } 1278 1346 1279 1347 // write uid … … static int mxf_write_essence_container_data(AVFormatContext *s) 1348 1416 AVIOContext *pb = s->pb; 1349 1417 1350 1418 mxf_write_metadata_key(pb, 0x012300); 1351 klv_encode_ber_length(pb, 72); 1419 // XDCAM ber4 1420 klv_encode_ber4_length(pb, 72); 1352 1421 1353 1422 mxf_write_local_tag(pb, 16, 0x3C0A); // Instance UID 1354 1423 mxf_write_uuid(pb, EssenceContainerData, 0); … … static void mxf_write_index_table_segment(AVFormatContext *s) 1413 1482 AVIOContext *pb = s->pb; 1414 1483 int i, j, temporal_reordering = 0; 1415 1484 int key_index = mxf->last_key_index; 1485 // XDCAM added line 1486 int prev_non_b_picture = 0; // XDCAM 1416 1487 1417 1488 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count); 1418 1489 … … static void mxf_write_index_table_segment(AVFormatContext *s) 1422 1493 avio_write(pb, index_table_segment_key, 16); 1423 1494 1424 1495 if (mxf->edit_unit_byte_count) { 1425 klv_encode_ber_length(pb, 80); 1496 // XDCAM ber4 1497 klv_encode_ber4_length(pb, 80); 1426 1498 } else { 1427 klv_encode_ber_length(pb, 85 + 12+(s->nb_streams+1LL)*6 + 1499 // XDCAM ber4 1500 klv_encode_ber4_length(pb, 85 + 12+(s->nb_streams+1LL)*6 + 1428 1501 12+mxf->edit_units_count*(11+mxf->slice_count*4LL)); 1429 1502 } 1430 1503 … … static void mxf_write_index_table_segment(AVFormatContext *s) 1490 1563 } 1491 1564 } 1492 1565 1566 // XDCAM added line 1567 MXFStreamContext *sc = s->streams[0]->priv_data; // XDCAM 1493 1568 mxf_write_local_tag(pb, 8 + mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A); 1494 1569 avio_wb32(pb, mxf->edit_units_count); // num of entries 1495 1570 avio_wb32(pb, 11+mxf->slice_count*4); // size of one entry … … static void mxf_write_index_table_segment(AVFormatContext *s) 1498 1573 int temporal_offset = 0; 1499 1574 1500 1575 if (!(mxf->index_entries[i].flags & 0x33)) { // I-frame 1576 // XDCAM added line 1577 sc->max_gop = FFMAX(sc->max_gop, i - mxf->last_key_index); // XDCAM 1501 1578 mxf->last_key_index = key_index; 1502 1579 key_index = i; 1503 1580 } … … static void mxf_write_index_table_segment(AVFormatContext *s) 1517 1594 avio_w8(pb, temporal_offset); 1518 1595 1519 1596 if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction 1597 // XDCAM added line 1598 sc->b_picture_count = FFMAX(sc->b_picture_count, i - prev_non_b_picture); // XDCAM 1520 1599 avio_w8(pb, mxf->last_key_index - i); 1521 1600 } else { 1522 1601 avio_w8(pb, key_index - i); // key frame offset 1523 1602 if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward 1524 1603 mxf->last_key_index = key_index; 1604 // XDCAM added line 1605 prev_non_b_picture = i; // XDCAM 1525 1606 } 1526 1607 1527 1608 if (!(mxf->index_entries[i].flags & 0x33) && // I-frame … … static int mxf_write_partition(AVFormatContext *s, int bodysid, 1590 1671 else 1591 1672 avio_write(pb, body_partition_key, 16); 1592 1673 1593 klv_encode_ber_length(pb, 88 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count)); 1674 // XDCAM ber4 1675 klv_encode_ber4_length(pb, 88 + 16LL * DESCRIPTOR_COUNT(mxf->essence_container_count)); 1594 1676 1595 1677 // write partition value 1596 1678 avio_wb16(pb, 1); // majorVersion … … static const struct { 1823 1905 int profile; 1824 1906 uint8_t interlaced; 1825 1907 } mxf_h264_codec_uls[] = { 1826 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 0, 66, 0 }, // AVC Baseline, Unconstrained Coding1827 1908 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x20,0x01 }, 0, 110, 0 }, // AVC High 10 Intra 1828 1909 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x01 }, 232960, 0, 1 }, // AVC Intra 50 1080i60 1829 1910 {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x02 }, 281088, 0, 1 }, // AVC Intra 50 1080i50 … … static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, 1953 2034 if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext 1954 2035 st->codecpar->profile = pkt->data[i+1] & 0x07; 1955 2036 st->codecpar->level = pkt->data[i+2] >> 4; 2037 // XDCAM added line 2038 sc->low_delay = pkt->data[i+6] >> 7; // XDCAM 1956 2039 } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext 1957 2040 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame 1958 2041 if (sc->interlaced) … … static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational rate) 2039 2122 2040 2123 static int mxf_write_header(AVFormatContext *s) 2041 2124 { 2125 local_log("Writing MXF header"); 2126 2042 2127 MXFContext *mxf = s->priv_data; 2043 2128 int i, ret; 2044 2129 uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; … … static int mxf_write_header(AVFormatContext *s) 2145 2230 av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n"); 2146 2231 } 2147 2232 sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1; 2233 2148 2234 } else if (s->oformat == &ff_mxf_opatom_muxer) { 2149 2235 AVRational tbc = av_inv_q(mxf->audio_edit_rate); 2150 2236 … … static void mxf_write_system_item(AVFormatContext *s) 2254 2340 avio_w8(pb, 0x00); // content package type 2255 2341 avio_wb16(pb, 0x00); // channel handle 2256 2342 avio_wb16(pb, (mxf->tc.start + frame) & 0xFFFF); // continuity count, supposed to overflow 2343 // XDCAM added line 2344 avio_wb16(pb, mxf->last_indexed_edit_unit + mxf->edit_units_count); // continuity count 2257 2345 if (mxf->essence_container_count > 1) 2258 2346 avio_write(pb, multiple_desc_ul, 16); 2259 2347 else { … … static void mxf_write_random_index_pack(AVFormatContext *s) 2502 2590 int i; 2503 2591 2504 2592 avio_write(pb, random_index_pack_key, 16); 2505 klv_encode_ber_length(pb, 28 + 12LL*mxf->body_partitions_count); 2593 // XDCAM ber4 2594 klv_encode_ber4_length(pb, 28 + 12LL*mxf->body_partitions_count); 2506 2595 2507 2596 if (mxf->edit_unit_byte_count && s->oformat != &ff_mxf_opatom_muxer) 2508 2597 avio_wb32(pb, 1); // BodySID of header partition … … AVOutputFormat ff_mxf_opatom_muxer = { 2764 2853 .interleave_packet = mxf_interleave, 2765 2854 .priv_class = &mxf_opatom_muxer_class, 2766 2855 }; 2856 2857 static void local_log(char * line) 2858 { 2859 FILE *f = fopen("c:\\ffmpeg_log.txt", "w"); 2860 if (f == NULL) 2861 { 2862 printf("Error opening file!\n"); 2863 exit(1); 2864 } 2865 2866 /* print some text */ 2867 const char *text = "Write this to the file"; 2868 fprintf(f, "", line); 2869 2870 fclose(f); 2871 }
