[FFmpeg-devel] [PATCH] avformat/mxfenc: simplify d-10 ul handling
Baptiste Coudurier
baptiste.coudurier at gmail.com
Sun Nov 10 01:46:36 EET 2019
---
libavformat/mxfenc.c | 110 ++++++++++++++++---------------------------
1 file changed, 41 insertions(+), 69 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 122d336fc3..b7ae5cc637 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -123,18 +123,8 @@ enum ULIndex {
INDEX_MPEG2 = 0,
INDEX_AES3,
INDEX_WAV,
- INDEX_D10_625_50_50_VIDEO,
- INDEX_D10_625_50_50_AUDIO,
- INDEX_D10_525_60_50_VIDEO,
- INDEX_D10_525_60_50_AUDIO,
- INDEX_D10_625_50_40_VIDEO,
- INDEX_D10_625_50_40_AUDIO,
- INDEX_D10_525_60_40_VIDEO,
- INDEX_D10_525_60_40_AUDIO,
- INDEX_D10_625_50_30_VIDEO,
- INDEX_D10_625_50_30_AUDIO,
- INDEX_D10_525_60_30_VIDEO,
- INDEX_D10_525_60_30_AUDIO,
+ INDEX_D10_VIDEO,
+ INDEX_D10_AUDIO,
INDEX_DV,
INDEX_DNXHD,
INDEX_JPEG2000,
@@ -179,60 +169,16 @@ static const MXFContainerEssenceEntry mxf_essence_container_uls[] = {
{ 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x16,0x01,0x01,0x00 },
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
mxf_write_wav_desc },
- // D-10 625/50 PAL 50mb/s
+ // D-10 Video
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
{ 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 },
mxf_write_cdci_desc },
+ // D-10 Audio
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 },
{ 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
mxf_write_generic_sound_desc },
- // D-10 525/60 NTSC 50mb/s
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x02 },
- mxf_write_cdci_desc },
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
- mxf_write_generic_sound_desc },
- // D-10 625/50 PAL 40mb/s
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x03 },
- mxf_write_cdci_desc },
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
- mxf_write_generic_sound_desc },
- // D-10 525/60 NTSC 40mb/s
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x04 },
- mxf_write_cdci_desc },
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
- mxf_write_generic_sound_desc },
- // D-10 625/50 PAL 30mb/s
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 },
- mxf_write_cdci_desc },
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
- mxf_write_generic_sound_desc },
- // D-10 525/60 NTSC 30mb/s
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x05,0x01,0x01,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 },
- mxf_write_cdci_desc },
- { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 },
- { 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x06,0x01,0x10,0x00 },
- { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 },
- mxf_write_generic_sound_desc },
// DV
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x7F,0x01 },
{ 0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x18,0x01,0x01,0x00 },
@@ -269,6 +215,24 @@ static const MXFContainerEssenceEntry mxf_essence_container_uls[] = {
NULL },
};
+static const UID mxf_d10_codec_uls[] = {
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, // D-10 625/50 PAL 50mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x02 }, // D-10 525/50 NTSC 50mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x03 }, // D-10 625/50 PAL 40mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x04 }, // D-10 525/50 NTSC 40mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, // D-10 625/50 PAL 30mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x06 }, // D-10 525/50 NTSC 30mb/s
+};
+
+static const UID mxf_d10_container_uls[] = {
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, // D-10 625/50 PAL 50mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x02,0x01 }, // D-10 525/50 NTSC 50mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, // D-10 625/50 PAL 40mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, // D-10 525/50 NTSC 40mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, // D-10 625/50 PAL 30mb/s
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x06,0x01 }, // D-10 525/50 NTSC 30mb/s
+};
+
typedef struct MXFContext {
AVClass *av_class;
int64_t footer_partition_offset;
@@ -2482,6 +2446,7 @@ static int mxf_write_header(AVFormatContext *s)
if (!sc)
return AVERROR(ENOMEM);
st->priv_data = sc;
+ sc->index = -1;
if (((i == 0) ^ (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) && s->oformat != &ff_mxf_opatom_muxer) {
av_log(s, AV_LOG_ERROR, "there must be exactly one video stream and it must be the first one\n");
@@ -2541,25 +2506,29 @@ static int mxf_write_header(AVFormatContext *s)
mxf->cbr_index = 1;
if (s->oformat == &ff_mxf_d10_muxer) {
+ int ntsc = mxf->time_base.den != 25;
+ int ul_index;
+
if (st->codecpar->codec_id != AV_CODEC_ID_MPEG2VIDEO) {
av_log(s, AV_LOG_ERROR, "error MXF D-10 only support MPEG-2 Video\n");
return AVERROR(EINVAL);
}
if ((sc->video_bit_rate == 50000000) && (mxf->time_base.den == 25)) {
- sc->index = INDEX_D10_625_50_50_VIDEO;
- } else if ((sc->video_bit_rate == 49999840 || sc->video_bit_rate == 50000000) && (mxf->time_base.den != 25)) {
- sc->index = INDEX_D10_525_60_50_VIDEO;
+ ul_index = 0;
+ } else if ((sc->video_bit_rate == 49999840 || sc->video_bit_rate == 50000000) && ntsc) {
+ ul_index = 1;
} else if (sc->video_bit_rate == 40000000) {
- if (mxf->time_base.den == 25) sc->index = INDEX_D10_625_50_40_VIDEO;
- else sc->index = INDEX_D10_525_60_40_VIDEO;
+ ul_index = 2+ntsc;
} else if (sc->video_bit_rate == 30000000) {
- if (mxf->time_base.den == 25) sc->index = INDEX_D10_625_50_30_VIDEO;
- else sc->index = INDEX_D10_525_60_30_VIDEO;
+ ul_index = 4+ntsc;
} else {
av_log(s, AV_LOG_ERROR, "error MXF D-10 only support 30/40/50 mbit/s\n");
return -1;
}
+ sc->codec_ul = &mxf_d10_codec_uls[ul_index];
+ sc->container_ul = &mxf_d10_container_uls[ul_index];
+ sc->index = INDEX_D10_VIDEO;
sc->signal_standard = 1;
sc->color_siting = 0;
sc->frame_size = (int64_t)sc->video_bit_rate *
@@ -2582,7 +2551,8 @@ static int mxf_write_header(AVFormatContext *s)
st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) {
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;
+ sc->index = INDEX_D10_AUDIO;
+ sc->container_ul = ((MXFStreamContext*)s->streams[0]->priv_data)->container_ul;
sc->frame_size = 4 + 8 * spf[0].samples_per_frame[0] * 4;
} else if (s->oformat == &ff_mxf_opatom_muxer) {
AVRational tbc = av_inv_q(mxf->audio_edit_rate);
@@ -2629,7 +2599,7 @@ static int mxf_write_header(AVFormatContext *s)
}
}
- if (!sc->index) {
+ if (sc->index == -1) {
sc->index = mxf_get_essence_container_ul_index(st->codecpar->codec_id);
if (sc->index == -1) {
av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
@@ -2638,8 +2608,10 @@ static int mxf_write_header(AVFormatContext *s)
}
}
- sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
- sc->container_ul = &mxf_essence_container_uls[sc->index].container_ul;
+ if (!sc->codec_ul)
+ sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
+ if (!sc->container_ul)
+ sc->container_ul = &mxf_essence_container_uls[sc->index].container_ul;
memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
sc->track_essence_element_key[15] = present[sc->index];
--
2.21.0 (Apple Git-122)
More information about the ffmpeg-devel
mailing list