* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mxf.h"
static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 };
static const int PAL_samples_per_frame[] = { 1920, 0 };
#include "mxf.h"
static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 };
static const int PAL_samples_per_frame[] = { 1920, 0 };
- { CODEC_ID_MPEG2VIDEO, 0 },
- { CODEC_ID_PCM_S24LE, 1 },
- { CODEC_ID_PCM_S16LE, 1 },
- { 0 }
+ { AV_CODEC_ID_MPEG2VIDEO, 0 },
+ { AV_CODEC_ID_PCM_S24LE, 1 },
+ { AV_CODEC_ID_PCM_S16LE, 1 },
+ { AV_CODEC_ID_NONE }
} MXFContext;
static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
} MXFContext;
static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
-static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13,0x00,0x00,0x00 };
+static const uint8_t umid_ul[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13 };
-static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x01,0x00 };
+static const uint8_t op1a_ul[] = { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x01,0x09,0x00 };
static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete
static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 };
static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 };
static const uint8_t footer_partition_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }; // ClosedComplete
static const uint8_t primer_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x02,0x01,0x01,0x05,0x01,0x00 };
static const uint8_t index_table_segment_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 };
{ 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */
// MPEG video Descriptor
{ 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
{ 0x3F0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}}, /* Index Entry Array */
// MPEG video Descriptor
{ 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
+ { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
// Wave Audio Essence Descriptor
{ 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
{ 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
};
// Wave Audio Essence Descriptor
{ 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
{ 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
};
- put_buffer(pb, umid_base, 16);
- mxf_write_uuid(pb, type, value);
+ MXFContext *mxf = s->priv_data;
+ avio_write(s->pb, umid_ul, 13);
+ avio_wb24(s->pb, mxf->instance_number);
+ avio_write(s->pb, mxf->umid, 15);
+ avio_w8(s->pb, type);
- put_be32(pb, local_tag_number); // local_tag num
- put_be32(pb, 18); // item size, always 18 according to the specs
+ avio_wb32(pb, local_tag_number); // local_tag num
+ avio_wb32(pb, 18); // item size, always 18 according to the specs
- put_be16(pb, mxf_local_tag_batch[i].local_tag);
- put_buffer(pb, mxf_local_tag_batch[i].uid, 16);
+ avio_wb16(pb, mxf_local_tag_batch[i].local_tag);
+ avio_write(pb, mxf_local_tag_batch[i].uid, 16);
int i;
mxf_write_refs_count(pb, c->essence_container_count);
av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count);
for (i = 0; i < c->essence_container_count; i++) {
MXFStreamContext *sc = s->streams[i]->priv_data;
int i;
mxf_write_refs_count(pb, c->essence_container_count);
av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count);
for (i = 0; i < c->essence_container_count; i++) {
MXFStreamContext *sc = s->streams[i]->priv_data;
mxf_write_metadata_key(pb, 0x012f00);
PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
mxf_write_metadata_key(pb, 0x012f00);
PRINT_KEY(s, "preface key", pb->buf_ptr - 16);
- if (s->nb_streams > 1) {
- put_buffer(pb, op1a_ul, 14);
- put_be16(pb, 0x0900); // multi track
- } else {
- put_buffer(pb, op1a_ul, 16);
- }
+ avio_write(pb, op1a_ul, 16);
{
int i, size = strlen(value);
mxf_write_local_tag(pb, size*2, tag);
for (i = 0; i < size; i++)
{
int i, size = strlen(value);
mxf_write_local_tag(pb, size*2, tag);
for (i = 0; i < size; i++)
mxf_write_metadata_key(pb, 0x011800);
PRINT_KEY(s, "content storage key", pb->buf_ptr - 16);
mxf_write_metadata_key(pb, 0x011800);
PRINT_KEY(s, "content storage key", pb->buf_ptr - 16);
mxf_write_refs_count(pb, 1);
if (st == mxf->timecode_track)
component = TimecodeComponent;
mxf_write_refs_count(pb, 1);
if (st == mxf->timecode_track)
component = TimecodeComponent;
mxf_write_metadata_key(pb, 0x011400);
klv_encode_ber_length(pb, 75);
// UID
mxf_write_local_tag(pb, 16, 0x3C0A);
mxf_write_metadata_key(pb, 0x011400);
klv_encode_ber_length(pb, 75);
// UID
mxf_write_local_tag(pb, 16, 0x3C0A);
mxf_write_common_fields(s, st);
// Start Time Code
mxf_write_local_tag(pb, 8, 0x1501);
mxf_write_common_fields(s, st);
// Start Time Code
mxf_write_local_tag(pb, 8, 0x1501);
// write source package uid, end of the reference
mxf_write_local_tag(pb, 32, 0x1101);
if (type == SourcePackage) {
for (i = 0; i < 4; i++)
// write source package uid, end of the reference
mxf_write_local_tag(pb, 32, 0x1101);
if (type == SourcePackage) {
for (i = 0; i < 4; i++)
- put_buffer(pb, key, 16);
- klv_encode_ber_length(pb, size);
+ avio_write(pb, key, 16);
+ klv_encode_ber4_length(pb, size+20+8+12+20);
mxf_write_local_tag(pb, 16, 0x3C0A);
mxf_write_uuid(pb, SubDescriptor, st->index);
mxf_write_local_tag(pb, 4, 0x3006);
mxf_write_local_tag(pb, 16, 0x3C0A);
mxf_write_uuid(pb, SubDescriptor, st->index);
mxf_write_local_tag(pb, 4, 0x3006);
}
static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
}
static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
{
MXFStreamContext *sc = st->priv_data;
static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
{
MXFStreamContext *sc = st->priv_data;
- put_be32(pb, st->codec->bit_rate);
+ avio_wb32(pb, st->codec->bit_rate);
+
+ // profile and level
+ mxf_write_local_tag(pb, 1, 0x8007);
+ if (!st->codec->profile)
+ profile_and_level |= 0x80; // escape bit
+ avio_w8(pb, profile_and_level);
mxf_write_metadata_key(pb, 0x013600);
PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
klv_encode_ber_length(pb, 92 + 16*track_count);
} else {
mxf_write_metadata_key(pb, 0x013600);
PRINT_KEY(s, "Material Package key", pb->buf_ptr - 16);
klv_encode_ber_length(pb, 92 + 16*track_count);
} else {
mxf_write_metadata_key(pb, 0x013700);
PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
klv_encode_ber_length(pb, 112 + 16*track_count); // 20 bytes length for descriptor reference
mxf_write_metadata_key(pb, 0x013700);
PRINT_KEY(s, "Source Package key", pb->buf_ptr - 16);
klv_encode_ber_length(pb, 112 + 16*track_count); // 20 bytes length for descriptor reference
PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16);
// package creation date
mxf_write_local_tag(pb, 8, 0x4405);
PRINT_KEY(s, "package umid second part", pb->buf_ptr - 16);
// package creation date
mxf_write_local_tag(pb, 8, 0x4405);
// write track refs
mxf_write_local_tag(pb, track_count*16 + 8, 0x4403);
mxf_write_refs_count(pb, track_count);
// write track refs
mxf_write_local_tag(pb, track_count*16 + 8, 0x4403);
mxf_write_refs_count(pb, track_count);
+ // write timecode track
+ mxf_write_track(s, mxf->timecode_track, type);
+ mxf_write_sequence(s, mxf->timecode_track, type);
+ mxf_write_timecode_component(s, mxf->timecode_track, type);
+
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
mxf_write_track(s, st, type);
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
mxf_write_track(s, st, type);
mxf_write_uuid(pb, EssenceContainerData, 0);
mxf_write_local_tag(pb, 32, 0x2701); // Linked Package UID
mxf_write_uuid(pb, EssenceContainerData, 0);
mxf_write_local_tag(pb, 32, 0x2701); // Linked Package UID
int key_index = mxf->last_key_index;
av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
int key_index = mxf->last_key_index;
av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
- if (temporal_reordering) {
- int temporal_offset = 0;
- for (j = i+1; j < mxf->edit_units_count; j++) {
- temporal_offset++;
- if (mxf->index_entries[j].flags & 0x10) { // backward prediction
- // next is not b, so is reordered
- if (!(mxf->index_entries[i+1].flags & 0x10)) {
- if ((mxf->index_entries[i].flags & 0x11) == 0) // i frame
- temporal_offset = 0;
- else
- temporal_offset = -temporal_offset;
- }
- break;
- }
- }
- put_byte(pb, temporal_offset);
- } else
- put_byte(pb, 0);
+ int temporal_offset = 0;
+
- if (mxf->index_entries[i].flags & 0x10 && // backward prediction
- !(mxf->index_entries[key_index].flags & 0x80)) { // open gop
- put_byte(pb, mxf->last_key_index - i);
+
+ if (temporal_reordering) {
+ int pic_num_in_gop = i - key_index;
+ if (pic_num_in_gop != mxf->index_entries[i].temporal_ref) {
+ for (j = key_index; j < mxf->edit_units_count; j++) {
+ if (pic_num_in_gop == mxf->index_entries[j].temporal_ref)
+ break;
+ }
+ if (j == mxf->edit_units_count)
+ av_log(s, AV_LOG_WARNING, "missing frames\n");
+ temporal_offset = j - key_index - pic_num_in_gop;
+ }
+ }
+ avio_w8(pb, temporal_offset);
+
+ if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction
+ avio_w8(pb, mxf->last_key_index - i);
if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
12+mxf->edit_units_count*(11+mxf->slice_count*4);
else if (mxf->edit_unit_byte_count && indexsid)
if (!mxf->edit_unit_byte_count && mxf->edit_units_count)
index_byte_count = 85 + 12+(s->nb_streams+1)*6 +
12+mxf->edit_units_count*(11+mxf->slice_count*4);
else if (mxf->edit_unit_byte_count && indexsid)
- put_be16(pb, 1); // majorVersion
- put_be16(pb, 2); // minorVersion
- put_be32(pb, KAG_SIZE); // KAGSize
+ avio_wb16(pb, 1); // majorVersion
+ avio_wb16(pb, 2); // minorVersion
+ avio_wb32(pb, KAG_SIZE); // KAGSize
- if (s->nb_streams > 1) {
- put_buffer(pb, op1a_ul, 14);
- put_be16(pb, 0x0900); // multi track
- } else {
- put_buffer(pb, op1a_ul, 16);
- }
+ avio_write(pb, op1a_ul, 16);
- url_fseek(pb, header_byte_count_offset, SEEK_SET);
- put_be64(pb, header_byte_count);
- url_fseek(pb, pos, SEEK_SET);
+ avio_seek(pb, header_byte_count_offset, SEEK_SET);
+ avio_wb64(pb, header_byte_count);
+ avio_seek(pb, pos, SEEK_SET);
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP
st->codec->profile = pkt->data[i+1] & 0x07;
st->codec->level = pkt->data[i+2] >> 4;
} else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
st->codec->profile = pkt->data[i+1] & 0x07;
st->codec->level = pkt->data[i+2] >> 4;
} else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
- if (i + 4 < pkt->size) {
- if (pkt->data[i+4]>>6 & 0x01) // closed
- *flags |= 0x80; // random access
- if (!mxf->header_written) {
- unsigned hours = (pkt->data[i+1]>>2) & 0x1f;
- unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4);
- unsigned seconds = ((pkt->data[i+2] & 0x07) << 3) | (pkt->data[i+3]>>5);
- unsigned frames = ((pkt->data[i+3] & 0x1f) << 1) | (pkt->data[i+4]>>7);
- mxf->timecode_drop_frame = !!(pkt->data[i+1] & 0x80);
- mxf->timecode_start = (hours*3600 + minutes*60 + seconds) *
- mxf->timecode_base + frames;
- if (mxf->timecode_drop_frame) {
- unsigned tminutes = 60 * hours + minutes;
- mxf->timecode_start -= 2 * (tminutes - tminutes / 10);
- }
- av_log(s, AV_LOG_DEBUG, "frame %d %d:%d:%d%c%d\n", mxf->timecode_start,
- hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames);
+ if (pkt->data[i+4]>>6 & 0x01) { // closed
+ sc->closed_gop = 1;
+ if (e->flags & 0x40) // sequence header present
+ e->flags |= 0x80; // random access
+ }
+ if (!mxf->header_written) {
+ unsigned hours = (pkt->data[i+1]>>2) & 0x1f;
+ unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4);
+ unsigned seconds = ((pkt->data[i+2] & 0x07) << 3) | (pkt->data[i+3]>>5);
+ unsigned frames = ((pkt->data[i+3] & 0x1f) << 1) | (pkt->data[i+4]>>7);
+ mxf->timecode_drop_frame = !!(pkt->data[i+1] & 0x80);
+ mxf->timecode_start = (hours*3600 + minutes*60 + seconds) *
+ mxf->timecode_base + frames;
+ if (mxf->timecode_drop_frame) {
+ unsigned tminutes = 60 * hours + minutes;
+ mxf->timecode_start -= 2 * (tminutes - tminutes / 10);
+ e->flags |= 0x40;
+ switch ((pkt->data[i+4]>>4) & 0xf) {
+ case 2: sc->aspect_ratio = (AVRational){ 4, 3}; break;
+ case 3: sc->aspect_ratio = (AVRational){ 16, 9}; break;
+ case 4: sc->aspect_ratio = (AVRational){221,100}; break;
+ default:
+ av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
+ st->codec->width, st->codec->height, 1024*1024);
+ }
+static void mxf_gen_umid(AVFormatContext *s)
+{
+ MXFContext *mxf = s->priv_data;
+ uint32_t seed = av_get_random_seed();
+ uint64_t umid = seed + 0x5294713400000000LL;
+
+ AV_WB64(mxf->umid , umid);
+ AV_WB64(mxf->umid+8, umid>>8);
+
+ mxf->instance_number = seed;
+}
+
static int mxf_write_header(AVFormatContext *s)
{
MXFContext *mxf = s->priv_data;
int i;
uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
const int *samples_per_frame = NULL;
static int mxf_write_header(AVFormatContext *s)
{
MXFContext *mxf = s->priv_data;
int i;
uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
const int *samples_per_frame = NULL;
- av_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
- if (s->oformat == &mxf_d10_muxer) {
+ avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
+ if (s->oformat == &ff_mxf_d10_muxer) {
- av_set_pts_info(st, 64, 1, st->codec->sample_rate);
- if (s->oformat == &mxf_d10_muxer) {
+ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ if (s->oformat == &ff_mxf_d10_muxer) {
av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
}
sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1;
av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
}
sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1;
memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
sc->track_essence_element_key[15] = present[sc->index];
PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
sc->track_essence_element_key[15] = present[sc->index];
PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
( ((frame % fps) / 10) << 28) | // tens of frames
( ((frame % fps) % 10) << 24) | // units of frames
(0 << 23) | // field phase (NTSC), b0 (PAL)
( ((frame % fps) / 10) << 28) | // tens of frames
( ((frame % fps) % 10) << 24) | // units of frames
(0 << 23) | // field phase (NTSC), b0 (PAL)
- put_byte(pb, 0x5c); // UL, user date/time stamp, picture and sound item present
- put_byte(pb, 0x04); // content package rate
- put_byte(pb, 0x00); // content package type
- put_be16(pb, 0x00); // channel handle
- put_be16(pb, frame); // continuity count
+ avio_w8(pb, 0x5c); // UL, user date/time stamp, picture and sound item present
+ avio_w8(pb, 0x04); // content package rate
+ avio_w8(pb, 0x00); // content package type
+ avio_wb16(pb, 0x00); // channel handle
+ avio_wb16(pb, frame); // continuity count
uint8_t *samples = pkt->data;
uint8_t *end = pkt->data + pkt->size;
int i;
klv_encode_ber4_length(pb, 4 + frame_size*4*8);
uint8_t *samples = pkt->data;
uint8_t *end = pkt->data + pkt->size;
int i;
klv_encode_ber4_length(pb, 4 + frame_size*4*8);
- put_byte(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
- put_le16(pb, frame_size);
- put_byte(pb, (1<<st->codec->channels)-1);
+ avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
+ avio_wl16(pb, frame_size);
+ avio_w8(pb, (1<<st->codec->channels)-1);
- if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
- if (!mxf_parse_mpeg2_frame(s, st, pkt, &flags)) {
+ if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+ if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {
- put_buffer(pb, sc->track_essence_element_key, 16); // write key
- if (s->oformat == &mxf_d10_muxer) {
- if (st->codec->codec_type == CODEC_TYPE_VIDEO)
+ avio_write(pb, sc->track_essence_element_key, 16); // write key
+ if (s->oformat == &ff_mxf_d10_muxer) {
+ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
mxf_write_d10_video_packet(s, st, pkt);
else
mxf_write_d10_audio_packet(s, st, pkt);
} else {
klv_encode_ber4_length(pb, pkt->size); // write length
mxf_write_d10_video_packet(s, st, pkt);
else
mxf_write_d10_audio_packet(s, st, pkt);
} else {
klv_encode_ber4_length(pb, pkt->size); // write length
- put_be32(pb, 0); // BodySID of header partition
- put_be64(pb, 0); // offset of header partition
+ if (mxf->edit_unit_byte_count)
+ avio_wb32(pb, 1); // BodySID of header partition
+ else
+ avio_wb32(pb, 0);
+ avio_wb64(pb, 0); // offset of header partition
if (mxf->edit_unit_byte_count) { // no need to repeat index
mxf_write_partition(s, 0, 0, footer_partition_key, 0);
} else {
if (mxf->edit_unit_byte_count) { // no need to repeat index
mxf_write_partition(s, 0, 0, footer_partition_key, 0);
} else {
if (mxf->edit_unit_byte_count) {
mxf_write_partition(s, 1, 2, header_closed_partition_key, 1);
mxf_write_klv_fill(s);
if (mxf->edit_unit_byte_count) {
mxf_write_partition(s, 1, 2, header_closed_partition_key, 1);
mxf_write_klv_fill(s);
- AVPacketList *pktl;
- int stream_count = 0;
- int streams[MAX_STREAMS];
-
- memset(streams, 0, sizeof(streams));
- pktl = s->packet_buffer;
- while (pktl) {
- //av_log(s, AV_LOG_DEBUG, "show st:%d dts:%lld\n", pktl->pkt.stream_index, pktl->pkt.dts);
- if (!streams[pktl->pkt.stream_index])
- stream_count++;
- streams[pktl->pkt.stream_index]++;
- pktl = pktl->next;
- }
+ int i, stream_count = 0;
+
+ for (i = 0; i < s->nb_streams; i++)
+ stream_count += !!s->streams[i]->last_in_packet_buffer;
-AVOutputFormat mxf_muxer = {
- "mxf",
- NULL_IF_CONFIG_SMALL("Material eXchange Format"),
- "application/mxf",
- "mxf",
- sizeof(MXFContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_MPEG2VIDEO,
- mxf_write_header,
- mxf_write_packet,
- mxf_write_footer,
- AVFMT_NOTIMESTAMPS,
- NULL,
- mxf_interleave,
+AVOutputFormat ff_mxf_muxer = {
+ .name = "mxf",
+ .long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format)"),
+ .mime_type = "application/mxf",
+ .extensions = "mxf",
+ .priv_data_size = sizeof(MXFContext),
+ .audio_codec = AV_CODEC_ID_PCM_S16LE,
+ .video_codec = AV_CODEC_ID_MPEG2VIDEO,
+ .write_header = mxf_write_header,
+ .write_packet = mxf_write_packet,
+ .write_trailer = mxf_write_footer,
+ .flags = AVFMT_NOTIMESTAMPS,
+ .interleave_packet = mxf_interleave,
-AVOutputFormat mxf_d10_muxer = {
- "mxf_d10",
- NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"),
- "application/mxf",
- NULL,
- sizeof(MXFContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_MPEG2VIDEO,
- mxf_write_header,
- mxf_write_packet,
- mxf_write_footer,
- AVFMT_NOTIMESTAMPS,
- NULL,
- mxf_interleave,
+AVOutputFormat ff_mxf_d10_muxer = {
+ .name = "mxf_d10",
+ .long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format) D-10 Mapping"),
+ .mime_type = "application/mxf",
+ .priv_data_size = sizeof(MXFContext),
+ .audio_codec = AV_CODEC_ID_PCM_S16LE,
+ .video_codec = AV_CODEC_ID_MPEG2VIDEO,
+ .write_header = mxf_write_header,
+ .write_packet = mxf_write_packet,
+ .write_trailer = mxf_write_footer,
+ .flags = AVFMT_NOTIMESTAMPS,
+ .interleave_packet = mxf_interleave,