* 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 },
{ CODEC_ID_MPEG2VIDEO, 0 },
{ CODEC_ID_PCM_S24LE, 1 },
{ CODEC_ID_PCM_S16LE, 1 },
{ 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
};
{ 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
};
- put_buffer(s->pb, umid_ul, 13);
- put_be24(s->pb, mxf->instance_number);
- put_buffer(s->pb, mxf->umid, 15);
- put_byte(s->pb, type);
+ 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);
{
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);
// 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++)
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);
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);
}
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;
mxf_write_generic_desc(s, st, key, size+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20);
mxf_write_local_tag(pb, 4, 0x3203);
mxf_write_generic_desc(s, st, key, size+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20);
mxf_write_local_tag(pb, 4, 0x3203);
int profile_and_level = (st->codec->profile<<4) | st->codec->level;
mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
// bit rate
mxf_write_local_tag(pb, 4, 0x8000);
int profile_and_level = (st->codec->profile<<4) | st->codec->level;
mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
// bit rate
mxf_write_local_tag(pb, 4, 0x8000);
mxf_write_generic_desc(s, st, key, size+5+12+8+8);
// audio locked
mxf_write_local_tag(pb, 1, 0x3D02);
mxf_write_generic_desc(s, st, key, size+5+12+8+8);
// audio locked
mxf_write_local_tag(pb, 1, 0x3D02);
mxf_write_generic_sound_common(s, st, key, size+6+8);
mxf_write_local_tag(pb, 2, 0x3D0A);
mxf_write_generic_sound_common(s, st, key, size+6+8);
mxf_write_local_tag(pb, 2, 0x3D0A);
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) {
- 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);
+
+ 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);
+
- 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
- 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
hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames);
}
} else if (c == 0x1b3) { // seq
hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames);
}
} else if (c == 0x1b3) { // seq
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;
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;
- 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) {
( ((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
- 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);
- 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
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;
*out = pktl->pkt;
//av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts);
s->packet_buffer = pktl->next;
*out = pktl->pkt;
//av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts);
s->packet_buffer = pktl->next;
-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("Material eXchange Format"),
+ .mime_type = "application/mxf",
+ .extensions = "mxf",
+ .priv_data_size = sizeof(MXFContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = 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("Material eXchange Format, D-10 Mapping"),
+ .mime_type = "application/mxf",
+ .priv_data_size = sizeof(MXFContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = 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,