Only dump to stdout

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15892 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
ranma 2005-07-02 19:35:15 +00:00
parent e0eb36e389
commit ed3073c074
1 changed files with 6 additions and 20 deletions

View File

@ -4,7 +4,7 @@
* avi vobsub subtitle stream dumper (c) 2004 Tobias Diedrich * avi vobsub subtitle stream dumper (c) 2004 Tobias Diedrich
* Licensed under GNU GPLv2 or (at your option) any later version. * Licensed under GNU GPLv2 or (at your option) any later version.
* *
* Compile with "make avisubdump" * The subtitles are dumped to stdout.
*/ */
#define _LARGEFILE_SOURCE #define _LARGEFILE_SOURCE
@ -30,8 +30,6 @@
#define GAB_ENTRY_UNICODE 3 #define GAB_ENTRY_UNICODE 3
#define GAB_RAWTEXTSUBTITLE 4 #define GAB_RAWTEXTSUBTITLE 4
static char *subfile;
static unsigned int getle16(FILE* f){ static unsigned int getle16(FILE* f){
unsigned int res; unsigned int res;
@ -83,7 +81,7 @@ static int dumpsub_gab2(FILE *f, int size) {
while (ret + 6 <= size) { while (ret + 6 <= size) {
unsigned int len, id; unsigned int len, id;
char *buf; char *buf;
int i, fd; int i;
id = getle16(f); ret += 2; id = getle16(f); ret += 2;
len = getle(f); ret += 4; len = getle(f); ret += 4;
@ -93,22 +91,18 @@ static int dumpsub_gab2(FILE *f, int size) {
ret += fread(buf, 1, len, f); ret += fread(buf, 1, len, f);
switch (id) { switch (id) {
case GAB_LANGUAGE_UNICODE: case GAB_LANGUAGE_UNICODE: /* FIXME: convert to utf-8; endianness */
for (i=0; i<len; i++) buf[i] = buf[i*2]; for (i=0; i<len; i++) buf[i] = buf[i*2];
case GAB_LANGUAGE: case GAB_LANGUAGE:
fprintf(stderr, "LANGUAGE: %s\n", buf); fprintf(stderr, "LANGUAGE: %s\n", buf);
break; break;
case GAB_ENTRY_UNICODE: case GAB_ENTRY_UNICODE: /* FIXME: convert to utf-8; endianness */
for (i=0; i<len; i++) buf[i] = buf[i*2]; for (i=0; i<len; i++) buf[i] = buf[i*2];
case GAB_ENTRY: case GAB_ENTRY:
fprintf(stderr, "ENTRY: %s\n", buf); fprintf(stderr, "ENTRY: %s\n", buf);
break; break;
case GAB_RAWTEXTSUBTITLE: case GAB_RAWTEXTSUBTITLE:
printf("%s", buf); printf("%s", buf);
fd = open(subfile, O_CREAT|O_APPEND|O_WRONLY, 0644);
write(fd, buf, len);
close(fd);
fprintf(stderr, "Dumped subtitles to %s.\n", subfile);
break; break;
default: default:
fprintf(stderr, "Unknown type %d, len %d\n", id, len); fprintf(stderr, "Unknown type %d, len %d\n", id, len);
@ -169,14 +163,14 @@ static void dump(FILE *f) {
int main(int argc,char* argv[]) int main(int argc,char* argv[])
{ {
FILE* f; FILE* f;
int i;
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: %s <avi>\n", argv[0]); fprintf(stderr, "Usage: %s <avi>\n", argv[0]);
exit(1); exit(1);
} }
f=fopen(argv[argc-1],"rb"); if (strcmp(argv[argc-1], "-") == 0) f=stdin;
else f=fopen(argv[argc-1],"rb");
if (!f) { if (!f) {
fprintf(stderr, "Could not open '%s': %s\n", fprintf(stderr, "Could not open '%s': %s\n",
@ -184,16 +178,8 @@ int main(int argc,char* argv[])
exit(-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); dump(f);
free(subfile);
return 0; return 0;
} }