Commit cff2c4d4 authored by Jan Gerber's avatar Jan Gerber
Browse files

further cleanup of kate support. In particular, empty Kate streams won't be

merged in (happens mostly when there is an error loading an srt file). 
(ogg.k.ogg.k)
parent 3246856f
......@@ -699,6 +699,9 @@ void ff2theora_output(ff2theora this) {
kate_info *ki = &info.kate_streams[i].ki;
kate_info_init(ki);
if (ks->num_subtitles > 0) {
if (!ks->subtitles_language[0]) {
fprintf(stderr, "WARNING - Subtitles language not set for input file %d\n",i);
}
kate_info_set_language(ki, ks->subtitles_language);
kate_info_set_category(ki, ks->subtitles_category[0]?ks->subtitles_category:"subtitles");
if(this->force_input_fps.num > 0) {
......@@ -1694,22 +1697,25 @@ int main (int argc, char **argv){
}
}
oggmux_setup_kate_streams(&info, convert->n_kate_streams);
for (n=0; n<convert->n_kate_streams; ++n) {
ff2theora_kate_stream *ks=convert->kate_streams+n;
if (load_subtitles(ks,convert->ignore_non_utf8)>=0) {
if (load_subtitles(ks,convert->ignore_non_utf8)>0) {
printf("Muxing Kate stream %d from %s as %s %s\n",
n,ks->filename,
ks->subtitles_language[0]?ks->subtitles_language:"<unknown language>",
ks->subtitles_category[0]?ks->subtitles_category:"subtitles");
}
else {
ks->filename = NULL;
ks->num_subtitles = 0;
ks->subtitles = NULL;
if (n!=convert->n_kate_streams) {
memmove(convert->kate_streams+n,convert->kate_streams+n+1,(convert->n_kate_streams-n-1)*sizeof(ff2theora_kate_stream));
--convert->n_kate_streams;
--n;
}
}
}
oggmux_setup_kate_streams(&info, convert->n_kate_streams);
//detect image sequences and set framerate if provided
if(av_guess_image2_codec(inputfile_name) != CODEC_ID_NONE || \
(input_fmt != NULL && strcmp(input_fmt->name, "video4linux") >= 0)) {
......
......@@ -249,6 +249,12 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
unsigned int line=0;
this->subtitles = NULL;
if (!this->filename) {
fprintf(stderr,"WARNING - No subtitles file to load from\n");
return -1;
}
f = fopen(this->filename, "r");
if (!f) {
fprintf(stderr,"WARNING - Failed to open subtitles file %s (%s)\n", this->filename, strerror(errno));
......@@ -272,7 +278,7 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
}
else {
ret=sscanf(str,"%d\n",&id);
if (ret!=1) {
if (ret!=1 || id<0) {
fprintf(stderr,"WARNING - %s:%u: Syntax error: %s\n",this->filename,line,str);
fclose(f);
free(this->subtitles);
......@@ -288,7 +294,7 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
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) {
if (ret!=8 || (h0|m0|s0|ms0)<0 || (h1|m1|s1|ms1)<0) {
fprintf(stderr,"WARNING - %s:%u: Syntax error: %s\n",this->filename,line,str);
fclose(f);
free(this->subtitles);
......@@ -301,7 +307,7 @@ int load_subtitles(ff2theora_kate_stream *this, int ignore_non_utf8)
need=need_text;
break;
case need_text:
if (*str=='\n') {
if (str[0]=='\n') {
/* we have all the lines for that subtitle, remove the last \n */
remove_last_newline(text);
......
Markdown is supported
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