Ticket #188: vobsub_mencoder.diff

File vobsub_mencoder.diff, 5.6 KB (added by hashao2@…, 22 years ago)

add -vobsub to mencoder

  • cfg-common.h

    RCS file: /cvsroot/mplayer/main/cfg-common.h,v
    retrieving revision 1.137
    diff -u -r1.137 cfg-common.h
     
    251251        {"sub-bg-alpha", &sub_bg_alpha, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
    252252        {"sub-no-text-pp", &sub_no_text_pp, CONF_TYPE_FLAG, 0, 0, 1, NULL},
    253253        {"sub-fuzziness", &sub_match_fuzziness, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
     254        {"vobsub", &vobsub_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
     255        {"vobsubid", &vobsub_id, CONF_TYPE_INT, CONF_RANGE, 0, 31, NULL},
     256
    254257#endif
    255258#ifdef USE_OSD
    256259        {"font", &font_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
  • cfg-mplayer.h

    RCS file: /cvsroot/mplayer/main/cfg-mplayer.h,v
    retrieving revision 1.236
    diff -u -r1.236 cfg-mplayer.h
     
    327327        {"menu", "OSD menu support was not compiled in.\n", CONF_TYPE_PRINT,0, 0, 0, NULL},
    328328#endif
    329329
    330         // these should be moved to -common, and supported in MEncoder
    331         {"vobsub", &vobsub_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
    332         {"vobsubid", &vobsub_id, CONF_TYPE_INT, CONF_RANGE, 0, 31, NULL},
    333 
    334330        {"sstep", &step_sec, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
    335331
    336332        // set a-v distance, should be moved to -common and supported in MEncoder
  • mencoder.c

    RCS file: /cvsroot/mplayer/main/mencoder.c,v
    retrieving revision 1.259
    diff -u -r1.259 mencoder.c
     
    196196float sub_delay=0;
    197197float sub_fps=0;
    198198int   sub_auto = 0;
     199char *vobsub_name=NULL;
    199200int   subcc_enabled=0;
    200201int   suboverlap_enabled = 1;
    201202
    … …  
    489490
    490491  vo_init_osd();
    491492
     493  //==================== Open VOB-Sub ============================
     494  if (vobsub_name){
     495      vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
     496      if(vo_vobsub==NULL)
     497          mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
     498  }else if(sub_auto && filename && (strlen(filename)>=5)){
     499      /* try to autodetect vobsub from movie filename ::atmos */
     500      char *buf = malloc((strlen(filename)-3) * sizeof(char));
     501      memset(buf,0,strlen(filename)-3); // make sure string is terminated
     502      strncpy(buf, filename, strlen(filename)-4);
     503      vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
     504      free(buf);
     505  }
     506
     507  if(vo_vobsub){
     508      sub_auto=0; // don't do autosub for textsubs if vobsub found
     509      // inited_flags|=INITED_VOBSUB;
     510      vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
     511      // check if vobsub requested only to display forced subtitles
     512      forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
     513  }
     514 
    492515  stream=open_stream(filename,0,&file_format);
    493516
    494517  if(!stream){
    … …  
    11311154    else
    11321155        sscanf(seek_to_sec, "%f", &d);
    11331156
    1134     demux_seek(demuxer, d, 1);
     1157    if (demux_seek(demuxer, d, 1)){
     1158        /* FIXME there should be real seeking for vobsub */
     1159        if (vo_vobsub)
     1160            vobsub_seek(vo_vobsub, d_video->pts);
     1161    }
    11351162//  there is 2 way to handle the -ss option in 3-pass mode:
    11361163// > 1. do the first pass for the whole file, and use -ss for 2nd/3rd pases only
    11371164// > 2. do all the 3 passes with the same -ss value
    … …  
    15481575// DVD sub:
    15491576 if(vo_spudec||vobsub_writer){
    15501577     unsigned char* packet=NULL;
    1551      int len;
    1552      while((len=ds_get_packet_sub(d_dvdsub,&packet))>0){
    1553          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);
    1554          if (vo_spudec)
    1555          spudec_assemble(vo_spudec,packet,len,90000*d_dvdsub->pts);
    1556          if (vobsub_writer)
    1557              vobsub_out_output(vobsub_writer,packet,len,mux_v->timer + d_dvdsub->pts - sh_video->pts);
    1558      }
     1578     int len, timestamp;
     1579     // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
     1580     while(1) {
     1581         // FIXME: messed up timer and pts?????????
     1582         // Vobsub
     1583         if(vo_vobsub) {
     1584             if(sh_video->pts+sub_delay>=0) {
     1585                 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay,(void**)&packet,&timestamp);
     1586                 if(len > 0) {
     1587                     timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
     1588                     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);
     1589                 }
     1590             }
     1591         } else {
     1592             // DVD sub
     1593             len=ds_get_packet_sub(d_dvdsub,&packet);
     1594             if(len > 0) {
     1595                 float x = d_dvdsub->pts - sh_video->pts;
     1596                 if (x < -10 || x > 10) // prevent missing subs on pts reset
     1597                     timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
     1598                 else
     1599                     timestamp = 90000*(sh_video->timer + sub_delay);
     1600
     1601                 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);
     1602             }
     1603         }
     1604         if (len <= 0 || !packet) break;
     1605         if (timestamp < 0) timestamp = 0;
     1606         else{
     1607             if (vo_spudec)
     1608                 spudec_assemble(vo_spudec,packet,len,timestamp);
     1609             if (vobsub_writer)
     1610                 vobsub_out_output(vobsub_writer,packet,len,mux_v->timer + d_dvdsub->pts - sh_video->pts);
     1611         }
     1612 }
    15591613     if (vo_spudec) {
    15601614     spudec_heartbeat(vo_spudec,90000*sh_video->pts);
    15611615     vo_osd_changed(OSDTYPE_SPU);
    … …  
    16031657    mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile, out_filename);
    16041658    mencoder_exit(1, NULL);
    16051659}
     1660
     1661if(vo_vobsub)
     1662    vobsub_close(vo_vobsub);
     1663    vo_vobsub = NULL;
     1664   
    16061665if(vobsub_writer)
    16071666    vobsub_out_close(vobsub_writer);
    16081667