Exemple #1
0
        public void RunNewKienzan(Decimal targetFramerate)
        {
            //Calculate target duration
            Decimal targetDuration = 1000.0m / targetFramerate;

            //Define maximum frame range
            Int32 maxFrameRound = 5;

            //Check for sections
            if (_VideoFrameList.CountSections < 1)
            {
                //If no section, create a dummy section for the whole video
                VideoFrameSection vfs = new VideoFrameSection();
                vfs.FrameStart  = 0;
                vfs.FrameEnd    = _VideoFrameList.Count - 1;
                vfs.SectionName = "Whole_Video";
                _VideoFrameList.AddSection(vfs);
            }

            Int32   sectionCounter     = 0;
            Decimal frameGlitch        = 0.0m;
            Decimal frameSectionGlitch = 0.0m;

            //Loop for every section
            foreach (VideoFrameSection vfs in _VideoFrameList.FrameSections)
            {
                //Reset data
                vfs.ClearToDelete();
                vfs.ClearToDuplicate();

                //Declare needed variables
                Int32   currentSectionFrame = 0;
                Decimal timeToremove        = _VideoFrameList.FrameList[vfs.FrameStart].FrameStartTime;
                Int32   gatherStartFrame    = vfs.FrameStart;
                Int32   gatherEndFrame      = vfs.FrameEnd;

                Decimal currentCheckTime    = 0.0m;
                Decimal currentShouldBeTime = 0.0m;

                //Check Section Name
                if (vfs.SectionName == "")
                {
                    //If no name, set a default
                    vfs.SectionName = "Section" + (sectionCounter + 1).ToString();
                }

                //Loop for all the frames in the section
                for (int i = vfs.FrameStart; i <= vfs.FrameEnd; i++)
                {
                    //Increase the current frame counter
                    currentSectionFrame++;

                    //Check the current time with the should be time
                    currentCheckTime = (_VideoFrameList.FrameList[i].FrameEndTime - timeToremove);
                    //currentCheckTime += vfs.TotalCutTime();
                    //currentCheckTime -= vfs.TotalAddTime();

                    currentShouldBeTime = (currentSectionFrame - vfs.CountToDelete + vfs.CountToDuplicate) * targetDuration;

                    frameGlitch  = (currentCheckTime - currentShouldBeTime) / targetDuration;
                    frameGlitch += frameSectionGlitch;

                    //Check if nothing happens
                    if (frameGlitch > -1.0m && frameGlitch < 1.0m)
                    {
                        continue;
                    }
                    else
                    {
                        //Check if frames need to be deleted
                        if (frameGlitch <= -1.0m)
                        {
                            gatherEndFrame = i;
                            //Check frame range
                            if (gatherEndFrame - gatherStartFrame > maxFrameRound)
                            {
                                gatherStartFrame = gatherEndFrame - maxFrameRound;
                            }
                            Int32 roundCutFrames = -Convert.ToInt32(Math.Ceiling(frameGlitch));
                            //Cut the frames
                            //Update frame section glitch
                            frameSectionGlitch = frameGlitch + CutFramesNew(vfs, gatherStartFrame, gatherEndFrame, roundCutFrames);
                        }
                        //Check if frames need to be added
                        else if (frameGlitch >= 1.0m)
                        {
                            gatherEndFrame = i;
                            //Check frame range
                            if (gatherEndFrame - gatherStartFrame > maxFrameRound)
                            {
                                gatherStartFrame = gatherEndFrame - maxFrameRound;
                            }
                            Int32 roundAddFrames = Convert.ToInt32(Math.Floor(frameGlitch));
                            //Add the frames
                            //Update frame section glitch
                            frameSectionGlitch = frameGlitch - AddFramesNew(vfs, gatherStartFrame, gatherEndFrame, roundAddFrames);
                        }

                        //Set the gather start frame
                        if (i + 1 > vfs.FrameEnd)
                        {
                            gatherStartFrame = vfs.FrameEnd;
                        }
                        else
                        {
                            gatherStartFrame = i + 1;
                        }
                    }
                }//End of the frame loop

                //Increase the section counter
                sectionCounter++;

                //Set the frame Section Glitch
                frameSectionGlitch = frameGlitch;
            }//End of the section loop

            //Create the final avs file
            String finalAvsFile = AcHelper.GetFilename(_TimecodesFile, GetFileNameMode.FilenameWithoutExtension, GetDirectoryNameMode.FullPath);

            finalAvsFile = AcHelper.GetLastUnusedFilename(finalAvsFile, "kienzan.avs", 3);

            //Define the filenames
            String ffindexFile = String.Format("{0}.ffindex", AcHelper.GetFilename(finalAvsFile, GetFileNameMode.FilenameWithoutExtension, GetDirectoryNameMode.FullPath));
            String tcFile      = String.Format("{0}.tc.txt", AcHelper.GetFilename(finalAvsFile, GetFileNameMode.FilenameWithoutExtension, GetDirectoryNameMode.FullPath));

            StringBuilder sb = new StringBuilder();

            //Write the header
            sb.AppendLine("#Script generated by New Kienzan Kai (Courtesy of AC Tools)");
            sb.AppendLine();
            sb.AppendLine();

            //Write the video provider
            sb.AppendFormat("original = FFVideoSource(source = \"{0}\", track = -1, cache = true, ", _OriginalVideoFile);
            sb.AppendFormat("cachefile = \"{0}\", fpsnum = -1, fpsden = 1, threads = -1, ", ffindexFile);
            sb.AppendFormat("timecodes = \"{0}\", seekmode = 1)", tcFile);
            sb.AppendLine();

            //Assume framerate
            sb.AppendFormat("original = AssumeFPS(original, {0}, false)", AcHelper.DecimalToString(targetFramerate, "##0.000###"));
            sb.AppendLine();
            sb.AppendLine();

            //Write the delete and duplicate frame
            //for each section
            foreach (VideoFrameSection vfs in _VideoFrameList.FrameSections)
            {
                sb.AppendLine(vfs.KienzanString());
            }
            sb.AppendLine();

            //Write the last line to concat the sections
            sb.AppendFormat("last = ");
            for (int i = 0; i < _VideoFrameList.FrameSections.Count; i++)
            {
                if (i == 0)
                {
                    sb.AppendFormat("{0}", _VideoFrameList.FrameSections[i].SectionName);
                }
                else
                {
                    sb.AppendFormat(" + {0}", _VideoFrameList.FrameSections[i].SectionName);
                }
            }
            sb.AppendLine();

            //Write the return statement
            sb.AppendFormat("return last");

            //Create the avs file
            using (StreamWriter sw = new StreamWriter(finalAvsFile, false, AcHelper.FindEncoding("1253")))
            {
                //Write the final String
                sw.Write(sb.ToString());
            }
        }
