Exemple #1
0
        /// <summary>
        /// generates a videojob from the given settings
        /// returns the job and whether or not this is an automated job (in which case another job
        /// will have to be created)
        /// </summary>
        /// <param name="input">the video input (avisynth script)</param>
        /// <param name="output">the video output</param>
        /// <param name="settings">the codec settings for this job</param>
        /// <returns>the generated job or null if there was an error with the video source</returns>
        public static VideoJob generateVideoJob(string input, string output, VideoCodecSettings settings, Dar?dar, Zone[] zones)
        {
            VideoJob job = new VideoJob(input, output, settings, dar, zones);

            if (Path.GetDirectoryName(settings.Logfile).Equals(""))             // no path set
            {
                settings.Logfile = Path.ChangeExtension(output, ".stats");
            }
            if (job.Settings.VideoEncodingType == VideoCodecSettings.VideoEncodingMode.twopassAutomated)             // automated 2 pass, change type to 2 pass 2nd pass
            {
                job.Settings.VideoEncodingType = VideoCodecSettings.VideoEncodingMode.twopass2;
            }
            else if (job.Settings.VideoEncodingType == VideoCodecSettings.VideoEncodingMode.threepassAutomated) // automated 3 pass, change type to 3 pass first pass
            {
                if (MainForm.Instance.Settings.OverwriteStats)
                {
                    job.Settings.VideoEncodingType = VideoCodecSettings.VideoEncodingMode.threepass3;
                }
                else
                {
                    job.Settings.VideoEncodingType = VideoCodecSettings.VideoEncodingMode.twopass2; // 2 pass 2nd pass.. doesn't overwrite the stats file
                }
            }

            return(job);
        }
Exemple #2
0
        /// <summary>
        /// generates a videojob from the given settings
        /// returns the job and whether or not this is an automated job (in which case another job
        /// will have to be created)
        /// </summary>
        /// <param name="input">the video input (avisynth script)</param>
        /// <param name="output">the video output</param>
        /// <param name="settings">the codec settings for this job</param>
        /// <returns>the generated job or null if there was an error with the video source</returns>
        public VideoJob generateVideoJob(string input, string output, VideoCodecSettings settings, bool skipVideoCheck, Dar?dar, Zone[] zones)
        {
            VideoJob job = new VideoJob(input, output, settings, dar, zones);

            if (Path.GetDirectoryName(settings.Logfile).Equals(""))             // no path set
            {
                settings.Logfile = Path.ChangeExtension(input, ".stats");
            }
            if (job.Settings.EncodingMode == 4)             // automated 2 pass, change type to 2 pass 2nd pass
            {
                job.Settings.EncodingMode = 3;
                job.Settings.Turbo        = false;
            }
            else if (job.Settings.EncodingMode == 8)             // automated 3 pass, change type to 3 pass first pass
            {
                if (mainForm.Settings.OverwriteStats)
                {
                    job.Settings.EncodingMode = 7;
                }
                else
                {
                    job.Settings.EncodingMode = 3;                     // 2 pass 2nd pass.. doesn't overwrite the stats file
                }
                job.Settings.Turbo = false;
            }

            if (!skipVideoCheck)
            {
                checkVideo(job.Input);
            }

            return(job);
        }
Exemple #3
0
        /// <summary>
        /// creates a copy of the most important parameters of a job
        /// </summary>
        /// <param name="oldJob">the job to be cloned</param>
        /// <returns>the cloned job</returns>
        private VideoJob cloneJob(VideoJob oldJob)
        {
            VideoJob job = new VideoJob();

            job.Input    = oldJob.Input;
            job.Output   = oldJob.Output;
            job.Settings = oldJob.Settings.clone();
            return(job);
        }
Exemple #4
0
        /// <summary>
        /// creates a copy of the most important parameters of a job
        /// </summary>
        /// <param name="oldJob">the job to be cloned</param>
        /// <returns>the cloned job</returns>
        private static VideoJob cloneJob(VideoJob oldJob)
        {
            VideoJob job = new VideoJob();

            job.Input    = oldJob.Input;
            job.Output   = oldJob.Output;
            job.Settings = oldJob.Settings.Clone();
            job.Zones    = oldJob.Zones;
            return(job);
        }
Exemple #5
0
        public virtual bool setup(Job job, out string error)
        {
            if (!(job is VideoJob))
            {
                throw new Exception("Setup was called on a non-video job");
            }
            VideoJob vJob = (VideoJob)job;

            if (vJob.Settings is x264Settings)
            {
                encoder = new x264Encoder(settings.X264Path);
            }
            else if (vJob.Settings is xvidSettings)
            {
                encoder = new XviDEncoder(settings.XviDEncrawPath);
            }
            else
            {
                encoder = new mencoderEncoder(settings.MencoderPath);
            }
            error = null;
            return(encoder.setup(job, out error));
        }
Exemple #6
0
 /// <summary>
 /// updates the video bitrate of a video job with the given bitrate
 /// in addition, the commandline is regenerated to reflect the bitrate change
 /// </summary>
 /// <param name="job">the job whose video bitrate is to be updated</param>
 /// <param name="bitrate">the new desired video bitrate</param>
 public void updateVideoBitrate(VideoJob job, int bitrate)
 {
     job.Settings.BitrateQuantizer = bitrate;
 }
