From 9580dd3d8dfd70a6088ff4d579659a25672c8352 Mon Sep 17 00:00:00 2001 From: ranma Date: Sat, 2 Jul 2005 15:22:49 +0000 Subject: avi subtitle stream dumper git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15887 b3059339-0415-0410-9bf9-f77b7e298cf2 --- TOOLS/avisubdump.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 TOOLS/avisubdump.c (limited to 'TOOLS') diff --git a/TOOLS/avisubdump.c b/TOOLS/avisubdump.c new file mode 100644 index 0000000000..77f914cceb --- /dev/null +++ b/TOOLS/avisubdump.c @@ -0,0 +1,199 @@ +/* + * avisubdump + * + * avi vobsub subtitle stream dumper (c) 2004 Tobias Diedrich + * Licensed under GNU GPLv2 or (at your option) any later version. + * + * Compile with "make avisubdump" + */ + +#define _LARGEFILE_SOURCE +#define _FILE_OFFSET_BITS 64 +#include +#include +#include +#include +#include +#include + +#define FCC(a,b,c,d) (((a))|((b)<<8)|((c)<<16)|((d)<<24)) + +#define FCC_RIFF FCC('R','I','F','F') +#define FCC_LIST FCC('L','I','S','T') +#define FCC_strh FCC('s','t','r','h') +#define FCC_txts FCC('t','x','t','s') +#define FCC_GAB2 FCC('G','A','B','2') + +#define GAB_LANGUAGE 0 +#define GAB_ENTRY 1 +#define GAB_LANGUAGE_UNICODE 2 +#define GAB_ENTRY_UNICODE 3 +#define GAB_RAWTEXTSUBTITLE 4 + +static char *subfile; + +static unsigned int getle16(FILE* f){ + unsigned int res; + + res = fgetc(f); + res |= fgetc(f) << 8; + + return res; +} + +static unsigned int getle(FILE* f){ + unsigned int res; + + res = fgetc(f); + res |= fgetc(f) << 8; + res |= fgetc(f) << 16; + res |= fgetc(f) << 24; + + return res; +} + +static void skip(FILE *f, int len) +{ + if (f != stdin) { + fseek(f,len,SEEK_CUR); + } else { + void *buf = malloc(len); + fread(buf,len,1,f); + free(buf); + } +} + +static int stream_id(unsigned int id) +{ + char c1,c2; + c1 = (char)(id & 0xff); + c2 = (char)((id >> 8) & 0xff); + if (c1 >= '0' && c1 <= '9' && + c2 >= '0' && c2 <= '9') { + c1 -= '0'; + c2 -= '0'; + return c1*10+c2; + } + return -1; +} + +static int dumpsub_gab2(FILE *f, int size) { + int ret = 0; + + while (ret + 6 <= size) { + unsigned int len, id; + char *buf; + int i, fd; + + id = getle16(f); ret += 2; + len = getle(f); ret += 4; + if (ret + len > size) break; + + buf = malloc(len); + ret += fread(buf, 1, len, f); + + switch (id) { + case GAB_LANGUAGE_UNICODE: + for (i=0; i> 8, + id >> 16, + id >> 24); + if (id == FCC_txts) { + substream = stream; + fprintf(stderr, " (subtitle stream)"); + } + fprintf(stderr, ".\n"); + stream++; + } else if (stream_id(id) == substream) { + unsigned int subid; + subid = getle(f); len -= 4; + if (subid != FCC_GAB2) { + fprintf(stderr, + "Unknown subtitle chunk %c%c%c%c (%08x).\n", + id, id >> 8, id >> 16, id >> 24, subid); + } else { + skip(f,1); len -= 1; + len -= dumpsub_gab2(f, len); + } + } + len+=len&1; + skip(f,len); + } +} + +int main(int argc,char* argv[]) +{ + FILE* f; + int i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + f=fopen(argv[argc-1],"rb"); + + if (!f) { + fprintf(stderr, "Could not open '%s': %s\n", + argv[argc-1], strerror(errno)); + exit(-errno); + } + + subfile = malloc(strlen(argv[1]) + 4); + strcpy(subfile, argv[1]); + for (i=strlen(subfile); i>0 && subfile[i] != '.'; i--); + subfile[i] = 0; + strcat(subfile, ".ssa"); + + dump(f); + + free(subfile); + + return 0; +} + -- cgit v1.2.3