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); }
public AviSynthClip(IntPtr avs) { _vi = new AVSDLLVideoInfo(); this._avs = avs; _colorSpace = AviSynthColorspace.RGB32; _sampleType = AudioSampleType.INT8; }
// Methods public AviSynthClip(string func, string arg, AviSynthColorspace forceColorspace, AviSynthScriptEnvironment env) { if (dimzon_avs_init_2(ref this._avs, func, arg, ref this._vi, ref this._colorSpace, ref this._sampleType, forceColorspace.ToString()) != 0) { string message = this.getLastError(); this.cleanup(false); throw new AviSynthException(message); } }
public AviSynthClip(string func, string arg, bool bRequireRGB24, bool bRunInThread) { _vi = new AVSDLLVideoInfo(); _avs = IntPtr.Zero; _colorSpace = AviSynthColorspace.Unknown; _sampleType = AudioSampleType.Unknown; bool bOpenSuccess = false; string strErrorMessage = string.Empty; lock (_locker) { Random rnd = new Random(); _random = rnd.Next(1, 1000000); if (MainForm.Instance.Settings.ShowDebugInformation) { HandleAviSynthWrapperDLL(false, arg); } System.Windows.Forms.Application.UseWaitCursor = true; if (bRunInThread) { Thread t = new Thread(new ThreadStart(delegate { bOpenSuccess = OpenAVSScript(func, arg, bRequireRGB24, out strErrorMessage); })); t.Start(); while (t.ThreadState == ThreadState.Running) { MeGUI.core.util.Util.Wait(1000); } } else { bOpenSuccess = OpenAVSScript(func, arg, bRequireRGB24, out strErrorMessage); } System.Windows.Forms.Application.UseWaitCursor = false; } if (bOpenSuccess == false) { string err = string.Empty; if (_avs != IntPtr.Zero) { err = getLastError(); } else { err = strErrorMessage; } Dispose(false); throw new AviSynthException(err); } }
public AviSynthClip(string func, string arg, AviSynthColorspace colorSpace) { _vi = new AVSDLLVideoInfo(); _avs = new IntPtr(0); _colorSpace = AviSynthColorspace.Unknown; _sampleType = AudioSampleType.Unknown; if (0 != dimzon_avs_init(ref _avs, func, arg, ref _vi, ref _colorSpace, ref _sampleType, colorSpace.ToString())) { var err = GetLastError(); throw new ApplicationException(err); } }
public AviSynthClip(string func, string arg , AviSynthColorspace forceColorspace, AviSynthScriptEnvironment env) { _vi = new AVSDLLVideoInfo(); _avs = new IntPtr(0); _colorSpace = AviSynthColorspace.Unknown; _sampleType = AudioSampleType.Unknown; if(0!=dimzon_avs_init_2(ref _avs, func, arg, ref _vi, ref _colorSpace, ref _sampleType, forceColorspace.ToString())) { string err = getLastError(); cleanup(false); throw new AviSynthException(err); } }
public AviSynthClip(string func, string arg, AviSynthColorspace forceColorspace, AviSynthScriptEnvironment env) { _vi = new AVSDLLVideoInfo(); _avs = new IntPtr(0); _colorSpace = AviSynthColorspace.Unknown; _sampleType = AudioSampleType.Unknown; if (0 != dimzon_avs_init(ref _avs, func, arg, ref _vi, ref _colorSpace, ref _sampleType, forceColorspace.ToString())) { string err = getLastError(); cleanup(false); throw new AviSynthException(err); } }
public AviSynthClip(string func, string arg, AviSynthColorspace forceColorspace, AviSynthScriptEnvironment env) { _vi = new AVSDLLVideoInfo(); _avs = new IntPtr(0); _colorSpace = AviSynthColorspace.Unknown; _sampleType = AudioSampleType.Unknown; bool bOpenSuccess = false; if (MainForm.Instance.Settings.OpenAVSInThreadDuringSession) { MainForm.Instance.AvsLock++; Thread t = new Thread(new ThreadStart(delegate { System.Windows.Forms.Application.UseWaitCursor = true; if (0 == dimzon_avs_init_2(ref _avs, func, arg, ref _vi, ref _colorSpace, ref _sampleType, forceColorspace.ToString())) { bOpenSuccess = true; } MainForm.Instance.AvsLock--; if (MainForm.Instance.AvsLock == 0) { System.Windows.Forms.Application.UseWaitCursor = false; } })); t.Start(); while (t.ThreadState == ThreadState.Running) { System.Windows.Forms.Application.DoEvents(); Thread.Sleep(100); } } else { if (0 == dimzon_avs_init_2(ref _avs, func, arg, ref _vi, ref _colorSpace, ref _sampleType, forceColorspace.ToString())) { bOpenSuccess = true; } } if (bOpenSuccess == false) { string err = getLastError(); cleanup(false); throw new AviSynthException(err); } }
//Полноценное открытие: инициализация + Invoke + GetVideoInfo (func обязательно должна возвращать Clip с видео!) public AviSynthClip(string func, string arg, AviSynthColorspace forceColorSpace, AudioSampleType forceSampleType) //, AviSynthScriptEnvironment env) { _avs = new IntPtr(0); _vi = new AVSDLLVideoInfo(); _vi.mt_import = (SysInfo.AVSIsMT) ? Settings.MTMode_Internal : MTMode.Undefined; //Эти два поля работают и на вход, и на выход. Для "dimzon_avs_init" через них можно задать требуемые на выходе PixelType и SampleType. //При нуле (Undefined) никаких преобразований не будет. На выходе из "dimzon_avs_init" поля будут содержать то, что получилось в итоге. //В "dimzon_avs_invoke" работают только на выход. _vi.pixel_type = forceColorSpace; _vi.sample_type = forceSampleType; //Эти поля содержат инфу об исходных PixelType и SampleType, т.е. до того, как они были изменены в "dimzon_avs_init". //В "dimzon_avs_invoke" обновляются только в случае их равенства нулю. _vi.pixel_type_orig = AviSynthColorspace.Undefined; _vi.sample_type_orig = AudioSampleType.Undefined; if (0 != dimzon_avs_init(ref _avs, func, arg, ref _vi)) { string err = GetLastError(); cleanup(false); throw new AviSynthException(err); } }
//, AviSynthScriptEnvironment env) //Полноценное открытие: инициализация + Invoke + GetVideoInfo (func обязательно должна возвращать Clip с видео!) public AviSynthClip(string func, string arg, AviSynthColorspace forceColorSpace, AudioSampleType forceSampleType) { _avs = new IntPtr(0); _vi = new AVSDLLVideoInfo(); _vi.mt_import = (SysInfo.AVSIsMT) ? Settings.MTMode_Internal : MTMode.Undefined; //Эти два поля работают и на вход, и на выход. Для "dimzon_avs_init" через них можно задать требуемые на выходе PixelType и SampleType. //При нуле (Undefined) никаких преобразований не будет. На выходе из "dimzon_avs_init" поля будут содержать то, что получилось в итоге. //В "dimzon_avs_invoke" работают только на выход. _vi.pixel_type = forceColorSpace; _vi.sample_type = forceSampleType; //Эти поля содержат инфу об исходных PixelType и SampleType, т.е. до того, как они были изменены в "dimzon_avs_init". //В "dimzon_avs_invoke" обновляются только в случае их равенства нулю. _vi.pixel_type_orig = AviSynthColorspace.Undefined; _vi.sample_type_orig = AudioSampleType.Undefined; if (0 != dimzon_avs_init(ref _avs, func, arg, ref _vi)) { string err = GetLastError(); cleanup(false); throw new AviSynthException(err); } }
public AviSynthReader() { //По умолчанию форматы не меняются forced_colorspace = AviSynthColorspace.Undefined; forced_sampletype = AudioSampleType.Undefined; }
public AviSynthClip OpenScriptFile(string filePath, AviSynthColorspace forceColorSpace, AudioSampleType forceSampleType) { return(new AviSynthClip("Import", filePath, forceColorSpace, forceSampleType)); //, this); }
/// <summary> /// Detects if the AviSynth version can be used /// </summary> /// <returns>0 if everything is fine, 3 if the version is outdated or a different value for other errors</param> public static int CheckAvisynthInstallation(out string strVersion, out bool bIsAVS26, out bool bIsAVSPlus, out bool bIsMT, out string strAviSynthDLL, ref core.util.LogItem oLog) { strVersion = ""; bIsAVS26 = false; bIsAVSPlus = false; bIsMT = false; strAviSynthDLL = string.Empty; IntPtr _avs = new IntPtr(0); AVSDLLVideoInfo _vi = new AVSDLLVideoInfo(); AviSynthColorspace _colorSpace = AviSynthColorspace.Unknown; AudioSampleType _sampleType = AudioSampleType.Unknown; int iStartResult = -1; try { iStartResult = dimzon_avs_init_2(ref _avs, "Eval", "Version()", ref _vi, ref _colorSpace, ref _sampleType, AviSynthColorspace.RGB24.ToString()); foreach (System.Diagnostics.ProcessModule module in System.Diagnostics.Process.GetCurrentProcess().Modules) { if (module.FileName.ToLowerInvariant().EndsWith("avisynth.dll")) { strAviSynthDLL = module.FileName.ToLowerInvariant(); } } if (iStartResult == 0) { int iWrapperVersion = GetAvisynthWrapperInterfaceVersion(); try { const int errlen = 1024; StringBuilder sb = new StringBuilder(errlen); sb.Length = dimzon_avs_getstrfunction(_avs, "VersionString", sb, errlen); strVersion = sb.ToString(); bool bResult = false; int iResult = dimzon_avs_functionexists(_avs, "AutoloadPlugins", ref bResult); bIsAVSPlus = false; if (iResult == 0) { bIsAVSPlus = bResult; } if (iWrapperVersion < 5) { bResult = false; iResult = dimzon_avs_functionexists(_avs, "ConvertToYV16", ref bResult); bIsAVS26 = false; if (iResult == 0) { bIsAVS26 = bResult; } } else { bIsAVS26 = true; } string strMTFunction = "Prefetch"; if (!bIsAVSPlus) { strMTFunction = "SetMTMode"; } bResult = false; iResult = dimzon_avs_functionexists(_avs, strMTFunction, ref bResult); bIsMT = false; if (iResult == 0) { bIsMT = bResult; } } catch (Exception ex) { oLog.LogValue("Error", ex.Message, core.util.ImageType.Error, false); } } int iCloseResult = dimzon_avs_destroy(ref _avs); if (_avs != IntPtr.Zero) { CloseHandle(_avs); } _avs = IntPtr.Zero; } catch (Exception ex) { oLog.LogValue("Error", ex.Message, core.util.ImageType.Error, false); } return(iStartResult); }
/// <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); } } }
public AviSynthClip ParseScript(string script, AviSynthColorspace forceColorSpace, AudioSampleType forceSampleType) { return(new AviSynthClip("Eval", script, forceColorSpace, forceSampleType)); //, this); }
public AviSynthClip OpenScriptFile(string filePath, AviSynthColorspace forceColorspace) { return new AviSynthClip("Import", filePath, forceColorspace, this); }
public AviSynthClip New(AviSynthColorspace forceColorspace) { return new AviSynthClip(forceColorspace, this); }
public AviSynthClip ParseScript(string script, AviSynthColorspace forceColorspace) { return(new AviSynthClip("Eval", script, forceColorspace, this)); }
public AviSynthClip ParseScript(string script, AviSynthColorspace forceColorSpace, AudioSampleType forceSampleType) { return new AviSynthClip("Eval", script, forceColorSpace, forceSampleType); //, this); }
public AviSynthClip OpenScriptFile(string filePath, AviSynthColorspace forceColorSpace, AudioSampleType forceSampleType) { return new AviSynthClip("Import", filePath, forceColorSpace, forceSampleType); //, this); }
/// <summary> /// gets the number of frames, framerate, horizontal and vertical resolution from a video source /// </summary> /// <param name="video">the video whose properties are to be read</param> /// <param name="nbOfFrames">the number of frames</param> /// <param name="framerate">the framerate</param> /// <param name="framerate_d">the FPS_D</param> /// <param name="framerate_n">the FPS_N</param> /// <param name="hRes">the horizontal resolution</param> /// <param name="vRes">the vertical resolution</param> /// <param name="dar">the dar value</param> /// <returns>whether the source could be opened or not</returns> public static bool GetAllInputProperties(string video, out ulong nbOfFrames, out double framerate, out int framerate_n, out int framerate_d, out int hRes, out int vRes, out Dar dar, out AviSynthColorspace colorspace) { try { using (AvsFile avi = AvsFile.OpenScriptFile(video)) { checked { nbOfFrames = (ulong)avi.VideoInfo.FrameCount; } framerate = avi.VideoInfo.FPS; framerate_n = avi.VideoInfo.FPS_N; framerate_d = avi.VideoInfo.FPS_D; hRes = (int)avi.VideoInfo.Width; vRes = (int)avi.VideoInfo.Height; dar = avi.VideoInfo.DAR; colorspace = avi.Clip.OriginalColorspace; } return(true); } catch (Exception e) { throw new JobRunException("The file " + video + " cannot be opened.\r\n" + "Error message for your reference: " + e.Message, e); } }
public AviSynthReader(AviSynthColorspace forceColorSpace, AudioSampleType forceSampleType) { //Если надо - меняем форматы forced_colorspace = forceColorSpace; forced_sampletype = forceSampleType; }
public AviSynthClip ParseScript(string script, AviSynthColorspace forceColorspace) { return new AviSynthClip("Eval", script, forceColorspace, this); }
private static extern int dimzon_avs_init(ref IntPtr avs, string func, string arg, ref AVSDLLVideoInfo vi, ref AviSynthColorspace originalColorspace, ref AudioSampleType originalSampleType, string cs);
/// <summary> /// Gets the target color space /// </summary> /// <param name="strEncoder">the encoder which will be used</param> /// <param name="colorspace">the current color space</param> /// <returns>Target Color Space</returns> public static AviSynthColorspace GetConvertedColorspace(string strEncoder, AviSynthColorspace colorspace) { ArrayList arrCodecsAllowed = new ArrayList(); // add always available color spaces arrCodecsAllowed.Add(AviSynthColorspace.I420); arrCodecsAllowed.Add(AviSynthColorspace.YV12); // if avs+ is used add the available color spaces for ffmpeg+x264 if (!strEncoder.Equals("xvid") && MainForm.Instance.Settings.AviSynthPlus) { arrCodecsAllowed.Add(AviSynthColorspace.YUV420P16); } if (strEncoder.Equals("ffmpeg")) { // ffmpeg is used arrCodecsAllowed.Add(AviSynthColorspace.YV16); arrCodecsAllowed.Add(AviSynthColorspace.YV24); arrCodecsAllowed.Add(AviSynthColorspace.YV411); // > 8bit is only possible if AVS+ is used if (MainForm.Instance.Settings.AviSynthPlus) { arrCodecsAllowed.Add(AviSynthColorspace.YUV444P10); arrCodecsAllowed.Add(AviSynthColorspace.YUV422P10); arrCodecsAllowed.Add(AviSynthColorspace.YUV420P10); arrCodecsAllowed.Add(AviSynthColorspace.YUV444P12); arrCodecsAllowed.Add(AviSynthColorspace.YUV422P12); arrCodecsAllowed.Add(AviSynthColorspace.YUV420P12); arrCodecsAllowed.Add(AviSynthColorspace.YUV444P14); arrCodecsAllowed.Add(AviSynthColorspace.YUV422P14); arrCodecsAllowed.Add(AviSynthColorspace.YUV420P14); arrCodecsAllowed.Add(AviSynthColorspace.YUV444P16); arrCodecsAllowed.Add(AviSynthColorspace.YUV422P16); arrCodecsAllowed.Add(AviSynthColorspace.YUV420P16); } } // check if the current color space does not have to be changed if (arrCodecsAllowed.Contains(colorspace)) { return(colorspace); } // if xvid is the encoder or AVS+ is not used, YV12 has to be used if (strEncoder.Equals("xvid") || !MainForm.Instance.Settings.AviSynthPlus) { return(AviSynthColorspace.YV12); } // try to get the bit depth Dictionary <AviSynthColorspace, int> arrColorspace = GetColorSpaceDictionary(); if (!arrColorspace.TryGetValue(colorspace, out int iBit)) { return(colorspace); } if (strEncoder.Equals("ffmpeg")) { switch (iBit) { case 8: colorspace = AviSynthColorspace.YV12; break; case 10: colorspace = AviSynthColorspace.YUV420P10; break; case 12: colorspace = AviSynthColorspace.YUV420P12; break; case 14: colorspace = AviSynthColorspace.YUV420P14; break; case 16: colorspace = AviSynthColorspace.YUV420P16; break; case 32: colorspace = AviSynthColorspace.YUV420P16; break; default: colorspace = AviSynthColorspace.YV12; break; } } else { switch (iBit) { case 8: colorspace = AviSynthColorspace.YV12; break; default: colorspace = AviSynthColorspace.YUV420P16; break; } } return(colorspace); }
public AviSynthClip OpenScriptFile(string filePath, AviSynthColorspace forceColorspace) { return(new AviSynthClip("Import", filePath, forceColorspace, this)); }
public static string GetLSMASHFormat8(AviSynthColorspace csp) { //Что LSMASH нам выдал с хаком, то ему и укажем, но уже в варианте 8-bit. if (csp == AviSynthColorspace.I420) return "YUV420P8"; if (csp == AviSynthColorspace.YV12) return "YUV420P8"; if (csp == AviSynthColorspace.YV16) return "YUV422P8"; //"YUY2" if (csp == AviSynthColorspace.YV24) return "YUV444P8"; return "YUY2"; }
private static extern int dimzon_avs_init_2(ref IntPtr avs, string func, string arg, ref AVSDLLVideoInfo vi, ref AviSynthColorspace originalColorspace, ref AudioSampleType originalSampleType, string cs);