[MPlayer-dev-eng] [PATCH] add mov plaintext subtitle support
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Nov 12 12:27:25 CET 2006
Hello,
attached is a quick hack to support subtitles like in
http://samples.mplayerhq.hu/mov/subtitles-embedded/subtitlemovie.mov
I do not know if it works really right, since above is the only sample I
have.
Just like the other demuxer supporting subtitles it is a bit ugly,
since it sets the subs directly instead of just demuxing them,
unfortunately I don't know the code enough to fix this properly.
Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/demux_mov.c
===================================================================
--- libmpdemux/demux_mov.c (revision 20847)
+++ libmpdemux/demux_mov.c (working copy)
@@ -32,6 +32,9 @@
#include "bswap.h"
+#include "libvo/sub.h"
+extern subtitle *vo_sub;
+
#include "qtpalette.h"
#include "parse_mp4.h" // .MP4 specific stuff
@@ -290,6 +293,7 @@
}
#define MOV_MAX_TRACKS 256
+#define MOV_MAX_SUBLEN 1024
typedef struct {
off_t moov_start;
@@ -300,6 +304,9 @@
mov_track_t* tracks[MOV_MAX_TRACKS];
int timescale; // movie timescale
int duration; // movie duration (in movie timescale units)
+ subtitle subs;
+ char subtext[MOV_MAX_SUBLEN + 1];
+ int current_sub;
} mov_priv_t;
#define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d))
@@ -312,6 +319,7 @@
mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n");
memset(priv,0,sizeof(mov_priv_t));
+ priv->current_sub = -1;
while(1){
int i;
@@ -2115,6 +2123,32 @@
++trak->pos;
+ if (demuxer->sub->id >= 0 && demuxer->sub->id < priv->track_db) {
+ int samplenr = 0;
+ trak = priv->tracks[demuxer->sub->id];
+ while (samplenr < trak->samples_size) {
+ double subpts = (double)trak->samples[samplenr].pts / (double)trak->timescale;
+ if (subpts >= pts) break;
+ samplenr++;
+ }
+ samplenr--;
+ if (samplenr < 0)
+ vo_sub = NULL;
+ else if (samplenr != priv->current_sub) {
+ off_t pos = trak->samples[samplenr].pos + 2;
+ int len = trak->samples[samplenr].size - 2;
+ if (len < 0) len = 0;
+ if (len > MOV_MAX_SUBLEN) len = MOV_MAX_SUBLEN;
+ stream_seek(demuxer->stream, pos);
+ stream_read(demuxer->stream, priv->subtext, len);
+ priv->subtext[len] = 0;
+ priv->subs.lines = 1;
+ priv->subs.text[0] = &priv->subtext;
+ vo_sub = &priv->subs;
+ }
+ vo_osd_changed (OSDTYPE_SUBTITLE);
+ }
+
return 1;
}
More information about the MPlayer-dev-eng
mailing list