⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsubreadermplayer.cpp

📁 从FFMPEG转换而来的H264解码程序,VC下编译..
💻 CPP
📖 第 1 页 / 共 4 页
字号:
     inV4styles=0;
     inEvents=2;
     inInfo=0;
    }
   else if (inV4styles==2 && strnicmp(line,_L("Format:"),7)==0)
    {
     strlwr(line);strrmchar(line,_L(' '));
     typedef std::vector<Tstrpart<tchar> > Tparts;
     Tparts fields;
     const tchar *l=line+7;
     strtok(l,_L(","),fields);
     styleFormat.clear();
     for (typename Tparts::const_iterator f=fields.begin();f!=fields.end();f++)
      {
       if (strnicmp(f->first,_L("name"),4)==0)
        styleFormat.push_back(&Tstyle::name);
       else if (strnicmp(f->first,_L("fontname"),8)==0)
        styleFormat.push_back(&Tstyle::fontname);
       else if (strnicmp(f->first,_L("fontsize"),8)==0)
        styleFormat.push_back(&Tstyle::fontsize);
       else if (strnicmp(f->first,_L("primaryColour"),13)==0)
        styleFormat.push_back(&Tstyle::primaryColour);
       else if (strnicmp(f->first,_L("bold"),4)==0)
        styleFormat.push_back(&Tstyle::bold);
       else if (strnicmp(f->first,_L("italic"),6)==0)
        styleFormat.push_back(&Tstyle::italic);
       else if (strnicmp(f->first,_L("alignment"),9)==0)
        styleFormat.push_back(&Tstyle::alignment);
       else if (strnicmp(f->first,_L("encoding"),8)==0)
        styleFormat.push_back(&Tstyle::encoding);
       else if (strnicmp(f->first,_L("marginl"),7)==0)
        styleFormat.push_back(&Tstyle::marginLeft);
       else if (strnicmp(f->first,_L("marginr"),7)==0)
        styleFormat.push_back(&Tstyle::marginRight);
       else if (strnicmp(f->first,_L("marginv"),7)==0)
        styleFormat.push_back(&Tstyle::marginV);
       else if (strnicmp(f->first,_L("borderstyle"),11)==0)
        styleFormat.push_back(&Tstyle::borderStyle);
       else if (strnicmp(f->first,_L("outline"),7)==0)
        styleFormat.push_back(&Tstyle::outlineWidth);
       else if (strnicmp(f->first,_L("shadow"),6)==0)
        styleFormat.push_back(&Tstyle::shadowDepth);
       else
        styleFormat.push_back(NULL);
      }
     inV4styles=1;
    }
   else if (inV4styles && strnicmp(line,_L("Style:"),6)==0)
    {
     if (inV4styles==2)
      {
       styleFormat.clear();
       if (version==ASS2)
        {
         styleFormat.push_back(&Tstyle::name);
         styleFormat.push_back(&Tstyle::fontname);
         styleFormat.push_back(&Tstyle::fontsize);
         styleFormat.push_back(&Tstyle::primaryColour);
         styleFormat.push_back(&Tstyle::secondaryColour);
         styleFormat.push_back(&Tstyle::tertiaryColour);
         styleFormat.push_back(&Tstyle::backgroundColour);
         styleFormat.push_back(&Tstyle::bold);
         styleFormat.push_back(&Tstyle::italic);
         if (version>=ASS) styleFormat.push_back(&Tstyle::underline);
         if (version>=ASS) styleFormat.push_back(&Tstyle::strikeout);
         if (version>=ASS) styleFormat.push_back(&Tstyle::fontScaleX);
         if (version>=ASS) styleFormat.push_back(&Tstyle::fontScaleY);
         if (version>=ASS) styleFormat.push_back(&Tstyle::spacing);
         if (version>=ASS) styleFormat.push_back(&Tstyle::angleZ);
         styleFormat.push_back(&Tstyle::borderStyle);
         styleFormat.push_back(&Tstyle::outlineWidth);
         styleFormat.push_back(&Tstyle::shadowDepth);
         styleFormat.push_back(&Tstyle::alignment);
         styleFormat.push_back(&Tstyle::marginLeft);
         styleFormat.push_back(&Tstyle::marginRight);
         styleFormat.push_back(&Tstyle::marginTop);
         if (version>=ASS2) styleFormat.push_back(&Tstyle::marginBottom);
         styleFormat.push_back(&Tstyle::encoding);
         if (version<=SSA) styleFormat.push_back(&Tstyle::alpha);
         styleFormat.push_back(&Tstyle::relativeTo);
        }
       inV4styles=1;
      }
     strings fields;
     strtok(line+7,_L(","),fields);
     Tstyle style(playResX,playResY,version);
     for (size_t i=0;i<fields.size() && i<styleFormat.size();i++)
       if (styleFormat[i])
        style.*(styleFormat[i])=fields[i];
     styles.add(style);
    }
   else if (inEvents==2 && strnicmp(line,_L("Format:"),7)==0)
    {
     strlwr(line);strrmchar(line,_L(' '));
     typedef std::vector<Tstrpart<tchar> > Tparts;
     Tparts fields;
     const tchar *l=line+7;
     strtok(l,_L(","),fields);
     eventFormat.clear();
     for (typename Tparts::const_iterator f=fields.begin();f!=fields.end();f++)
      {
       if (strnicmp(f->first,_L("marked"),6)==0)
        eventFormat.push_back(&Tevent::marked);
       else if (strnicmp(f->first,_L("start"),5)==0)
        {
         if (!isEmbedded) eventFormat.push_back(&Tevent::start);
        }
       else if (strnicmp(f->first,_L("end"),3)==0)
        eventFormat.push_back(&Tevent::end);
       else if (strnicmp(f->first,_L("style"),5)==0)
        eventFormat.push_back(&Tevent::style);
       else if (strnicmp(f->first,_L("name"),4)==0)
        eventFormat.push_back(&Tevent::name);
       else if (strnicmp(f->first,_L("marginL"),7)==0)
        eventFormat.push_back(&Tevent::marginL);
       else if (strnicmp(f->first,_L("marginR"),7)==0)
        eventFormat.push_back(&Tevent::marginR);
       else if (strnicmp(f->first,_L("marginV"),7)==0)
        eventFormat.push_back(&Tevent::marginV);
       else if (strnicmp(f->first,_L("marginR"),7)==0)
        eventFormat.push_back(&Tevent::marginR);
       else if (strnicmp(f->first,_L("effect"),6)==0)
        eventFormat.push_back(&Tevent::effect);
       else if (strnicmp(f->first,_L("text"),4)==0)
        eventFormat.push_back(&Tevent::text);
       else
        eventFormat.push_back(NULL);
      }
     inEvents=1;
    }
   else if ((flags&this->SSA_NODIALOGUE) || (inEvents==1 && strnicmp(line,_L("Dialogue:"),8)==0))
    {
     if (eventFormat.empty())
      {
       if (!(flags&this->SSA_NODIALOGUE))
        {
         if (version<=SSA) eventFormat.push_back(&Tevent::marked);
         if (version>=ASS) eventFormat.push_back(&Tevent::layer);
         eventFormat.push_back(&Tevent::start);
         eventFormat.push_back(&Tevent::end);
        }
       else
        {
         eventFormat.push_back(&Tevent::readorder);
         eventFormat.push_back(&Tevent::layer);
        }
       eventFormat.push_back(&Tevent::style);
       eventFormat.push_back(&Tevent::actor);
       eventFormat.push_back(&Tevent::marginL);
       eventFormat.push_back(&Tevent::marginR);
       eventFormat.push_back(&Tevent::marginT);
       if (version>=ASS2) eventFormat.push_back(&Tevent::marginB);
       eventFormat.push_back(&Tevent::effect);
       eventFormat.push_back(&Tevent::text);
      }
     strings fields;
     strtok(line+(flags&this->SSA_NODIALOGUE?0:9),_L(",") ,fields,true,eventFormat.size());
     Tevent event;
     event.dummy=""; // avoid being optimized.
     for (size_t i=0;i<fields.size() && i<eventFormat.size();i++/*,it++*/)
      {
       const tchar *str=fields[i].data();
       if (eventFormat[i])
        event.*(eventFormat[i]/* *it*/)=fields[i];
      }
     if (event.text)
      {
#if 0
       text<char_t> lineD2(event.text.c_str());
       const char_t* lineD3=(const char_t*)lineD2;
       DPRINTF(_l("%s"),lineD3);
#endif
       int hour1=0,min1=0,sec1=0,hunsec1=0;
       int hour2=0,min2=0,sec2=0,hunsec2=0;
       if (!(flags&this->PARSETIME) ||
           (tchar_traits<tchar>::sscanf()(event.start.c_str(),_L("%d:%d:%d.%d"),&hour1, &min1, &sec1, &hunsec1)==4 &&
            tchar_traits<tchar>::sscanf()(event.end.c_str()  ,_L("%d:%d:%d.%d"),&hour2, &min2, &sec2, &hunsec2)==4))
        {
         const TSubtitleProps *props=styles.getProps(event.style);
         TsubtitleTextBase<tchar> current(this->format,props?*props:defprops);
         strToIntMargin(event.marginL,&current.defProps.marginL);
         strToIntMargin(event.marginL,&current.defProps.marginR);
         strToIntMargin(event.marginV,&current.defProps.marginV);
         strToIntMargin(event.marginL,&current.defProps.marginTop);
         strToIntMargin(event.marginL,&current.defProps.marginBottom);
         if (flags&this->PARSETIME)
          {
           current.start=timer.den*this->hmsToTime(hour1,min1,sec1,hunsec1)/timer.num;
           current.stop =timer.den*this->hmsToTime(hour2,min2,sec2,hunsec2)/timer.num;
          }

         // FIXME
         // ffdshow custom code
         // \h removal : \h is hard space, so it should be replaced HARD sapce, soft space for band-aid.
         for (size_t i=0 ; i<event.text.size() ; i++)
         {
          if (event.text[i]=='\\' && event.text[i+1]=='h')
           {
            event.text[i]=0x20; // ' '
            event.text.erase(i+1,1);
           }
         }

         const tchar *line2=event.text.c_str();
         do
         {
          const tchar *tmp;
          while (((tmp=strstr(line2, _L("\\n"))) != NULL) || ((tmp=strstr(line2, _L("\\N"))) != NULL) )
           {
            current.add(line2,tmp-line2);
            line2=tmp+2;
           }
          current.add(line2);
         } while (flags&this->SSA_NODIALOGUE && fd.fgets((tchar*)(line2=line),this->LINE_LEN));
         return store(current);
        }
      }
    }
  }
 return NULL;
}

