summaryrefslogtreecommitdiffstats
path: root/sub/sd_ass.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-23 22:10:10 +0200
committerwm4 <wm4@nowhere>2013-06-25 00:11:54 +0200
commit7e033da8923801da5f8ef08f442dd50f172bac7c (patch)
tree33e71c4cb30fa195f76a5435c520da9bf6066cb5 /sub/sd_ass.c
parent1058d80a5ecafeb4eebcc558be548ac6877955ef (diff)
downloadmpv-7e033da8923801da5f8ef08f442dd50f172bac7c.tar.bz2
mpv-7e033da8923801da5f8ef08f442dd50f172bac7c.tar.xz
sd_ass: disable special handling of subtitles with duration 0
sd_ass contains some code that treats subtitle events with duration 0 specially, and adjust their duration so that they will disappear with the next event. This is most likely not needed anymore. Some subtitle formats allow omitting the duration so that the event is visible until the next one, but both subreader.c as well as libavformat subtitle demuxers already handle this. Subtitles embedded in mp4 files (movtext) used to trigger this code. But these files appear to export subtitle duration correctly (at least libavcodec's movtext decoder is using this assumption). Since commit 6dbedd2 changed demux_lavf to actually copy the packet duration field, the code removed with this commit isn't needed anymore for correct display of movtext subtitles. (The change in sd_movtext is for dropping empty subtitle events, which would now be "displayed" - libavcodec does the same.) On the other hand, this code incorrectly displayed hidden events in .srt subtitles. See for example the first event in SubRip_capability_tester.srt (part of FFmpeg's FATE). These intentionally have a duration of 0, and should not be displayed. (As of with this commit, they are still displayed in external .srt subs because of subreader.c hacks.) However, we can't be 100% sure that this code is really unneeded, so just comment the code. Hopefully it can be removed if there are no regressions after some weeks or months.
Diffstat (limited to 'sub/sd_ass.c')
-rw-r--r--sub/sd_ass.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index 22cd33b113..fad323a735 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -32,6 +32,10 @@
#include "ass_mp.h"
#include "sd.h"
+// Enable code that treats subtitle events with duration 0 specially, and
+// adjust their duration so that they will disappear with the next event.
+#define INCOMPLETE_EVENTS 0
+
struct sd_ass_priv {
struct ass_track *ass_track;
bool vsfilter_aspect;
@@ -114,6 +118,7 @@ static void decode(struct sd *sd, struct demux_packet *packet)
}
long long ipts = pts * 1000 + 0.5;
long long iduration = duration * 1000 + 0.5;
+#if INCOMPLETE_EVENTS
if (ctx->incomplete_event) {
ctx->incomplete_event = false;
ASS_Event *event = track->events + track->n_events - 1;
@@ -144,6 +149,21 @@ static void decode(struct sd *sd, struct demux_packet *packet)
iduration = 10000;
ctx->incomplete_event = true;
}
+#else
+ if (duration <= 0) {
+ mp_msg(MSGT_SUBREADER, MSGL_WARN, "Subtitle without duration or "
+ "duration set to 0 at pts %f, ignored\n", pts);
+ return;
+ }
+ if (!sd->no_remove_duplicates) {
+ for (int i = 0; i < track->n_events; i++) {
+ if (track->events[i].Start == ipts
+ && (track->events[i].Duration == iduration)
+ && strcmp(track->events[i].Text, text) == 0)
+ return; // We've already added this subtitle
+ }
+ }
+#endif
int eid = ass_alloc_event(track);
ASS_Event *event = track->events + eid;
event->Start = ipts;