Index: cfg-common.h =================================================================== RCS file: /cvsroot/mplayer/main/cfg-common.h,v retrieving revision 1.137 diff -u -r1.137 cfg-common.h --- cfg-common.h 18 Oct 2004 20:41:05 -0000 1.137 +++ cfg-common.h 2 Jan 2005 10:24:51 -0000 @@ -251,6 +251,9 @@ {"sub-bg-alpha", &sub_bg_alpha, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL}, {"sub-no-text-pp", &sub_no_text_pp, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"sub-fuzziness", &sub_match_fuzziness, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, + {"vobsub", &vobsub_name, CONF_TYPE_STRING, 0, 0, 0, NULL}, + {"vobsubid", &vobsub_id, CONF_TYPE_INT, CONF_RANGE, 0, 31, NULL}, + #endif #ifdef USE_OSD {"font", &font_name, CONF_TYPE_STRING, 0, 0, 0, NULL}, Index: cfg-mplayer.h =================================================================== RCS file: /cvsroot/mplayer/main/cfg-mplayer.h,v retrieving revision 1.236 diff -u -r1.236 cfg-mplayer.h --- cfg-mplayer.h 27 Dec 2004 19:34:42 -0000 1.236 +++ cfg-mplayer.h 2 Jan 2005 10:24:51 -0000 @@ -327,10 +327,6 @@ {"menu", "OSD menu support was not compiled in.\n", CONF_TYPE_PRINT,0, 0, 0, NULL}, #endif - // these should be moved to -common, and supported in MEncoder - {"vobsub", &vobsub_name, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"vobsubid", &vobsub_id, CONF_TYPE_INT, CONF_RANGE, 0, 31, NULL}, - {"sstep", &step_sec, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, // set a-v distance, should be moved to -common and supported in MEncoder Index: mencoder.c =================================================================== RCS file: /cvsroot/mplayer/main/mencoder.c,v retrieving revision 1.259 diff -u -r1.259 mencoder.c --- mencoder.c 27 Dec 2004 17:30:12 -0000 1.259 +++ mencoder.c 2 Jan 2005 10:24:53 -0000 @@ -196,6 +196,7 @@ float sub_delay=0; float sub_fps=0; int sub_auto = 0; +char *vobsub_name=NULL; int subcc_enabled=0; int suboverlap_enabled = 1; @@ -489,6 +490,28 @@ vo_init_osd(); + //==================== Open VOB-Sub ============================ + if (vobsub_name){ + vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec); + if(vo_vobsub==NULL) + mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name); + }else if(sub_auto && filename && (strlen(filename)>=5)){ + /* try to autodetect vobsub from movie filename ::atmos */ + char *buf = malloc((strlen(filename)-3) * sizeof(char)); + memset(buf,0,strlen(filename)-3); // make sure string is terminated + strncpy(buf, filename, strlen(filename)-4); + vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec); + free(buf); + } + + if(vo_vobsub){ + sub_auto=0; // don't do autosub for textsubs if vobsub found + // inited_flags|=INITED_VOBSUB; + vobsub_set_from_lang(vo_vobsub, dvdsub_lang); + // check if vobsub requested only to display forced subtitles + forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub); + } + stream=open_stream(filename,0,&file_format); if(!stream){ @@ -1131,7 +1154,11 @@ else sscanf(seek_to_sec, "%f", &d); - demux_seek(demuxer, d, 1); + if (demux_seek(demuxer, d, 1)){ + /* FIXME there should be real seeking for vobsub */ + if (vo_vobsub) + vobsub_seek(vo_vobsub, d_video->pts); + } // there is 2 way to handle the -ss option in 3-pass mode: // > 1. do the first pass for the whole file, and use -ss for 2nd/3rd pases only // > 2. do all the 3 passes with the same -ss value @@ -1548,14 +1575,41 @@ // DVD sub: if(vo_spudec||vobsub_writer){ unsigned char* packet=NULL; - int len; - while((len=ds_get_packet_sub(d_dvdsub,&packet))>0){ - mp_msg(MSGT_MENCODER,MSGL_V,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f \n",len,sh_video->pts,d_dvdsub->pts); - if (vo_spudec) - spudec_assemble(vo_spudec,packet,len,90000*d_dvdsub->pts); - if (vobsub_writer) - vobsub_out_output(vobsub_writer,packet,len,mux_v->timer + d_dvdsub->pts - sh_video->pts); - } + int len, timestamp; + // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer + while(1) { + // FIXME: messed up timer and pts????????? + // Vobsub + if(vo_vobsub) { + if(sh_video->pts+sub_delay>=0) { + len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay,(void**)&packet,×tamp); + if(len > 0) { + timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000; + mp_dbg(MSGT_CPLAYER,MSGL_V,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len,sh_video->pts,sh_video->timer,timestamp / 90000.0,timestamp); + } + } + } else { + // DVD sub + len=ds_get_packet_sub(d_dvdsub,&packet); + if(len > 0) { + float x = d_dvdsub->pts - sh_video->pts; + if (x < -10 || x > 10) // prevent missing subs on pts reset + timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts); + else + timestamp = 90000*(sh_video->timer + sub_delay); + + mp_msg(MSGT_MENCODER,MSGL_V,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f ts=%d \n",len,sh_video->pts,d_dvdsub->pts,timestamp); + } + } + if (len <= 0 || !packet) break; + if (timestamp < 0) timestamp = 0; + else{ + if (vo_spudec) + spudec_assemble(vo_spudec,packet,len,timestamp); + if (vobsub_writer) + vobsub_out_output(vobsub_writer,packet,len,mux_v->timer + d_dvdsub->pts - sh_video->pts); + } + } if (vo_spudec) { spudec_heartbeat(vo_spudec,90000*sh_video->pts); vo_osd_changed(OSDTYPE_SPU); @@ -1603,6 +1657,11 @@ mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile, out_filename); mencoder_exit(1, NULL); } + +if(vo_vobsub) + vobsub_close(vo_vobsub); + vo_vobsub = NULL; + if(vobsub_writer) vobsub_out_close(vobsub_writer);