Exemplo n.º 1
0
        public static int GetFrameCount(string filename, double fps)
        {
            double framel;

            ASSFile assfile = ASSFile.LoadFromFile(filename);

            Common.SUBTime at = new Common.SUBTime();

            foreach (var ae in assfile.Events)
            {
                if (ae.End > at)
                {
                    at = ae.End;
                }
            }


            framel = at.GetSecond() * fps;
            return((int)(framel));
        }
Exemplo n.º 2
0
        public static ASSFile LoadFromFile(string filename)
        {
            List <string> ls = Common.ReadFile(filename);

            if (ls == null)
            {
                return(null);
            }

            ASSFile assfile = new ASSFile();

            foreach (string s in ls)
            {
                if (s[0] == ';' || s.ToUpper().IndexOf("COMMENT") >= 0)
                {
                    continue;
                }

                string[] sa = s.Split(new char[] { ':' }, 2);

                if (sa.Length != 2)
                {
                    continue;
                }


                string sl = sa[0];
                string sr = sa[1].TrimStart(' ');

                switch (sl.ToUpper())
                {
                case "TITLE": assfile.Header.Title = sr; break;

                case "ORIGINAL_SCRIPT": assfile.Header.Original_Script = sr; break;

                case "ORIGINAL_TRANSLATION": assfile.Header.Original_Translation = sr; break;

                case "ORIGINAL_EDITING": assfile.Header.Original_Editing = sr; break;

                case "Original_Timing": assfile.Header.Original_Timing = sr; break;

                case "SCRIPT_UPDATED_BY": assfile.Header.Script_Updated_By = sr; break;

                case "UPDATE_DETAILS": assfile.Header.Update_Details = sr; break;

                case "SCRIPTTYPE": assfile.Header.ScriptType = sr; break;

                case "WRAPSTYLE": assfile.Header.WrapStyle = sr; break;

                case "SCALEDBORDERANDSHADOW": assfile.Header.ScaledBorderAndShadow = sr; break;

                case "SYNCH_POINT": assfile.Header.Synch_Point = sr; break;

                case "COLLISIONS": assfile.Header.Collisions = sr; break;

                case "PLAYDEPTH": assfile.Header.PlayDepth = sr; break;

                case "PLAYRESX": assfile.Header.PlayResX = sr; break;

                case "PLAYRESY": assfile.Header.PlayResY = sr; break;

                case "TIMER": assfile.Header.Timer = sr; break;

                case "STYLE":

                    string[] sas = sr.Split(new char[] { ',' }, 23);

                    if (sas.Length != 23)
                    {
                        break;
                    }

                    assfile.Styles.Add(new ASSFile.ASS_Style(sas[0], sas[1], sas[2], sas[3], sas[4], sas[5], sas[6], sas[7], sas[8],
                                                             sas[9], sas[10], sas[11], sas[12], sas[13], sas[14], sas[15], sas[16], sas[17], sas[18], sas[19], sas[20], sas[21], sas[22]));
                    break;

                case "DIALOGUE":
                    string[] sae = sr.Split(new char[] { ',' }, 10);

                    if (sae.Length != 10)
                    {
                        break;
                    }

                    assfile.Events.Add(new ASSFile.ASS_Event(sae[0], Common.SUBTime.Parse(sae[1]), Common.SUBTime.Parse(sae[2]), sae[3], sae[4], sae[5], sae[6], sae[7], sae[8], sae[9]));
                    break;
                }
            }

            return(assfile);
        }
Exemplo n.º 3
0
        private void MakeAvs(int index)
        {
            Common.TaskData tdata = Task_Data_List[index];
            List <string>   olst  = new List <string>();

            int    fcount = 0;
            double fps;

            Common.Resolution res;
            string            filemainname = Path.GetFileNameWithoutExtension(tdata.FileName);
            string            outputpath   = tdata.CData.OutputPath + "\\" + filemainname + "\\";

            fps = Common.FPSList[tdata.CData.FPSIndex];
            res = Common.ResolutionList[tdata.CData.ResolutionIndex];
            Common.FileType ftype = Common.GetFileType(tdata.FileFullPath);

            if (ftype == Common.FileType.ASS)
            {
                fcount = ASSFile.GetFrameCount(tdata.FileFullPath, fps);
            }
            else if (ftype == Common.FileType.SSA)
            {
                fcount = SSAFile.GetFrameCount(tdata.FileFullPath, fps);
            }

            fcount += 100;

            if (tdata.CData.BVSMod)
            {
                olst.Add("LoadPlugin(\"" + _vsfiltermodpath + "\")");
                olst.Add("MaskSubMod(\"" + tdata.FileFullPath + "\", " + res.X.ToString() + ", " + res.Y.ToString() + ", " + fps.ToString() + ", " + fcount.ToString() + ")");
            }
            else
            {
                olst.Add("LoadPlugin(\"" + _vsfilterpath + "\")");
                olst.Add("MaskSub(\"" + tdata.FileFullPath + "\", " + res.X.ToString() + ", " + res.Y.ToString() + ", " + fps.ToString() + ", " + fcount.ToString() + ")");
            }



            if (tdata.CData.ResolutionIndex == 3)
            {
                olst.Add("LanczosResize(720,480)");
            }
            else if (tdata.CData.ResolutionIndex == 4)
            {
                olst.Add("LanczosResize(720,576)");
            }
            else
            {
                olst.Add("LanczosResize(" + res.X.ToString() + ", " + res.Y.ToString() + ")");
            }

            if (!Directory.Exists(tdata.CData.OutputPath))
            {
                Directory.CreateDirectory(tdata.CData.OutputPath);
            }

            string avsfile = outputpath + filemainname + ".avs";

            if (!Directory.Exists(outputpath))
            {
                Directory.CreateDirectory(outputpath);
            }

            if (File.Exists(avsfile))
            {
                File.Delete(avsfile);
            }

            FileStream   fs = File.Create(avsfile);
            StreamWriter sr = new StreamWriter(fs);

            sr.AutoFlush = true;

            foreach (string s in olst)
            {
                sr.WriteLine(s);
            }

            sr.Close();
            fs.Close();
        }