summaryrefslogtreecommitdiff
path: root/libavformat/matroskadec.c
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2012-05-22 21:50:02 -0700
committerPhilip Langdale <philipl@overt.org>2012-08-31 20:22:49 -0700
commit9d89c8b3ac80134f0bd32512eb208b113795ab9e (patch)
tree69d2f7f93e53afe2599209619c2fdb6acdbde653 /libavformat/matroskadec.c
parent6a0dfe3b9dc6b9420b25bfd089c655583cf045d6 (diff)
matroskadec, matroskadec, srtenc: Read/Write duration for subtitles.
After much discussion and back-and-forth, we reached the conclusion that matroska uses convergence_duration for subtitle duration because a 32bit value isn't large enough to store the duration if sub-micro-second timebases are used. Matroska may not be the only one that supports these timebases, but it's certainly the only one that ffmpeg attempts to support in this way. The long term solution that we seemed to reach was that if we encounter a matroska file with a sub-micro-second timebase, we should internally scale it up to at least micro-second, and then duration can be used normally. This suggests that on the encode side, we should not allow generation of files with sub-micro-second timebases, but that's a separate issue. That being a non-trivial change, and the subtitle interoperability breakage being very real, I'm re-submitting this small change for consideration. In this diff, we make sure that duration is populated by the matroska demuxer, and that convergence_duration is respected in matroskaenc and srtenc, but that duration is used otherwise. This ends up being a strict improvement - pipelines that use convergence duration are unchanged, and ones that are currently broken due to the duration mismatch will start working - except for the ones with the extreme timebases, but those were already broken. Signed-off-by: Philip Langdale <philipl@overt.org>
Diffstat (limited to 'libavformat/matroskadec.c')
-rw-r--r--libavformat/matroskadec.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 1d0dbb3296..c4e0438c1d 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2105,10 +2105,29 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
else
pkt->pts = timecode;
pkt->pos = pos;
- if (st->codec->codec_id == AV_CODEC_ID_SUBRIP)
+ if (st->codec->codec_id == AV_CODEC_ID_SUBRIP) {
+ /*
+ * For backward compatibility.
+ * Historically, we have put subtitle duration
+ * in convergence_duration, on the off chance
+ * that the time_scale is less than 1us, which
+ * could result in a 32bit overflow on the
+ * normal duration field.
+ */
pkt->convergence_duration = lace_duration;
- else if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE)
+ }
+
+ if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE ||
+ lace_duration <= INT_MAX) {
+ /*
+ * For non subtitle tracks, just store the duration
+ * as normal.
+ *
+ * If it's a subtitle track and duration value does
+ * not overflow a uint32, then also store it normally.
+ */
pkt->duration = lace_duration;
+ }
if (st->codec->codec_id == AV_CODEC_ID_SSA)
matroska_fix_ass_packet(matroska, pkt, lace_duration);