aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Härdin <tomas.hardin@codemill.se>2012-12-14 15:39:16 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-12-25 17:45:34 +0100
commit928727f951d6cdfec278a71c88a486d178baa2da (patch)
treeecbd25f2140e808032c9bcc98516944bc796aa8a
parenta752b9b8635ab11f464e215dee76ac02ef6f9a70 (diff)
downloadffmpeg-928727f951d6cdfec278a71c88a486d178baa2da.tar.gz
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>
-rw-r--r--libavformat/mxfdec.c17
-rw-r--r--tests/ref/seek/lavf-mxf2
-rw-r--r--tests/ref/seek/lavf-mxf_d102
3 files changed, 17 insertions, 4 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)
diff --git a/tests/ref/seek/lavf-mxf b/tests/ref/seek/lavf-mxf
index 34dddc3831..9b2346663a 100644
--- a/tests/ref/seek/lavf-mxf
+++ b/tests/ref/seek/lavf-mxf
@@ -30,7 +30,7 @@ ret: 0 st: 0 flags:1 ts: 2.400000
ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460288 size: 24711
ret:-1 st: 1 flags:0 ts: 1.306667
ret: 0 st: 1 flags:1 ts: 0.200833
-ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460288 size: 24711
+ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801
ret: 0 st:-1 flags:0 ts:-0.904994
ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801
ret: 0 st:-1 flags:1 ts: 1.989173
diff --git a/tests/ref/seek/lavf-mxf_d10 b/tests/ref/seek/lavf-mxf_d10
index e091c77633..17cca29c03 100644
--- a/tests/ref/seek/lavf-mxf_d10
+++ b/tests/ref/seek/lavf-mxf_d10
@@ -34,7 +34,7 @@ ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000
ret: 0 st: 1 flags:0 ts: 1.306667
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:5117952 size:150000
ret: 0 st: 1 flags:1 ts: 0.200833
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:5117952 size:150000
+ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:1071104 size:150000
ret: 0 st:-1 flags:0 ts:-0.904994
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000
ret: 0 st:-1 flags:1 ts: 1.989173