From c15ddd92386cbeb80eaa1975a012b4b05e9fe31b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 23 May 2011 20:49:57 +0200 Subject: [PATCH] Handle IDX VobSub files with negative "delay" fields --- ChangeLog | 5 +++++ src/input/r_vobsub.cpp | 16 +++++++++++++++- tests/results.txt | 1 + tests/test-294vobsub_negative_delay.rb | 13 +++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/test-294vobsub_negative_delay.rb diff --git a/ChangeLog b/ChangeLog index 75eb1e84e..19f97b82e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-23 Moritz Bunkus + + * mkvmerge: enhancement: Added support for VobSub IDX files with + negative "delay" fields. + 2011-05-11 Moritz Bunkus * mkvmerge: bug fix: The 'doc type read version' EBML header field diff --git a/src/input/r_vobsub.cpp b/src/input/r_vobsub.cpp index fb69abffe..82612a618 100644 --- a/src/input/r_vobsub.cpp +++ b/src/input/r_vobsub.cpp @@ -204,6 +204,7 @@ vobsub_reader_c::parse_headers() { } } track = new vobsub_track_c(language); + delay = 0; last_timestamp = 0; sort_required = false; continue; @@ -216,10 +217,16 @@ vobsub_reader_c::parse_headers() { line.erase(0, 6); strip(line); + int factor = 1; + if (!line.empty() && (line[0] == '-')) { + factor = -1; + line.erase(0, 1); + } + int64_t timestamp; if (!parse_timecode(line, timestamp, true)) mxerror_fn(m_ti.m_fname, boost::format(Y("line %1%: The 'delay' timestamp could not be parsed.\n")) % line_no); - delay = timestamp; + delay += timestamp * factor; } if ((7 == version) && starts_with_case(line, "timestamp:")) { @@ -262,6 +269,13 @@ vobsub_reader_c::parse_headers() { entry.position = filepos; entry.timestamp = timestamp * factor + delay; + if ( (0 > delay) + && (0 != last_timestamp) + && (entry.timestamp < last_timestamp)) { + delay += last_timestamp - entry.timestamp; + entry.timestamp = last_timestamp; + } + if (0 > entry.timestamp) { mxwarn_fn(m_ti.m_fname, boost::format(Y("Line %1%: The line seems to be a subtitle entry but the timecode was negative even after adding the track " diff --git a/tests/results.txt b/tests/results.txt index 681dd1787..fd18e746a 100644 --- a/tests/results.txt +++ b/tests/results.txt @@ -140,3 +140,4 @@ T_290seven_bytes_aac_codec_data:d8680e35f0f6b595dce0fcb8af3b6e9e:passed:20110415 T_291waveformatextensible:wav-avi:passed:20110415-124159:0.057127293 T_292avi_aac_706d_privsize_huge:7b34a92c34461e869834e7db0c63ab97:passed:20110422-152313:0.042857788 T_293aac_adif_misdetected_as_video:3:passed:20110426-091956:0.02536219 +T_294vobsub_negative_delay:6e1c59551b7ad05fa570bed2ffc926fe:passed:20110523-204847:1.41224474 diff --git a/tests/test-294vobsub_negative_delay.rb b/tests/test-294vobsub_negative_delay.rb new file mode 100644 index 000000000..52b7059e5 --- /dev/null +++ b/tests/test-294vobsub_negative_delay.rb @@ -0,0 +1,13 @@ +#!/usr/bin/ruby -w + +class T_294vobsub_negative_delay < Test + def description + "mkvmerge / VobSub with negative \"delay\" fields" + end + + def run + merge "data/vobsub/House.S07E22.idx" + hash_tmp + end +end +