Esempio n. 1
0
        public void PrepareJobFiles(MediaEncoderSettings settings)
        {
            settings.JobIndex = ++JobIndex;
            // Files must be prepared before adding to queue so that user can replace preview files.
            PathManager.DeleteJobFiles(settings.JobIndex);
            File.Delete(PathManager.PreviewScriptFile);
            File.Delete(PathManager.PreviewSettingsFile);
            if (settings.ConvertToAvi)
            {
                PathManager.SafeMove(PathManager.PreviewSourceFile, settings.InputFile);
            }
            if (settings.Deshaker)
            {
                PathManager.SafeMove(PathManager.PreviewDeshakerLog, settings.DeshakerLog);
            }
            settings.Save(settings.SettingsFile);
            AviSynthScriptBuilder Script = new AviSynthScriptBuilder(settings.CustomScript);

            if (Script.IsEmpty)
            {
                Script = MediaEncoderScript.GenerateVideoScript(settings, settings.InputFile, false, true);
            }
            else
            {
                Script.Replace(Script.GetAsciiPath(PathManager.PreviewSourceFile), Script.GetAsciiPath(settings.InputFile));
                Script.Replace(Script.GetAsciiPath(PathManager.PreviewDeshakerLog), Script.GetAsciiPath(settings.DeshakerLog));
            }
            Script.WriteToFile(settings.ScriptFile);
            // if (settings.DeshakerSettings.PrescanAction == PrescanType.Full)
        }
Esempio n. 2
0
        private CompletionStatus GenerateDeshakerLogSegment(MediaEncoderSettings settings, string inputFile, int segment, long jobStart, long frameStart, long frameEnd, ProcessStartOptions jobOptions)
        {
            // Write Deshaker Pass 1 script to file.
            string Script = MediaEncoderScript.GenerateDeshakerScript(settings, inputFile, segment, frameStart, frameEnd);

            File.WriteAllText(settings.DeshakerScript, Script);

            // Run pass.
            jobOptions.IsMainTask = true;
            jobOptions.Title      = "Running Deshaker Prescan";
            jobOptions.ResumePos  = frameStart - jobStart;
            CompletionStatus Result = FFmpeg.MediaEncoder.ConvertToAvi(settings.DeshakerScript, settings.DeshakerTempOut, false, jobOptions);

            File.Delete(settings.DeshakerScript);
            File.Delete(settings.DeshakerTempOut);
            return(Result);
        }
Esempio n. 3
0
        public void GenerateScript(MediaEncoderSettings settings, bool preview, bool multiThreaded)
        {
            AviSynthScriptBuilder Script = new AviSynthScriptBuilder(settings.CustomScript);

            if (Script.IsEmpty)
            {
                Script = MediaEncoderScript.GenerateVideoScript(settings, GetPreviewSourceFile(settings), preview, multiThreaded);
            }
            else if (preview)
            {
                Script.RemoveMT();
                Script.AppendLine(@"ConvertToRGB32(matrix=""Rec709"")");
            }
            else if (!multiThreaded)
            {
                Script.RemoveMT();
            }
            Script.WriteToFile(PathManager.PreviewScriptFile);
            settings.Save(PathManager.PreviewSettingsFile);
        }
