Commit 1220f889 authored by Jan Gerber's avatar Jan Gerber
Browse files

various other cleanup/improvements. by ogg.k.ogg.k to subtitle part, update changelog

parent e9184216
0.22 ???
- enable v4l input again (-f video4linux or -f video4linux2)
- ability to set framerate for image sequences (--inputfps)
- fix several memory leaks
- fix several memory leaks
- if only width or height are given, the other is set to preserve aspect ratio
0.21 2008-05-19
- switch default extension to .ogv
......
.\" Hey, EMACS: -*- nroff -*-
.TH FFMPEG2THEORA 1 "December 30, 2005"
.TH FFMPEG2THEORA 1 "August 31, 2008"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
......@@ -148,29 +148,34 @@ issues with A/V sync.
.TP
.B \-\-subtitles
Encode subtitles from the given file to a multiplexed Kate stream.
The input file should be in SubRip (.srt) format, encoded in utf-8,
The input file should be in SubRip (.srt) format, encoded in UTF-8,
unless the --subtitles-encoding option is also given.
.TP
.B \-\-subtitles-encoding encoding
Assumes the corresponding subtitles file is encoded in the given
encoding (utf-8 and iso-8859-1 (aka latin1) are supported).
encoding (UTF-8 and iso-8859-1 (aka latin1) are supported). The
default is UTF-8.
.TP
.B \-\-subtitles-language language
Sets the language of the corresponding subtitles stream. This will
be set in the corresponding Kate stream so a video player may make
this available to the user for language selection.
this available to the user for language selection. Language is an
ISO 639-1 or RFC 3066 ASCII string and is limited to 15 characters.
.TP
.B \-\-subtitles-category category
Sets the category of the corresponding subtitles stream. This will
be set in the corresponding Kate stream so a video player may make
this available to the user for selection. The default category is
"subtitles". Suggested other categories may include "transcript",
"commentary", "lyrics", etc.
"commentary", "lyrics", etc. Category is an ASCII string and is
limited to 15 characters
.TP
.B \-\-subtitles-ignore-non-utf8
When reading an utf-8 subtitles text file, any invalid utf-8 sequence
When reading an UTF-8 subtitles text file, any invalid UTF-8 sequence
will be ignored. This may be useful if there are stray sequences in
an otherwise utf-8 file.
an otherwise UTF-8 file. Note that, since those invalid sequences
will be removed from the output, this option is not a substitute to
converting a non UTF-8 file to UTF-8.
.SS Metadata options:
.TP
.B \-\-artist
......
......@@ -289,7 +289,7 @@ static void prepare_yuv_buffer(ff2theora this, yuv_buffer *yuv, AVFrame *frame)
}
void ff2theora_output(ff2theora this) {
int i;
unsigned int i;
AVCodecContext *aenc = NULL;
AVCodecContext *venc = NULL;
AVStream *astream = NULL;
......@@ -1339,7 +1339,7 @@ int main (int argc, char **argv){
break;
case PP_FLAG:
if(!strcmp(optarg, "help")) {
fprintf(stdout, pp_help);
fprintf(stdout, "%s", pp_help);
exit(1);
}
snprintf(convert->pp_mode,sizeof(convert->pp_mode),"%s",optarg);
......@@ -1496,7 +1496,8 @@ int main (int argc, char **argv){
info.with_skeleton=1;
break;
case 'P':
sprintf(pidfile_name,optarg);
snprintf(pidfile_name, sizeof(pidfile_name), "%s", optarg);
pidfile_name[sizeof(pidfile_name)-1] = '\0';
break;
case 'f':
input_fmt=av_find_input_format(optarg);
......
......@@ -131,7 +131,7 @@ static double hmsms2s(int h,int m,int s,int ms)
}
/* very simple implementation when no iconv */
static void convert_subtitle_to_utf8(F2T_ENCODING encoding,unsigned char *text,int ignore_non_utf8)
static void convert_subtitle_to_utf8(F2T_ENCODING encoding,char *text,int ignore_non_utf8)
{
size_t nbytes;
char *ptr,*newtext;
......@@ -151,7 +151,7 @@ static void convert_subtitle_to_utf8(F2T_ENCODING encoding,unsigned char *text,i
size_t wlen0;
nbytes = strlen(text)+1;
newtext=(unsigned char*)malloc(nbytes);
newtext=(char*)malloc(nbytes);
if (!newtext) {
fprintf(stderr, "WARNING - Memory allocation failed - cannot convert text\n");
return;
......@@ -193,18 +193,18 @@ static void convert_subtitle_to_utf8(F2T_ENCODING encoding,unsigned char *text,i
nbytes=0;
for (ptr=text;*ptr;++ptr) {
nbytes++;
if (0x80&*ptr) nbytes++;
if (0x80&*(unsigned char*)ptr) nbytes++;
}
newtext=(unsigned char*)malloc(1+nbytes);
newtext=(char*)malloc(1+nbytes);
if (!newtext) {
fprintf(stderr, "WARNING - Memory allocation failed - cannot convert text\n");
return;
}
nbytes=0;
for (ptr=text;*ptr;++ptr) {
if (0x80&*ptr) {
newtext[nbytes++]=0xc0|((*ptr)>>6);
newtext[nbytes++]=0x80|((*ptr)&0x3f);
if (0x80&*(unsigned char*)ptr) {
newtext[nbytes++]=0xc0|((*(unsigned char*)ptr)>>6);
newtext[nbytes++]=0x80|((*(unsigned char*)ptr)&0x3f);
}
else {
newtext[nbytes++]=*ptr;
......@@ -222,8 +222,10 @@ static void convert_subtitle_to_utf8(F2T_ENCODING encoding,unsigned char *text,i
static void remove_last_newline(char *text)
{
char *ptr = text+strlen(text)-1;
if (*ptr=='\n') *ptr=0;
if (*text) {
char *ptr = text+strlen(text)-1;
if (*ptr=='\n') *ptr=0;
}
}
#endif
......@@ -242,9 +244,12 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
double t1=0.0;
static char str[4096];
int warned=0;
FILE *f;
size_t len;
unsigned int line=0;
this->subtitles = NULL;
FILE *f = fopen(this->filename, "r");
f = fopen(this->filename, "r");
if (!f) {
fprintf(stderr,"WARNING - Failed to open subtitles file %s (%s)\n", this->filename, strerror(errno));
return -1;
......@@ -258,27 +263,33 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
}
fgets2(str,sizeof(str),f);
++line;
while (!feof(f)) {
switch (need) {
case need_id:
ret=sscanf(str,"%d\n",&id);
if (ret!=1) {
fprintf(stderr,"WARNING - Syntax error: %s\n",str);
fclose(f);
free(this->subtitles);
return -1;
if (!strcmp(str,"\n")) {
/* be nice and ignore extra empty lines between records */
}
if (id!=last_seen_id+1) {
fprintf(stderr,"WARNING - non consecutive ids: %s - pretending not to have noticed\n",str);
else {
ret=sscanf(str,"%d\n",&id);
if (ret!=1) {
fprintf(stderr,"WARNING - %s:%u: Syntax error: %s\n",this->filename,line,str);
fclose(f);
free(this->subtitles);
return -1;
}
if (id!=last_seen_id+1) {
fprintf(stderr,"WARNING - %s:%u: non consecutive ids: %s - pretending not to have noticed\n",this->filename,line,str);
}
last_seen_id=id;
need=need_timing;
strcpy(text,"");
}
last_seen_id=id;
need=need_timing;
strcpy(text,"");
break;
case need_timing:
ret=sscanf(str,"%d:%d:%d%*[.,]%d --> %d:%d:%d%*[.,]%d\n",&h0,&m0,&s0,&ms0,&h1,&m1,&s1,&ms1);
if (ret!=8) {
fprintf(stderr,"WARNING - Syntax error: %s\n",str);
fprintf(stderr,"WARNING - %s:%u: Syntax error: %s\n",this->filename,line,str);
fclose(f);
free(this->subtitles);
return -1;
......@@ -295,8 +306,8 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
remove_last_newline(text);
/* we want all text to be UTF8 */
convert_subtitle_to_utf8(this->subtitles_encoding,(unsigned char*)text,ignore_non_utf8);
size_t len = strlen(text);
convert_subtitle_to_utf8(this->subtitles_encoding,text,ignore_non_utf8);
len = strlen(text);
this->subtitles = (ff2theora_subtitle*)realloc(this->subtitles, (this->num_subtitles+1)*sizeof(ff2theora_subtitle));
if (!this->subtitles) {
fprintf(stderr, "Out of memory\n");
......@@ -307,7 +318,7 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
ret=kate_text_validate(kate_utf8,text,len+1);
if (ret<0) {
if (!warned) {
fprintf(stderr,"WARNING: subtitle %s is not valid utf-8\n",text);
fprintf(stderr,"WARNING - %s:%u: subtitle %s is not valid utf-8\n",this->filename,line,text);
fprintf(stderr," further invalid subtitles will NOT be flagged\n");
warned=1;
}
......@@ -327,15 +338,27 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
need=need_id;
}
else {
strcat(text,str);
/* in case of very long subtitles */
len=strlen(text);
if (len+strlen(str) >= sizeof(text)) {
fprintf(stderr,"WARNING - %s:%u: subtitle text is too long - truncated\n",this->filename,line);
}
strncpy(text+len,str,sizeof(text)-len);
text[sizeof(text)-1]=0;
}
break;
}
fgets2(str,sizeof(str),f);
++line;
}
fclose(f);
if (need!=need_id) {
/* shouldn't be a problem though, but warn */
fprintf(stderr,"WARNING - %s:%u: missing data in %s - truncated file ?\n",this->filename,line,this->filename);
}
/* fprintf(stderr," %u subtitles loaded.\n", this->num_subtitles); */
return this->num_subtitles;
......
......@@ -73,6 +73,7 @@ void init_info(oggmux_info *info) {
info->with_kate = 0;
info->n_kate_streams = 0;
info->kate_streams = NULL;
}
void oggmux_setup_kate_streams(oggmux_info *info, int n_kate_streams)
......@@ -80,6 +81,7 @@ void oggmux_setup_kate_streams(oggmux_info *info, int n_kate_streams)
int n;
info->n_kate_streams = n_kate_streams;
info->kate_streams = NULL;
if (n_kate_streams == 0) return;
info->kate_streams = (oggmux_kate_stream*)malloc(n_kate_streams*sizeof(oggmux_kate_stream));
for (n=0; n<n_kate_streams; ++n) {
......@@ -295,9 +297,15 @@ void oggmux_init (oggmux_info *info){
oggmux_kate_stream *ks=info->kate_streams+n;
ogg_stream_init (&ks->ko, rand ()); /* oops, add one ot the above */
ret = kate_encode_init (&ks->k, &ks->ki);
if (ret<0) fprintf(stderr, "kate_encode_init: %d\n",ret);
if (ret<0) {
fprintf(stderr, "kate_encode_init: %d\n",ret);
exit(1);
}
ret = kate_comment_init(&ks->kc);
if (ret<0) fprintf(stderr, "kate_comment_init: %d\n",ret);
if (ret<0) {
fprintf(stderr, "kate_comment_init: %d\n",ret);
exit(1);
}
kate_comment_add_tag (&ks->kc, "ENCODER",PACKAGE_STRING);
}
#endif
......
......@@ -12,7 +12,7 @@ Text subtitles can be embedded in an Ogg stream alongside a Theora video.
Subtitles are read from SubRip (.srt) format files and converted to
Kate streams. Those SubRip files must be encoded in utf-8 (7 bit ASCII
is a subset of utf-8 so are valid input as well). See below for more
is a subset of utf-8 so is valid input as well). See below for more
information on converting SubRip files with other encodings to utf-8.
Subtitles support requires libkate, available from:
......@@ -41,7 +41,8 @@ different languages and/or categories. See below for examples of this.
a language tag according to RFC 3066 (usually a two letter language
code, optionally followed by a dash (or underscore) and a region code.
Examples include en, it, ja, en_GB, de_DE, etc.
If unspecified, the default is to not set a language.
If unspecified, the default is to not set a language. It is however
strongly encouraged to set the language.
--subtitles-category <category>
Sets the category of the relevant subtitles stream. Category must be
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment