Project: FFmpeg2theora
Revision: 15235
Author: j
Date: 01 Sep 2008 07:26:15
Changes:various other cleanup/improvements. by ogg.k.ogg.k to subtitle part, update changelog
Files:modified: /trunk/ffmpeg2theora/src/subtitles.c (
try)
modified: /trunk/ffmpeg2theora/ChangeLog (
try)
modified: /trunk/ffmpeg2theora/ffmpeg2theora.1 (
try)
modified: /trunk/ffmpeg2theora/src/theorautils.c (
try)
modified: /trunk/ffmpeg2theora/subtitles.txt (
try)
modified: /trunk/ffmpeg2theora (
try)
modified: /trunk/ffmpeg2theora/src/ffmpeg2theora.c (
try)
Diff:
| ... | ...@@ -131,7 +131,7 @@ |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /* very simple implementation when no iconv */ |
| 134 | | static void convert_subtitle_to_utf8(F2T_ENCODING encoding,unsigned char *text,int ignore_non_utf8) |
| 134 | static void convert_subtitle_to_utf8(F2T_ENCODING encoding,char *text,int ignore_non_utf8) |
| 135 | 135 | { |
| 136 | 136 | size_t nbytes; |
| 137 | 137 | char *ptr,*newtext; |
| ... | ...@@ -151,7 +151,7 @@ |
| 151 | 151 | size_t wlen0; |
| 152 | 152 | |
| 153 | 153 | nbytes = strlen(text)+1; |
| 154 | | newtext=(unsigned char*)malloc(nbytes); |
| 154 | newtext=(char*)malloc(nbytes); |
| 155 | 155 | if (!newtext) { |
| 156 | 156 | fprintf(stderr, "WARNING - Memory allocation failed - cannot convert text\n"); |
| 157 | 157 | return; |
| ... | ...@@ -193,18 +193,18 @@ |
| 193 | 193 | nbytes=0; |
| 194 | 194 | for (ptr=text;*ptr;++ptr) { |
| 195 | 195 | nbytes++; |
| 196 | | if (0x80&*ptr) nbytes++; |
| 196 | if (0x80&*(unsigned char*)ptr) nbytes++; |
| 197 | 197 | } |
| 198 | | newtext=(unsigned char*)malloc(1+nbytes); |
| 198 | newtext=(char*)malloc(1+nbytes); |
| 199 | 199 | if (!newtext) { |
| 200 | 200 | fprintf(stderr, "WARNING - Memory allocation failed - cannot convert text\n"); |
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | nbytes=0; |
| 204 | 204 | for (ptr=text;*ptr;++ptr) { |
| 205 | | if (0x80&*ptr) { |
| 206 | | newtext[nbytes++]=0xc0|((*ptr)>>6); |
| 207 | | newtext[nbytes++]=0x80|((*ptr)&0x3f); |
| 205 | if (0x80&*(unsigned char*)ptr) { |
| 206 | newtext[nbytes++]=0xc0|((*(unsigned char*)ptr)>>6); |
| 207 | newtext[nbytes++]=0x80|((*(unsigned char*)ptr)&0x3f); |
| 208 | 208 | } |
| 209 | 209 | else { |
| 210 | 210 | newtext[nbytes++]=*ptr; |
| ... | ...@@ -222,8 +222,10 @@ |
| 222 | 222 | |
| 223 | 223 | static void remove_last_newline(char *text) |
| 224 | 224 | { |
| 225 | | char *ptr = text+strlen(text)-1; |
| 226 | | if (*ptr=='\n') *ptr=0; |
| 225 | if (*text) { |
| 226 | char *ptr = text+strlen(text)-1; |
| 227 | if (*ptr=='\n') *ptr=0; |
| 228 | } |
| 227 | 229 | } |
| 228 | 230 | |
| 229 | 231 | #endif |
| ... | ...@@ -242,9 +244,12 @@ |
| 242 | 244 | double t1=0.0; |
| 243 | 245 | static char str[4096]; |
| 244 | 246 | int warned=0; |
| 247 | FILE *f; |
| 248 | size_t len; |
| 249 | unsigned int line=0; |
| 245 | 250 | |
| 246 | 251 | this->subtitles = NULL; |
| 247 | | FILE *f = fopen(this->filename, "r"); |
| 252 | f = fopen(this->filename, "r"); |
| 248 | 253 | if (!f) { |
| 249 | 254 | fprintf(stderr,"WARNING - Failed to open subtitles file %s (%s)\n", this->filename, strerror(errno)); |
| 250 | 255 | return -1; |
| ... | ...@@ -258,27 +263,33 @@ |
| 258 | 263 | } |
| 259 | 264 | |
| 260 | 265 | fgets2(str,sizeof(str),f); |
| 266 | ++line; |
| 261 | 267 | while (!feof(f)) { |
| 262 | 268 | switch (need) { |
| 263 | 269 | case need_id: |
| 264 | | ret=sscanf(str,"%d\n",&id); |
| 265 | | if (ret!=1) { |
| 266 | | fprintf(stderr,"WARNING - Syntax error: %s\n",str); |
| 267 | | fclose(f); |
| 268 | | free(this->subtitles); |
| 269 | | return -1; |
| 270 | if (!strcmp(str,"\n")) { |
| 271 | /* be nice and ignore extra empty lines between records */ |
| 270 | 272 | } |
| 271 | | if (id!=last_seen_id+1) { |
| 272 | | fprintf(stderr,"WARNING - non consecutive ids: %s - pretending not to have noticed\n",str); |
| 273 | else { |
| 274 | ret=sscanf(str,"%d\n",&id); |
| 275 | if (ret!=1) { |
| 276 | fprintf(stderr,"WARNING - %s:%u: Syntax error: %s\n",this->filename,line,str); |
| 277 | fclose(f); |
| 278 | free(this->subtitles); |
| 279 | return -1; |
| 280 | } |
| 281 | if (id!=last_seen_id+1) { |
| 282 | fprintf(stderr,"WARNING - %s:%u: non consecutive ids: %s - pretending not to have noticed\n",this->filename,line,str); |
| 283 | } |
| 284 | last_seen_id=id; |
| 285 | need=need_timing; |
| 286 | strcpy(text,""); |
| 273 | 287 | } |
| 274 | | last_seen_id=id; |
| 275 | | need=need_timing; |
| 276 | | strcpy(text,""); |
| 277 | 288 | break; |
| 278 | 289 | case need_timing: |
| 279 | 290 | ret=sscanf(str,"%d:%d:%d%*[.,]%d --> %d:%d:%d%*[.,]%d\n",&h0,&m0,&s0,&ms0,&h1,&m1,&s1,&ms1); |
| 280 | 291 | if (ret!=8) { |
| 281 | | fprintf(stderr,"WARNING - Syntax error: %s\n",str); |
| 292 | fprintf(stderr,"WARNING - %s:%u: Syntax error: %s\n",this->filename,line,str); |
| 282 | 293 | fclose(f); |
| 283 | 294 | free(this->subtitles); |
| 284 | 295 | return -1; |
| ... | ...@@ -295,8 +306,8 @@ |
| 295 | 306 | remove_last_newline(text); |
| 296 | 307 | |
| 297 | 308 | /* we want all text to be UTF8 */ |
| 298 | | convert_subtitle_to_utf8(this->subtitles_encoding,(unsigned char*)text,ignore_non_utf8); |
| 299 | | size_t len = strlen(text); |
| 309 | convert_subtitle_to_utf8(this->subtitles_encoding,text,ignore_non_utf8); |
| 310 | len = strlen(text); |
| 300 | 311 | this->subtitles = (ff2theora_subtitle*)realloc(this->subtitles, (this->num_subtitles+1)*sizeof(ff2theora_subtitle)); |
| 301 | 312 | if (!this->subtitles) { |
| 302 | 313 | fprintf(stderr, "Out of memory\n"); |
| ... | ...@@ -307,7 +318,7 @@ |
| 307 | 318 | ret=kate_text_validate(kate_utf8,text,len+1); |
| 308 | 319 | if (ret<0) { |
| 309 | 320 | if (!warned) { |
| 310 | | fprintf(stderr,"WARNING: subtitle %s is not valid utf-8\n",text); |
| 321 | fprintf(stderr,"WARNING - %s:%u: subtitle %s is not valid utf-8\n",this->filename,line,text); |
| 311 | 322 | fprintf(stderr," further invalid subtitles will NOT be flagged\n"); |
| 312 | 323 | warned=1; |
| 313 | 324 | } |
| ... | ...@@ -327,15 +338,27 @@ |
| 327 | 338 | need=need_id; |
| 328 | 339 | } |
| 329 | 340 | else { |
| 330 | | strcat(text,str); |
| 341 | /* in case of very long subtitles */ |
| 342 | len=strlen(text); |
| 343 | if (len+strlen(str) >= sizeof(text)) { |
| 344 | fprintf(stderr,"WARNING - %s:%u: subtitle text is too long - truncated\n",this->filename,line); |
| 345 | } |
| 346 | strncpy(text+len,str,sizeof(text)-len); |
| 347 | text[sizeof(text)-1]=0; |
| 331 | 348 | } |
| 332 | 349 | break; |
| 333 | 350 | } |
| 334 | 351 | fgets2(str,sizeof(str),f); |
| 352 | ++line; |
| 335 | 353 | } |
| 336 | 354 | |
| 337 | 355 | fclose(f); |
| 338 | 356 | |
| 357 | if (need!=need_id) { |
| 358 | /* shouldn't be a problem though, but warn */ |
| 359 | fprintf(stderr,"WARNING - %s:%u: missing data in %s - truncated file ?\n",this->filename,line,this->filename); |
| 360 | } |
| 361 | |
| 339 | 362 | /* fprintf(stderr," %u subtitles loaded.\n", this->num_subtitles); */ |
| 340 | 363 | |
| 341 | 364 | return this->num_subtitles; |
| ... | ...@@ -1,7 +1,8 @@ |
| 1 | 1 | 0.22 ??? |
| 2 | 2 | - enable v4l input again (-f video4linux or -f video4linux2) |
| 3 | 3 | - ability to set framerate for image sequences (--inputfps) |
| 4 | | - fix several memory leaks |
| 4 | - fix several memory leaks |
| 5 | - if only width or height are given, the other is set to preserve aspect ratio |
| 5 | 6 | |
| 6 | 7 | 0.21 2008-05-19 |
| 7 | 8 | - switch default extension to .ogv |
| ... | ...@@ -1,5 +1,5 @@ |
| 1 | 1 | .\" Hey, EMACS: -*- nroff -*- |
| 2 | | .TH FFMPEG2THEORA 1 "December 30, 2005" |
| 2 | .TH FFMPEG2THEORA 1 "August 31, 2008" |
| 3 | 3 | .\" Please adjust this date whenever revising the manpage. |
| 4 | 4 | .\" |
| 5 | 5 | .\" Some roff macros, for reference: |
| ... | ...@@ -148,29 +148,34 @@ |
| 148 | 148 | .TP |
| 149 | 149 | .B \-\-subtitles |
| 150 | 150 | Encode subtitles from the given file to a multiplexed Kate stream. |
| 151 | | The input file should be in SubRip (.srt) format, encoded in utf-8, |
| 151 | The input file should be in SubRip (.srt) format, encoded in UTF-8, |
| 152 | 152 | unless the --subtitles-encoding option is also given. |
| 153 | 153 | .TP |
| 154 | 154 | .B \-\-subtitles-encoding encoding |
| 155 | 155 | Assumes the corresponding subtitles file is encoded in the given |
| 156 | | encoding (utf-8 and iso-8859-1 (aka latin1) are supported). |
| 156 | encoding (UTF-8 and iso-8859-1 (aka latin1) are supported). The |
| 157 | default is UTF-8. |
| 157 | 158 | .TP |
| 158 | 159 | .B \-\-subtitles-language language |
| 159 | 160 | Sets the language of the corresponding subtitles stream. This will |
| 160 | 161 | be set in the corresponding Kate stream so a video player may make |
| 161 | | this available to the user for language selection. |
| 162 | this available to the user for language selection. Language is an |
| 163 | ISO 639-1 or RFC 3066 ASCII string and is limited to 15 characters. |
| 162 | 164 | .TP |
| 163 | 165 | .B \-\-subtitles-category category |
| 164 | 166 | Sets the category of the corresponding subtitles stream. This will |
| 165 | 167 | be set in the corresponding Kate stream so a video player may make |
| 166 | 168 | this available to the user for selection. The default category is |
| 167 | 169 | "subtitles". Suggested other categories may include "transcript", |
| 168 | | "commentary", "lyrics", etc. |
| 170 | "commentary", "lyrics", etc. Category is an ASCII string and is |
| 171 | limited to 15 characters |
| 169 | 172 | .TP |
| 170 | 173 | .B \-\-subtitles-ignore-non-utf8 |
| 171 | | When reading an utf-8 subtitles text file, any invalid utf-8 sequence |
| 174 | When reading an UTF-8 subtitles text file, any invalid UTF-8 sequence |
| 172 | 175 | will be ignored. This may be useful if there are stray sequences in |
| 173 | | an otherwise utf-8 file. |
| 176 | an otherwise UTF-8 file. Note that, since those invalid sequences |
| 177 | will be removed from the output, this option is not a substitute to |
| 178 | converting a non UTF-8 file to UTF-8. |
| 174 | 179 | .SS Metadata options: |
| 175 | 180 | .TP |
| 176 | 181 | .B \-\-artist |
| ... | ...@@ -73,6 +73,7 @@ |
| 73 | 73 | |
| 74 | 74 | info->with_kate = 0; |
| 75 | 75 | info->n_kate_streams = 0; |
| 76 | info->kate_streams = NULL; |
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | void oggmux_setup_kate_streams(oggmux_info *info, int n_kate_streams) |
| ... | ...@@ -80,6 +81,7 @@ |
| 80 | 81 | int n; |
| 81 | 82 | |
| 82 | 83 | info->n_kate_streams = n_kate_streams; |
| 84 | info->kate_streams = NULL; |
| 83 | 85 | if (n_kate_streams == 0) return; |
| 84 | 86 | info->kate_streams = (oggmux_kate_stream*)malloc(n_kate_streams*sizeof(oggmux_kate_stream)); |
| 85 | 87 | for (n=0; n<n_kate_streams; ++n) { |
| ... | ...@@ -295,9 +297,15 @@ |
| 295 | 297 | oggmux_kate_stream *ks=info->kate_streams+n; |
| 296 | 298 | ogg_stream_init (&ks->ko, rand ()); /* oops, add one ot the above */ |
| 297 | 299 | ret = kate_encode_init (&ks->k, &ks->ki); |
| 298 | | if (ret<0) fprintf(stderr, "kate_encode_init: %d\n",ret); |
| 300 | if (ret<0) { |
| 301 | fprintf(stderr, "kate_encode_init: %d\n",ret); |
| 302 | exit(1); |
| 303 | } |
| 299 | 304 | ret = kate_comment_init(&ks->kc); |
| 300 | | if (ret<0) fprintf(stderr, "kate_comment_init: %d\n",ret); |
| 305 | if (ret<0) { |
| 306 | fprintf(stderr, "kate_comment_init: %d\n",ret); |
| 307 | exit(1); |
| 308 | } |
| 301 | 309 | kate_comment_add_tag (&ks->kc, "ENCODER",PACKAGE_STRING); |
| 302 | 310 | } |
| 303 | 311 | #endif |
| ... | ...@@ -12,7 +12,7 @@ |
| 12 | 12 | |
| 13 | 13 | Subtitles are read from SubRip (.srt) format files and converted to |
| 14 | 14 | Kate streams. Those SubRip files must be encoded in utf-8 (7 bit ASCII |
| 15 | | is a subset of utf-8 so are valid input as well). See below for more |
| 15 | is a subset of utf-8 so is valid input as well). See below for more |
| 16 | 16 | information on converting SubRip files with other encodings to utf-8. |
| 17 | 17 | |
| 18 | 18 | Subtitles support requires libkate, available from: |
| ... | ...@@ -41,7 +41,8 @@ |
| 41 | 41 | a language tag according to RFC 3066 (usually a two letter language |
| 42 | 42 | code, optionally followed by a dash (or underscore) and a region code. |
| 43 | 43 | Examples include en, it, ja, en_GB, de_DE, etc. |
| 44 | | If unspecified, the default is to not set a language. |
| 44 | If unspecified, the default is to not set a language. It is however |
| 45 | strongly encouraged to set the language. |
| 45 | 46 | |
| 46 | 47 | --subtitles-category <category> |
| 47 | 48 | Sets the category of the relevant subtitles stream. Category must be |
| ... | ...@@ -289,7 +289,7 @@ |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | void ff2theora_output(ff2theora this) { |
| 292 | | int i; |
| 292 | unsigned int i; |
| 293 | 293 | AVCodecContext *aenc = NULL; |
| 294 | 294 | AVCodecContext *venc = NULL; |
| 295 | 295 | AVStream *astream = NULL; |
| ... | ...@@ -1339,7 +1339,7 @@ |
| 1339 | 1339 | break; |
| 1340 | 1340 | case PP_FLAG: |
| 1341 | 1341 | if(!strcmp(optarg, "help")) { |
| 1342 | | fprintf(stdout, pp_help); |
| 1342 | fprintf(stdout, "%s", pp_help); |
| 1343 | 1343 | exit(1); |
| 1344 | 1344 | } |
| 1345 | 1345 | snprintf(convert->pp_mode,sizeof(convert->pp_mode),"%s",optarg); |
| ... | ...@@ -1496,7 +1496,8 @@ |
| 1496 | 1496 | info.with_skeleton=1; |
| 1497 | 1497 | break; |
| 1498 | 1498 | case 'P': |
| 1499 | | sprintf(pidfile_name,optarg); |
| 1499 | snprintf(pidfile_name, sizeof(pidfile_name), "%s", optarg); |
| 1500 | pidfile_name[sizeof(pidfile_name)-1] = '\0'; |
| 1500 | 1501 | break; |
| 1501 | 1502 | case 'f': |
| 1502 | 1503 | input_fmt=av_find_input_format(optarg); |
To list