private static LogItem postprocess(MainForm mainForm, Job ajob) { if (!(ajob is FFMSIndexJob)) { return(null); } FFMSIndexJob job = (FFMSIndexJob)ajob; StringBuilder logBuilder = new StringBuilder(); VideoUtil vUtil = new VideoUtil(mainForm); List <string> arrFilesToDelete = new List <string>(); Dictionary <int, string> audioFiles = vUtil.getAllDemuxedAudio(job.AudioTracks, job.AudioTracksDemux, out arrFilesToDelete, job.Output, null); if (job.LoadSources) { if (job.DemuxMode != 0) { string[] files = new string[audioFiles.Values.Count]; audioFiles.Values.CopyTo(files, 0); Util.ThreadSafeRun(mainForm, new MethodInvoker( delegate { mainForm.Audio.openAudioFile(files); })); } // if the above needed delegation for openAudioFile this needs it for openVideoFile? // It seems to fix the problem of ASW dissapearing as soon as it appears on a system (Vista X64) Util.ThreadSafeRun(mainForm, new MethodInvoker( delegate { AviSynthWindow asw = new AviSynthWindow(mainForm, job.Input, job.Output); asw.OpenScript += new OpenScriptCallback(mainForm.Video.openVideoFile); asw.Show(); })); } return(null); }
/// <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); }
/// <summary> /// creates a project /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void queueButton_Click(object sender, System.EventArgs e) { if (dialogMode) { return; } if (!configured) { MessageBox.Show("You must select the input and output file to continue", "Configuration incomplete", MessageBoxButtons.OK); return; } if (!Drives.ableToWriteOnThisDrive(Path.GetPathRoot(output.Filename))) { MessageBox.Show("MeGUI cannot write on the disc " + Path.GetPathRoot(output.Filename) + "\n" + "Please, select another output path to save your project...", "Configuration Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } JobChain prepareJobs = null; string videoInput = input.Filename; // create pgcdemux job if needed if (Path.GetExtension(input.Filename).ToUpperInvariant().Equals(".IFO")) { if (iFile.VideoInfo.PGCCount > 1 || iFile.VideoInfo.AngleCount > 0) { // pgcdemux must be used as either multiple PGCs or a multi-angle disc are found string tempFile = Path.Combine(Path.GetDirectoryName(output.Filename), Path.GetFileNameWithoutExtension(output.Filename) + "_1.VOB"); prepareJobs = new SequentialChain(new PgcDemuxJob(videoInput, tempFile, iFile.VideoInfo.PGCNumber, iFile.VideoInfo.AngleNumber)); videoInput = tempFile; string filesToOverwrite = string.Empty; for (int i = 1; i < 10; i++) { string file = Path.Combine(Path.GetDirectoryName(output.Filename), Path.GetFileNameWithoutExtension(output.Filename) + "_" + i + ".VOB"); if (File.Exists(file)) { filesToOverwrite += file + "\n"; } } if (!String.IsNullOrEmpty(filesToOverwrite)) { DialogResult dr = MessageBox.Show("The pgc demux files already exist: \n" + filesToOverwrite + "\n" + "Do you want to overwrite these files?", "Configuration Incomplete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.No) { return; } } } else { // change from _0.IFO to _1.VOB for the indexer videoInput = input.Filename.Substring(0, input.Filename.Length - 5) + "1.VOB"; if (!File.Exists(videoInput)) { MessageBox.Show("The file following file cannot be found: \n" + videoInput, "Configuration Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } else if (Path.GetExtension(input.Filename).ToUpperInvariant().Equals(".MPLS") && IndexerUsed != IndexType.DGI && IndexerUsed != IndexType.DGM) { // blu-ray playlist without DGI/DGM used - therefore eac3to must be used first string strTempMKVFile = Path.Combine(Path.GetDirectoryName(output.Filename), Path.GetFileNameWithoutExtension(output.Filename) + ".mkv"); if (File.Exists(strTempMKVFile)) { DialogResult dr = MessageBox.Show("The demux file already exist: \n" + strTempMKVFile + "\n" + "Do you want to overwrite this file?", "Configuration Incomplete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.No) { return; } } StringBuilder sb = new StringBuilder(); sb.Append(string.Format("{0}:\"{1}\" ", iFile.VideoInfo.Track.TrackID, strTempMKVFile)); foreach (AudioTrackInfo oStreamControl in AudioTracks.CheckedItems) { bool bCoreOnly = false; AudioCodec audioCodec = oStreamControl.AudioCodec; if (oStreamControl.HasCore && !MainForm.Instance.Settings.Eac3toDefaultToHD) { // audio file can be demuxed && should be touched (core needed) if (audioCodec == AudioCodec.THDAC3) { oStreamControl.Codec = "AC-3"; oStreamControl.AudioType = AudioType.AC3; oStreamControl.AudioCodec = AudioCodec.AC3; bCoreOnly = true; oStreamControl.HasCore = false; } else if (audioCodec == AudioCodec.DTS) { oStreamControl.Codec = "DTS"; oStreamControl.AudioType = AudioType.DTS; oStreamControl.AudioCodec = AudioCodec.DTS; oStreamControl.HasCore = false; bCoreOnly = true; } } // core must be extracted (workaround for an eac3to issue) // http://bugs.madshi.net/view.php?id=450 if (audioCodec == AudioCodec.EAC3) { bCoreOnly = true; } string strSourceFileName = Path.Combine(Path.GetDirectoryName(input.Filename), Path.GetFileNameWithoutExtension(strTempMKVFile)); oStreamControl.SourceFileName = strSourceFileName; sb.Append(string.Format("{0}:\"{1}\" ", oStreamControl.TrackID, Path.Combine(Path.GetDirectoryName(output.Filename), oStreamControl.DemuxFileName))); if (bCoreOnly) { sb.Append("-core "); } } HDStreamsExJob oJob = new HDStreamsExJob(new List <string>() { input.Filename }, Path.GetDirectoryName(output.Filename), null, sb.ToString(), 2); prepareJobs = new SequentialChain(oJob); videoInput = strTempMKVFile; } switch (IndexerUsed) { case IndexType.D2V: { prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(generateD2VIndexJob(videoInput))); MainForm.Instance.Jobs.AddJobsWithDependencies(prepareJobs, true); if (this.closeOnQueue.Checked) { this.Close(); } break; } case IndexType.DGI: { prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(generateDGNVIndexJob(videoInput))); MainForm.Instance.Jobs.AddJobsWithDependencies(prepareJobs, true); if (this.closeOnQueue.Checked) { this.Close(); } break; } case IndexType.DGM: { prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(generateDGMIndexJob(videoInput))); MainForm.Instance.Jobs.AddJobsWithDependencies(prepareJobs, true); if (this.closeOnQueue.Checked) { this.Close(); } break; } case IndexType.FFMS: { FFMSIndexJob job = generateFFMSIndexJob(videoInput); if (job.DemuxMode > 0 && job.AudioTracks.Count > 0 && (txtContainerInformation.Text.Trim().ToUpperInvariant().Equals("MATROSKA") || txtContainerInformation.Text.Trim().ToUpperInvariant().Equals("BLU-RAY PLAYLIST"))) { job.DemuxMode = 0; job.AudioTracksDemux = job.AudioTracks; job.AudioTracks = new List <AudioTrackInfo>(); if (txtContainerInformation.Text.Trim().ToUpperInvariant().Equals("MATROSKA")) { MkvExtractJob extractJob = new MkvExtractJob(videoInput, Path.GetDirectoryName(this.output.Filename), job.AudioTracksDemux); prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(extractJob)); } } prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(job)); MainForm.Instance.Jobs.AddJobsWithDependencies(prepareJobs, true); if (this.closeOnQueue.Checked) { this.Close(); } break; } case IndexType.LSMASH: { LSMASHIndexJob job = generateLSMASHIndexJob(videoInput); if (job.DemuxMode > 0 && job.AudioTracks.Count > 0 && (txtContainerInformation.Text.Trim().ToUpperInvariant().Equals("MATROSKA") || txtContainerInformation.Text.Trim().ToUpperInvariant().Equals("BLU-RAY PLAYLIST"))) { job.DemuxMode = 0; job.AudioTracksDemux = job.AudioTracks; job.AudioTracks = new List <AudioTrackInfo>(); if (txtContainerInformation.Text.Trim().ToUpperInvariant().Equals("MATROSKA")) { MkvExtractJob extractJob = new MkvExtractJob(videoInput, Path.GetDirectoryName(this.output.Filename), job.AudioTracksDemux); prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(extractJob)); } } prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(job)); MainForm.Instance.Jobs.AddJobsWithDependencies(prepareJobs, true); if (this.closeOnQueue.Checked) { this.Close(); } break; } } }
/// <summary> /// creates a project /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void queueButton_Click(object sender, System.EventArgs e) { if (dialogMode) { return; } if (!configured) { MessageBox.Show("You must select the input and output file to continue", "Configuration incomplete", MessageBoxButtons.OK); return; } if (!Drives.ableToWriteOnThisDrive(Path.GetPathRoot(output.Text))) { MessageBox.Show("MeGUI cannot write on the disc " + Path.GetPathRoot(output.Text) + "\n" + "Please, select another output path to save your project...", "Configuration Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } JobChain prepareJobs = null; string videoInput = input.Filename; // create pgcdemux job if needed if (cbPGC.SelectedIndex > 0 && Path.GetExtension(input.Filename.ToUpper(System.Globalization.CultureInfo.InvariantCulture)) == ".VOB") { string videoIFO; // PGC numbers are not present in VOB, so we check the main IFO if (Path.GetFileName(input.Filename).ToUpper(System.Globalization.CultureInfo.InvariantCulture).Substring(0, 4) == "VTS_") { videoIFO = input.Filename.Substring(0, input.Filename.LastIndexOf("_")) + "_0.IFO"; } else { videoIFO = Path.ChangeExtension(input.Filename, ".IFO"); } if (File.Exists(videoIFO)) { prepareJobs = new SequentialChain(new PgcDemuxJob(videoIFO, Path.GetDirectoryName(output.Text), cbPGC.SelectedIndex)); videoInput = Path.Combine(Path.GetDirectoryName(output.Text), "VTS_01_1.VOB"); for (int i = 1; i < 10; i++) { string file = Path.Combine(Path.GetDirectoryName(output.Text), "VTS_01_" + i + ".VOB"); if (File.Exists(file)) { MessageBox.Show("The pgc demux file already exists: \n" + file + "\n\n" + "Please select another output path to save your project.", "Configuration Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } } switch (IndexerUsed) { case IndexType.D2V: { prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(generateD2VIndexJob(videoInput))); mainForm.Jobs.addJobsWithDependencies(prepareJobs); if (this.closeOnQueue.Checked) { this.Close(); } break; } case IndexType.DGI: { prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(generateDGNVIndexJob(videoInput))); mainForm.Jobs.addJobsWithDependencies(prepareJobs); if (this.closeOnQueue.Checked) { this.Close(); } break; } case IndexType.DGA: { prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(generateDGAIndexJob(videoInput))); mainForm.Jobs.addJobsWithDependencies(prepareJobs); if (this.closeOnQueue.Checked) { this.Close(); } break; } case IndexType.FFMS: { FFMSIndexJob job = generateFFMSIndexJob(videoInput); if (txtContainerInformation.Text.Trim().ToUpper(System.Globalization.CultureInfo.InvariantCulture).Equals("MATROSKA") && job.DemuxMode > 0 && job.AudioTracks.Count > 0) { job.AudioTracksDemux = job.AudioTracks; job.AudioTracks = new List <AudioTrackInfo>(); MkvExtractJob extractJob = new MkvExtractJob(videoInput, Path.GetDirectoryName(this.output.Text), job.AudioTracksDemux); prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(extractJob)); } prepareJobs = new SequentialChain(prepareJobs, new SequentialChain(job)); mainForm.Jobs.addJobsWithDependencies(prepareJobs); if (this.closeOnQueue.Checked) { this.Close(); } break; } } }