diff options
author | Tomas Härdin <tomas.hardin@codemill.se> | 2012-12-14 18:39:16 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-12-25 20:45:34 +0400 |
commit | 928727f951d6cdfec278a71c88a486d178baa2da (patch) | |
tree | ecbd25f2140e808032c9bcc98516944bc796aa8a /libavformat | |
parent | a752b9b8635ab11f464e215dee76ac02ef6f9a70 (diff) |
mxfdec: Rescale audio stream duration from EditRate to SampleRate
Since 83cab07 audio stream time bases are based on SampleRate, not EditRate.
This fixes trac ticket #2029 and a few seeking issues.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/mxfdec.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 0141dd92f1..e45d99faf3 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -134,6 +134,7 @@ typedef struct { AVRational edit_rate; int intra_only; uint64_t sample_count; + int64_t original_duration; ///< duration before multiplying st->duration by SampleRate/EditRate } MXFTrack; typedef struct { @@ -1445,7 +1446,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } st->id = source_track->track_id; st->priv_data = source_track; - st->duration = component->duration; + source_track->original_duration = st->duration = component->duration; if (st->duration == -1) st->duration = AV_NOPTS_VALUE; st->start_time = component->start_position; @@ -1457,6 +1458,9 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } avpriv_set_pts_info(st, 64, material_track->edit_rate.den, material_track->edit_rate.num); + /* ensure SourceTrack EditRate == MaterialTrack EditRate since only the former is accessible via st->priv_data */ + source_track->edit_rate = material_track->edit_rate; + PRINT_KEY(mxf->fc, "data definition ul", source_track->sequence->data_definition_ul); codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, &source_track->sequence->data_definition_ul); st->codec->codec_type = codec_ul->id; @@ -1570,6 +1574,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) avpriv_set_pts_info(st, 64, 1, 48000); } + /* if duration is set, rescale it from EditRate to SampleRate */ + if (st->duration != AV_NOPTS_VALUE) + st->duration = av_rescale_q(st->duration, av_inv_q(material_track->edit_rate), st->time_base); + /* TODO: implement AV_CODEC_ID_RAWAUDIO */ if (st->codec->codec_id == AV_CODEC_ID_PCM_S16LE) { if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) @@ -2298,6 +2306,11 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti int64_t seekpos; int i, ret; MXFIndexTable *t; + MXFTrack *source_track = st->priv_data; + + /* if audio then truncate sample_time to EditRate */ + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + sample_time = av_rescale_q(sample_time, st->time_base, av_inv_q(source_track->edit_rate)); if (mxf->nb_index_tables <= 0) { if (!s->bit_rate) @@ -2323,7 +2336,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti } else { /* no IndexEntryArray (one or more CBR segments) * make sure we don't seek past the end */ - sample_time = FFMIN(sample_time, st->duration - 1); + sample_time = FFMIN(sample_time, source_track->original_duration - 1); } if ((ret = mxf_edit_unit_absolute_offset(mxf, t, sample_time, &sample_time, &seekpos, 1)) << 0) |