template<class tchar> Tsubtitle* TsubtitleParserDunnowhat<tchar>::parse(Tstream &fd,int flags) {
    tchar line[this->LINE_LEN+1];
    tchar text[this->LINE_LEN+1];

    if (!fd.fgets (line, this->LINE_LEN))
        return NULL;
    long start,stop;
    if (tchar_traits<tchar>::sscanf() (line, _L("%ld,%ld,\"%[^\"]"), &start,
                &stop, text) <3)
        return NULL;
    TsubtitleTextBase<tchar> current(this->format);
    current.start=this->frameToTime(start);
    current.stop =this->frameToTime(stop );
    current.add(text);

    return store(current);
}

template<class tchar> Tsubtitle* TsubtitleParserMPsub<tchar>::parse(Tstream &fd,int flags) {
        tchar line[this->LINE_LEN+1];
        float a,b;
        int num=0;
        tchar *p, *q;

        do
        {
                if (!fd.fgets(line, this->LINE_LEN)) return NULL;
        } while (tchar_traits<tchar>::sscanf() (line, _L("%f %f"), &a, &b) !=2);
        TsubtitleTextBase<tchar> current(this->format);
        mpsub_position += a*(sub_uses_time ? 100.0 : 1.0);
        current.start=this->frameToTime(int(sub_uses_time?mpsub_position/100.0:mpsub_position));
        mpsub_position += b*(sub_uses_time ? 100.0 : 1.0);
        current.stop =this->frameToTime(int(sub_uses_time?mpsub_position/100.0:mpsub_position));

        while (1) {
                if (!fd.fgets (line, this->LINE_LEN)) {
                        if (num == 0) return NULL;
                        else return store(current);
                }
                p=line;
                while (tchar_traits<tchar>::isspace((typename tchar_traits<tchar>::uchar_t)*p)) p++;
                if (eol(*p) && num > 0) return store(current);
                if (eol(*p)) return NULL;

                for (q=p; !eol(*q); q++);
                *q='\0';
                if (strlen(p)) {
                        current.add(p);
                        ++num;
                } else {
                        if (num) return store(current);
                        else return NULL;
                }
        }
        return NULL; // we should have returned before if it's OK
}

template<class tchar> Tsubtitle* TsubtitleParserAqt<tchar>::parse(Tstream &fd,int flags) {
    tchar line[this->LINE_LEN+1];
    const tchar *next;
    //int i;

    long start;
    while (1) {
    // try to locate next subtitle
        if (!fd.fgets (line, this->LINE_LEN))
                return NULL;
        if (!(tchar_traits<tchar>::sscanf() (line, _L("-->> %ld"), &start) <1))
                break;
    }
    TsubtitleTextBase<tchar> current(this->format);
    current.start=this->frameToTime(start);
    if (previous != NULL)
        previous->stop = current.start-1;

    //previous_aqt_sub = current;

    if (!fd.fgets (line, this->LINE_LEN))
        return NULL;

    sub_readtext(line,current);
    current.stop = current.start; // will be corrected by next subtitle

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -