public static bool IsConvertedToColorspace(string file, string colorspace) { try { String strLastLine = "", line = ""; using (StreamReader reader = new StreamReader(file)) { while ((line = reader.ReadLine()) != null) { if (!String.IsNullOrEmpty(line)) { strLastLine = line; } } } if (strLastLine.ToLowerInvariant().Equals(AviSynthColorspaceHelper.GetConvertTo(colorspace, string.Empty).ToLowerInvariant())) { return(true); } else { return(false); } } catch { return(false); } }
public static bool AppendConvertTo(string file, AviSynthColorspace colorspace_new, AviSynthColorspace colorspace_old) { try { StreamWriter avsOut = new StreamWriter(file, true); if (MainForm.Instance.Settings.AviSynthPlus) { System.Collections.Generic.Dictionary <AviSynthColorspace, int> arrColorspace = AviSynthColorspaceHelper.GetColorSpaceDictionary(); if (!arrColorspace.TryGetValue(colorspace_new, out int iBit)) { avsOut.Write("\r\nConvertBits(8)"); } else { avsOut.Write("\r\nConvertBits(" + iBit + ")"); } } avsOut.Write("\r\n" + AviSynthColorspaceHelper.GetConvertTo(colorspace_new.ToString(), colorspace_old.ToString())); avsOut.Close(); } catch (Exception) { return(false); } return(true); }
/// <summary> /// tries to open the video source and gets the number of frames from it, or /// exits with an error /// </summary> /// <param name="videoSource">the AviSynth script</param> /// <param name="error">return parameter for all errors</param> /// <returns>true if the file could be opened, false if not</returns> protected void getInputProperties(VideoJob job) { log.LogValue("AviSynth input script", GetAVSFileContent()); double fps; Dar d = Dar.A1x1; AviSynthColorspace colorspace_original; JobUtil.GetAllInputProperties(job.Input, out numberOfFrames, out fps, out fps_n, out fps_d, out hres, out vres, out d, out colorspace_original); Dar?dar = job.DAR; su.NbFramesTotal = numberOfFrames; su.ClipLength = TimeSpan.FromSeconds((double)numberOfFrames / fps); if (!job.DAR.HasValue) { job.DAR = d; } // log if (log == null) { return; } log.LogEvent("resolution: " + hres + "x" + vres); log.LogEvent("frame rate: " + fps_n + "/" + fps_d); log.LogEvent("frames: " + numberOfFrames); log.LogEvent("length: " + string.Format("{0:00}:{1:00}:{2:00}.{3:000}", (int)(su.ClipLength.Value.TotalHours), su.ClipLength.Value.Minutes, su.ClipLength.Value.Seconds, su.ClipLength.Value.Milliseconds)); if (dar.HasValue && d.AR == dar.Value.AR) { log.LogValue("aspect ratio", d); } else { log.LogValue("aspect ratio (avs)", d); if (dar.HasValue) { log.LogValue("aspect ratio (job)", dar.Value); } } if (Int32.TryParse(colorspace_original.ToString(), out int result)) { log.LogValue("color space", colorspace_original.ToString(), ImageType.Warning); } else { log.LogValue("color space", colorspace_original.ToString()); } string strEncoder = "ffmpeg"; if (this is XviDEncoder) { strEncoder = "xvid"; } else if (this is x264Encoder && (MainForm.Instance.Settings.IsMeGUIx64 || !MainForm.Instance.Settings.Usex64Tools)) { strEncoder = "x264"; } AviSynthColorspace colorspace_target = AviSynthColorspaceHelper.GetConvertedColorspace(strEncoder, colorspace_original); if (colorspace_original != colorspace_target && !AviSynthColorspaceHelper.IsConvertedToColorspace(job.Input, colorspace_target.ToString())) { if (MainForm.Instance.DialogManager.AddConvertTo(colorspace_original.ToString(), colorspace_target.ToString())) { AviSynthColorspaceHelper.AppendConvertTo(job.Input, colorspace_target, colorspace_original); log.LogValue("AviSynth input script (appended)", GetAVSFileContent()); // Check everything again, to see if it is all fixed now AviSynthColorspace colorspace_converted; JobUtil.GetAllInputProperties(job.Input, out numberOfFrames, out fps, out fps_n, out fps_d, out hres, out vres, out d, out colorspace_converted); if (colorspace_original != colorspace_converted) { log.LogValue("color space converted", colorspace_converted.ToString()); } else { log.LogEvent("color space not supported, conversion failed", ImageType.Error); } } else { log.LogEvent("color space not supported", ImageType.Error); } } }