Message ID | 20180610103650.10155-3-cus@passwd.hu |
---|---|
State | New |
Headers | show |
sön 2018-06-10 klockan 12:36 +0200 skrev Marton Balint: > Also make sure we set a valid track index sid and a valid track edit rate in > order for the index to be useful. > > > Signed-off-by: Marton Balint <cus@passwd.hu> > --- > libavformat/mxfdec.c | 39 +++++++++++++++++++++++---------------- > 1 file changed, 23 insertions(+), 16 deletions(-) > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c > index 927653b515..1ab34f4873 100644 > --- a/libavformat/mxfdec.c > +++ b/libavformat/mxfdec.c > @@ -2877,35 +2877,33 @@ static void mxf_handle_small_eubc(AVFormatContext *s) > } > > /** > - * Deal with the case where OPAtom files does not have any IndexTableSegments. > + * Deal with the case where ClipWrapped essences does not have any IndexTableSegments. > */ > -static int mxf_handle_missing_index_segment(MXFContext *mxf) > +static int mxf_handle_missing_index_segment(MXFContext *mxf, AVStream *st) > { > - AVFormatContext *s = mxf->fc; > - AVStream *st = NULL; > + MXFTrack *track = st->priv_data; > MXFIndexTableSegment *segment = NULL; > MXFPartition *p = NULL; > int essence_partition_count = 0; > int i, ret; > > - st = mxf_get_opatom_stream(mxf); > - if (!st) > - return 0; > - > /* TODO: support raw video without an index if they exist */ > - if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(st->codecpar->codec_id)) > + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(st->codecpar->codec_id) || track->wrapping != ClipWrapped) > return 0; > > - /* check if file already has a IndexTableSegment */ > + /* check if track already has a IndexTableSegment */ "an" :) > for (i = 0; i < mxf->metadata_sets_count; i++) { > - if (mxf->metadata_sets[i]->type == IndexTableSegment) > - return 0; > + if (mxf->metadata_sets[i]->type == IndexTableSegment) { > + MXFIndexTableSegment *s = (MXFIndexTableSegment*)mxf->metadata_sets[i]; > + if (s->body_sid == track->body_sid) > + return 0; > + } Feels like this would have been pretty bork before? Or maybe it just worked because OPAtom. The rest looks OK as far as I can tell /Tomas
On Wed, 13 Jun 2018, Tomas Härdin wrote: > sön 2018-06-10 klockan 12:36 +0200 skrev Marton Balint: >> Also make sure we set a valid track index sid and a valid track edit rate in >> order for the index to be useful. >> >> > Signed-off-by: Marton Balint <cus@passwd.hu> >> --- >> libavformat/mxfdec.c | 39 +++++++++++++++++++++++---------------- >> 1 file changed, 23 insertions(+), 16 deletions(-) >> >> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c >> index 927653b515..1ab34f4873 100644 >> --- a/libavformat/mxfdec.c >> +++ b/libavformat/mxfdec.c >> @@ -2877,35 +2877,33 @@ static void mxf_handle_small_eubc(AVFormatContext *s) >> } >> >> /** >> - * Deal with the case where OPAtom files does not have any IndexTableSegments. >> + * Deal with the case where ClipWrapped essences does not have any IndexTableSegments. >> */ >> -static int mxf_handle_missing_index_segment(MXFContext *mxf) >> +static int mxf_handle_missing_index_segment(MXFContext *mxf, AVStream *st) >> { >> - AVFormatContext *s = mxf->fc; >> - AVStream *st = NULL; >> + MXFTrack *track = st->priv_data; >> MXFIndexTableSegment *segment = NULL; >> MXFPartition *p = NULL; >> int essence_partition_count = 0; >> int i, ret; >> >> - st = mxf_get_opatom_stream(mxf); >> - if (!st) >> - return 0; >> - >> /* TODO: support raw video without an index if they exist */ >> - if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(st->codecpar->codec_id)) >> + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(st->codecpar->codec_id) || track->wrapping != ClipWrapped) >> return 0; >> >> - /* check if file already has a IndexTableSegment */ >> + /* check if track already has a IndexTableSegment */ > > "an" :) Fixed locally. > >> for (i = 0; i < mxf->metadata_sets_count; i++) { >> - if (mxf->metadata_sets[i]->type == IndexTableSegment) >> - return 0; >> + if (mxf->metadata_sets[i]->type == IndexTableSegment) { >> + MXFIndexTableSegment *s = (MXFIndexTableSegment*)mxf->metadata_sets[i]; >> + if (s->body_sid == track->body_sid) >> + return 0; >> + } > > Feels like this would have been pretty bork before? Or maybe it just > worked because OPAtom. Yeah, it was only used for OPAtom before, therefore multiple index tables was not an issue. Regards, Marton
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 927653b515..1ab34f4873 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -2877,35 +2877,33 @@ static void mxf_handle_small_eubc(AVFormatContext *s) } /** - * Deal with the case where OPAtom files does not have any IndexTableSegments. + * Deal with the case where ClipWrapped essences does not have any IndexTableSegments. */ -static int mxf_handle_missing_index_segment(MXFContext *mxf) +static int mxf_handle_missing_index_segment(MXFContext *mxf, AVStream *st) { - AVFormatContext *s = mxf->fc; - AVStream *st = NULL; + MXFTrack *track = st->priv_data; MXFIndexTableSegment *segment = NULL; MXFPartition *p = NULL; int essence_partition_count = 0; int i, ret; - st = mxf_get_opatom_stream(mxf); - if (!st) - return 0; - /* TODO: support raw video without an index if they exist */ - if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(st->codecpar->codec_id)) + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(st->codecpar->codec_id) || track->wrapping != ClipWrapped) return 0; - /* check if file already has a IndexTableSegment */ + /* check if track already has a IndexTableSegment */ for (i = 0; i < mxf->metadata_sets_count; i++) { - if (mxf->metadata_sets[i]->type == IndexTableSegment) - return 0; + if (mxf->metadata_sets[i]->type == IndexTableSegment) { + MXFIndexTableSegment *s = (MXFIndexTableSegment*)mxf->metadata_sets[i]; + if (s->body_sid == track->body_sid) + return 0; + } } /* find the essence partition */ for (i = 0; i < mxf->partitions_count; i++) { /* BodySID == 0 -> no essence */ - if (!mxf->partitions[i].body_sid) + if (mxf->partitions[i].body_sid != track->body_sid) continue; p = &mxf->partitions[i]; @@ -2924,12 +2922,19 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf) return ret; } + /* Make sure we have nonzero unique index_sid, body_sid will be ok, because + * using the same SID for index is forbidden in MXF. */ + if (!track->index_sid) + track->index_sid = track->body_sid; + track->edit_rate = av_inv_q(st->time_base); + segment->type = IndexTableSegment; /* stream will be treated as small EditUnitByteCount */ segment->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; segment->index_start_position = 0; - segment->index_duration = s->streams[0]->duration; - segment->index_sid = p->index_sid; + segment->index_duration = st->duration; + segment->index_edit_rate = track->edit_rate; + segment->index_sid = track->index_sid; segment->body_sid = p->body_sid; return 0; } @@ -3100,7 +3105,9 @@ static int mxf_read_header(AVFormatContext *s) if ((ret = mxf_parse_structural_metadata(mxf)) < 0) goto fail; - mxf_handle_missing_index_segment(mxf); + for (int i = 0; i < s->nb_streams; i++) + mxf_handle_missing_index_segment(mxf, s->streams[i]); + if ((ret = mxf_compute_index_tables(mxf)) < 0) goto fail;
Also make sure we set a valid track index sid and a valid track edit rate in order for the index to be useful. Signed-off-by: Marton Balint <cus@passwd.hu> --- libavformat/mxfdec.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-)