Exemple #7
0
        /// <summary>
        /// at first, the job from the currently configured settings is generated. In addition, we find out if this job is
        /// a part of an automated series of jobs. If so, it means the first generated job was the second pass, and we have
        /// to create the first pass using the same settings
        /// then, all the generated jobs are returned
        /// </summary>
        /// <returns>an Array of VideoJobs in the order they are to be encoded</returns>
        public JobChain prepareVideoJob(string movieInput, string movieOutput, VideoCodecSettings settings, Dar?dar, bool prerender, bool checkVideo, Zone[] zones)
        {
            //Check to see if output file already exists before creating the job.
            if (File.Exists(movieOutput) && !mainForm.DialogManager.overwriteJobOutput(movieOutput))
            {
                return(null);
            }

            bool twoPasses = false, threePasses = false;

            if (settings.EncodingMode == 4)             // automated twopass
            {
                twoPasses = true;
            }
            else if (settings.EncodingMode == 8)             // automated threepass
            {
                threePasses = true;
            }

            VideoJob     prerenderJob = null;
            FFMSIndexJob indexJob     = null;
            string       hfyuFile     = null;
            string       inputAVS     = movieInput;

            if (prerender)
            {
                hfyuFile = Path.Combine(Path.GetDirectoryName(movieInput), "hfyu_" +
                                        Path.GetFileNameWithoutExtension(movieInput) + ".avi");
                inputAVS = Path.ChangeExtension(hfyuFile, ".avs");
                if (File.Exists(hfyuFile))
                {
                    if (MessageBox.Show("The intended temporary file, " + hfyuFile + " already exists.\r\n" +
                                        "Do you wish to over-write it?", "File already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
                        == DialogResult.No)
                    {
                        return(null);
                    }
                }
                if (File.Exists(inputAVS))
                {
                    if (MessageBox.Show("The intended temporary file, " + inputAVS + " already exists.\r\n" +
                                        "Do you wish to over-write it?", "File already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
                        == DialogResult.No)
                    {
                        return(null);
                    }
                }
                try
                {
                    StreamWriter hfyuWrapper = new StreamWriter(inputAVS, false, Encoding.Default);
                    hfyuWrapper.WriteLine(VideoUtil.getFFMSVideoInputLine(hfyuFile, null, 0));
                    hfyuWrapper.Close();
                }
                catch (Exception)
                {
                    return(null);
                }
                indexJob     = new FFMSIndexJob(hfyuFile, null, 0, null, false);
                prerenderJob = this.generateVideoJob(movieInput, hfyuFile, new hfyuSettings(), dar, zones);
                if (prerenderJob == null)
                {
                    return(null);
                }
            }
            if (checkVideo)
            {
                VideoUtil vUtil = new VideoUtil(mainForm);
                string    error = vUtil.checkVideo(movieInput);
                if (error != null)
                {
                    bool bContinue = mainForm.DialogManager.createJobs(error);
                    if (!bContinue)
                    {
                        MessageBox.Show("Job creation aborted due to invalid AviSynth script");
                        return(null);
                    }
                }
            }
            VideoJob job        = this.generateVideoJob(inputAVS, movieOutput, settings, prerender, dar, zones);
            VideoJob firstpass  = null;
            VideoJob middlepass = null;

            if (job != null)
            {
                if (twoPasses || threePasses)                 // we just created the last pass, now create previous one(s)
                {
                    job.FilesToDelete.Add(job.Settings.Logfile);
                    if (job.Settings.SettingsID.Equals("x264"))
                    {
                        job.FilesToDelete.Add(mbtreeFile);
                    }
                    firstpass        = cloneJob(job);
                    firstpass.Output = "";                     // the first pass has no output
                    firstpass.Settings.EncodingMode = 2;
                    firstpass.DAR = dar;
                    if (threePasses)
                    {
                        firstpass.Settings.EncodingMode = 5;      // change to 3 pass 3rd pass just for show
                        middlepass = cloneJob(job);
                        middlepass.Settings.EncodingMode = 6;     // 3 pass 2nd pass
                        if (mainForm.Settings.Keep2of3passOutput) // give the 2nd pass a new name
                        {
                            middlepass.Output = Path.Combine(Path.GetDirectoryName(job.Output), Path.GetFileNameWithoutExtension(job.Output)
                                                             + "-2ndpass" + Path.GetExtension(job.Output));
                            job.FilesToDelete.Add(middlepass.Output);
                        }
                        middlepass.DAR = dar;
                    }
                }
                if (prerender)
                {
                    job.FilesToDelete.Add(hfyuFile);
                    job.FilesToDelete.Add(inputAVS);
                    job.FilesToDelete.Add(hfyuFile + ".ffindex");
                }
                List <Job> jobList = new List <Job>();
                if (prerenderJob != null)
                {
                    jobList.Add(prerenderJob);
                    jobList.Add(indexJob);
                }
                if (firstpass != null)
                {
                    jobList.Add(firstpass);
                }
                if (middlepass != null) // we have a middle pass
                {
                    jobList.Add(middlepass);
                }
                jobList.Add(job);

                return(new SequentialChain(jobList.ToArray()));
            }
            return(null);
        }