Esempio n. 4
0
        public CompletionStatus GenerateDeshakerLog(MediaEncoderSettings settings, string inputFile)
        {
            // Prepare Deshaker settings.
            settings.DeshakerSettings.Pass    = 1;
            settings.DeshakerSettings.LogFile = settings.DeshakerTempLog;
            settings.DeshakerSettings.SourcePixelAspectRatio = settings.SourceAspectRatio.Value;
            // settings.DeshakerSettings.AppendToFile = true;
            File.Delete(settings.DeshakerLog);

            // Start UI.
            CompletionStatus Result = CompletionStatus.Success;
            object           JobId  = "Deshaker";

            FFmpegConfig.UserInterfaceManager.Start(JobId, "Running Deshaker Prescan");
            ProcessStartOptions JobOptions = new ProcessStartOptions(JobId, "Getting Frame Count", false);

            // Get frame count.
            settings.CalculateSize();
            int    FrameStart = (int)((settings.DeshakerSettings.PrescanStart ?? 0) * settings.SourceFrameRate.Value);
            int    FrameEnd   = (int)((settings.DeshakerSettings.PrescanEnd ?? 0) * settings.SourceFrameRate.Value);
            string Script     = MediaEncoderScript.GenerateDeshakerScript(settings, inputFile, 0, FrameStart, FrameEnd);

            File.WriteAllText(settings.DeshakerScript, Script);
            JobOptions.FrameCount = AvisynthTools.GetFrameCount(settings.DeshakerScript, JobOptions);

            // Pad file start.
            using (StreamWriter sw = new StreamWriter(File.Open(settings.DeshakerLog, FileMode.Create), Encoding.ASCII)) {
                for (int i = 0; i < FrameStart; i++)
                {
                    sw.WriteLine((i + 1).ToString().PadLeft(7) + "									skipped		#	   0.00	   0.00	");
                }
            }

            // Run segments.
            var Segments = settings.DeshakerSettings.Segments;

            if (JobOptions.FrameCount > 0)
            {
                for (int i = 0; i < Segments.Count; i++)
                {
                    // Get start position of next segment.
                    long NextSegmentStart = i < Segments.Count - 1 ? Segments[i + 1].FrameStart : 0;
                    if (NextSegmentStart == 0 || NextSegmentStart > FrameStart)   // Enforce PrescanStart for preview
                    {
                        long SegmentStart = Segments[i].FrameStart;
                        long SegmentEnd   = NextSegmentStart > 0 ? NextSegmentStart - 1 : 0;
                        // Enforce PrescanEnd for preview
                        if ((FrameEnd > 0 && SegmentStart > FrameEnd) || (SegmentEnd > 0 && SegmentStart > SegmentEnd))
                        {
                            break;
                        }
                        if ((FrameStart > 0 && FrameStart > SegmentStart) || SegmentStart == 0)
                        {
                            SegmentStart = FrameStart;
                        }
                        if ((FrameEnd > 0 && FrameEnd < SegmentEnd) || SegmentEnd == 0)
                        {
                            SegmentEnd = FrameEnd;
                        }
                        Result = GenerateDeshakerLogSegment(settings, inputFile, i, FrameStart, SegmentStart, SegmentEnd, JobOptions);
                        if (Result != CompletionStatus.Success)
                        {
                            break;
                        }

                        // Merge log segment into log file and set right frame numbers.
                        using (StreamWriter sw = new StreamWriter(File.Open(settings.DeshakerLog, FileMode.Append), Encoding.ASCII)) {
                            using (StreamReader sr = new StreamReader(File.OpenRead(settings.DeshakerTempLog), Encoding.ASCII)) {
                                string LogLine, LogNum, LogNumField, LineOut;
                                long   NewLineNum = SegmentStart;
                                LogLine = sr.ReadLine();
                                while (LogLine != null)
                                {
                                    if (LogLine.Length > 7)
                                    {
                                        LogNum = LogLine.Substring(0, 7).Trim();
                                        if (LogNum.Length > 0)
                                        {
                                            LogNumField = LogNum[LogNum.Length - 1].ToString();
                                            if (LogNumField != "A" && LogNumField != "B") // For interlaced videos
                                            {
                                                LogNumField = "";
                                            }
                                            NewLineNum++; // Log file starts at 1, not 0.
                                            LineOut = (NewLineNum.ToString() + LogNumField).PadLeft(7) + LogLine.Substring(7, LogLine.Length - 8);
                                            sw.WriteLine(LineOut);
                                        }
                                    }
                                    LogLine = sr.ReadLine();
                                }
                            }
                        }
                        File.Delete(settings.DeshakerTempLog);
                    }
                }
            }
            else
            {
                Result = CompletionStatus.Error;
            }

            // End UI.
            FFmpegConfig.UserInterfaceManager.Stop(JobId);
            return(Result);
        }
Esempio n. 5
0
 public bool CustomScriptHasChanges(MediaEncoderSettings settings)
 {
     return(settings.CustomScript.Replace("\r\n", "\n") != MediaEncoderScript.GenerateVideoScript(settings, GetPreviewSourceFile(settings), false, true).Script.Replace("\r\n", "\n"));
 }
Esempio n. 6
0
 public void GenerateCustomScript(MediaEncoderSettings settings)
 {
     settings.CustomScript = MediaEncoderScript.GenerateVideoScript(settings, GetPreviewSourceFile(settings), false, true).Script;
 }