Exemple #2
0
        private void ParseProject(String prFile)
        {
            //Open the project file
            StreamReader sr = new StreamReader(prFile, Encoding.UTF8);

            //Start parsing the file
            while (!sr.EndOfStream)
            {
                String line = sr.ReadLine();
                //Check for comments
                if (line.StartsWith("#"))
                {
                    //Ignore line
                    continue;
                }
                //Check for section names
                else if (line.StartsWith("["))
                {
                    //Ignore line
                    continue;
                }
                //Check if it is a proper property
                else if (line.Contains("="))
                {
                    String[] elements = line.Split(new String[] { "=" }, StringSplitOptions.None);
                    if (elements[0].Trim().ToLower() == "usefaketimecodes")
                    {
                        useFakeTimecodes = Int32.Parse(elements[1].Trim()) == 1 ? true : false;
                    }
                    else if (elements[0].Trim().ToLower() == "videofile")
                    {
                        videoFile = elements[1].Trim().Replace("\"", "");
                    }
                    else if (elements[0].Trim().ToLower() == "avisynthoutput")
                    {
                        aviSynthOutputFile = elements[1].Trim().Replace("\"", "");
                    }
                    else if (elements[0].Trim().ToLower() == "timecodesfile")
                    {
                        timecodesFile = elements[1].Trim().Replace("\"", "");
                        //Check for fake timecodes
                        if (!useFakeTimecodes)
                        {
                            //Read the timecodes into the list
                            vfl.LoadTimecodes(timecodesFile, false, 3);
                            //Check if the timecodes were valid
                            if (vfl.Count == 0)
                            {
                                throw new AcException("Error parsing project file! Timecodes file didn't contain any frames!");
                            }
                            //Create a new section
                            VideoFrameSection vfs = new VideoFrameSection("Whole_Video", 0, vfl.Count - 1);
                            vfl.AddSection(vfs);
                        }
                    }
                }
                //Check if it contains a proper frame directive
                else if (line.Contains(":"))
                {
                    String[] elements = line.Split(new String[] { ":" }, StringSplitOptions.None);
                    if (elements[0].Trim().ToLower() == "del")
                    {
                        vfl.FrameSections[0].AddToDelete(vfl.FrameList[Convert.ToInt32(elements[1].Trim().ToLower())]);
                    }
                    else if (elements[0].Trim().ToLower() == "dup")
                    {
                        vfl.FrameSections[0].AddToDuplicate(vfl.FrameList[Convert.ToInt32(elements[1].Trim().ToLower())]);
                    }
                }
            }
            sr.Close();
        }