public AviSynthClip(AviSynthColorspace forceColorspace, AviSynthScriptEnvironment env) { _vi = new AVSDLLVideoInfo(); _avs = new IntPtr(0); _colorSpace = AviSynthColorspace.Unknown; _sampleType = AudioSampleType.Unknown; if (0 != avs_init(ref _avs, "blankclip", "", ref _vi, ref _colorSpace, ref _sampleType, forceColorspace.ToString())) { string err = getLastError(); cleanup(false); throw new AviSynthException(err); } }
private void RefreshImageAVS() { string tmp = GetTempFileName(); AVSTextBox a = GetAVSTextBox(tabControl.SelectedIndex); a.SaveFile(tmp, RichTextBoxStreamType.PlainText); try { File.SetAttributes(tmp, FileAttributes.Hidden); } catch { } try { TabPage t = (TabPage)tabControl.Controls[tabControl.SelectedIndex]; int k = t.Handle.ToInt32(); AviSynthScriptEnvironment env = new AviSynthScriptEnvironment(); AviSynthClip clip = env.OpenScriptFile(tmp); if (AVSEnvironments.ContainsKey(k)) AVSEnvironments.Remove(k); AVSEnvironments.Add(k, env); if (AVSClips.ContainsKey(k)) { AviSynthClip old_clip = (AviSynthClip)AVSClips[k]; old_clip.cleanup(false); AVSClips.Remove(k); } AVSClips.Add(k, clip); if (AVSActualFrames.ContainsKey(k)) AVSActualFrames.Remove(k); AVSActualFrames.Add(k, 0); DateTime inicio = DateTime.Now; PictureBox p = GetPictureBox(tabControl.SelectedIndex); Bitmap frame = AviSynthFunctions.getBitmapFromFrame(clip, 0, 0); p.Size = frame.Size; p.Image = frame; DateTime fin = DateTime.Now; TimeSpan tiempo = fin - inicio; int t_millis = tiempo.Milliseconds; label1.Text = "Tiempo de carga: " + t_millis.ToString() + "ms"; updateFromAviSynthClip(clip); /* int tiempo_est = (t_millis * clip.num_frames); long ticks = tiempo_est * 10000000; TimeSpan t_est = new TimeSpan(ticks); label2.Text = "Tiempo estimado: " + t_est.ToString(); */ } catch (AviSynthException ase) { mW.errorMsg(ase.Message); } }
private void showPreview() { if (listBox1.SelectedIndex == -1) { mW.errorMsg("No se puede hacer preview si no hay un estilo seleccionado."); return; } if (!checkBox1.Checked) return; try { env = new AviSynthScriptEnvironment(); string script0rz = "blankclip(color=$"+PreviewBackColor+")"; avs = env.ParseScript(script0rz); string vsf_path = AviSynthFunctions.getVSFilterPath(avs); if (vsf_path != null) avs.AviSynthInvoke(avs.GetAVS(),0, "LoadPlugin", false, vsf_path); makeTempFile(); avs.AviSynthInvoke(avs.GetAVS(), 0, "Eval", false, script0rz); avs.AviSynthInvoke(avs.GetAVS(),0, "TextSub", true, PreviewFile); Bitmap b = AviSynthFunctions.getBitmapFromFrame(avs,0,0); b = BitmapFunctions.Crop(b, 640, 480, 0, 376); stylePreviewBox.Image = b; } catch { mW.errorMsg("Error cargando AviSynth."); checkBox1.Checked = false; } }
private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked) { stylePreviewBox.Visible=true; showPreview(); } else { stylePreviewBox.Visible=false; avs=null; env=null; } }
private void gridASS_CellContentClick(object sender, DataGridViewCellEventArgs e) { switch (e.ColumnIndex) { case 1: //MessageBox.Show(script.GetLines()[e.RowIndex].ToString()); string presx = script.GetHeader().GetHeaderValue("PlayResX"); string presy = script.GetHeader().GetHeaderValue("PlayResY"); int py = -1, px = -1; if (presx.Equals(string.Empty) && presy.Equals(string.Empty)) return; if (presx.Equals(string.Empty)) { py = int.Parse(presy); px = ((py * 4) / 3); } else if (presy.Equals(string.Empty)) { px = int.Parse(presx); py = ((px * 3) / 4); } else { px = int.Parse(presx); py = int.Parse(presy); } try { AviSynthScriptEnvironment env = new AviSynthScriptEnvironment(); string script0rz = "blankclip(color=$000000,width=" + px + ",height=" + py + ")"; AviSynthClip avs = env.ParseScript(script0rz); string vsf_path = AviSynthFunctions.getVSFilterPath(avs); if (vsf_path != null) avs.AviSynthInvoke(avs.GetAVS(), 0, "LoadPlugin", false, vsf_path); // escribir ssa temporal string PreviewFile = "PrevFile-l" + e.RowIndex + ".ass"; lineaASS actual = (lineaASS)script.GetLineArrayList().GetFullArrayList()[e.RowIndex]; TextWriter o = new StreamWriter(PreviewFile, false, System.Text.Encoding.UTF8); o.WriteLine(headerMark); o.WriteLine(script.GetHeader().ToString()); o.WriteLine(stylesMark); foreach (estiloV4 e2 in script.GetStyles()) { if (e2.Name.Equals(actual.estilo)) { estiloV4 new_est = new estiloV4(e2.ToString()); new_est.PrimaryColor = "&H00FFFFFF"; new_est.SecondaryColor = "&H00FFFFFF"; new_est.OutlineColor = "&H00FFFFFF"; new_est.ShadowColor = "&H00FFFFFF"; o.WriteLine(new_est.ToString().Replace("\n", string.Empty)); } } o.WriteLine(); // --- o.WriteLine(dialoguesMark); actual.t_inicial.setTiempo(0); actual.t_final.setTiempo(50); o.WriteLine(actual.ToString()); o.Close(); avs.AviSynthInvoke(avs.GetAVS(), 0, "Eval", false, script0rz); avs.AviSynthInvoke(avs.GetAVS(), 0, "TextSub", true, PreviewFile); //LinePreviewBox.Image = (Image)AviSynthFunctions.getBitmapFromFrame(avs, 0, 0); avs.cleanup(true); File.Delete(PreviewFile); //b = BitmapFunctions.Crop(b, 640, 480, 0, 376); } catch { errorMsg("Error cargando AviSynth."); } break; } }
private AviSynthClip LoadAudioWithDependencies(AviSynthClip avsc, string filename) { OpenAudioSourceType = GetAudioSourceFilter(filename); AviSynthScriptEnvironment env = new AviSynthScriptEnvironment(); avsc = env.ParseScript("BlankClip"); switch (OpenAudioSourceType) { case AudioSourceType.DirectShowSource: avsc.AviSynthInvoke(avsc.GetAVS(), 0, "LoadPlugin", false, System.IO.Path.Combine(Application.StartupPath, "DirectShowSource.dll")); break; case AudioSourceType.FFAudioSource: avsc.AviSynthInvoke(avsc.GetAVS(), 0, "LoadPlugin", false, System.IO.Path.Combine(Application.StartupPath, "ffms2.dll")); break; default: break; } avsc.AviSynthInvoke(avsc.GetAVS(), 0, OpenAudioSourceType.ToString(), false, filename); avsc.AviSynthInvoke(avsc.GetAVS(), 0, "killvideo", false, "Nulo"); return avsc; }
private void InitAviSynth(out AviSynthScriptEnvironment env, out AviSynthClip avs) { env = new AviSynthScriptEnvironment(); avs = env.ParseScript("blankclip(color=$000000,width=" + width + ",height=" + height + ")"); string vsf_path = AviSynthFunctions.getVSFilterPath(avs); if (vsf_path != null) avs.AviSynthInvoke(avs.GetAVS(), 0, "LoadPlugin", false, vsf_path); }
private void openAVS(string fname) { videoPictureBox.Visible = true; if (VideoBoxType == PreviewType.DirectShow) { VideoBoxType = PreviewType.AviSynth; videoWindow.put_Visible(DirectShowLib.OABool.False); setStatus("Cargando modo AviSynth. Dependiendo de los filtros, puede tardar unos segundos..."); try { OpenSourceType = GetVideoSourceFilter(fname); OpenAudioSourceType = HasAudio(fname) ? GetAudioSourceFilter(fname) : AudioSourceType.None; if (avsClip != null) avsClip.cleanup(true); if (avsaudio != null) avsaudio.cleanup(true); } catch (AviSynthException x) { errorMsg("No se puede entrar en el modo AviSynth.\nMensaje de error : " + x.Message); VideoBoxType = PreviewType.DirectShow; videoWindow.put_Visible(DirectShowLib.OABool.True); return; } try { avsEnv = new AviSynthScriptEnvironment(); avsClip = avsEnv.ParseScript("BlankClip"); avsaudio = avsEnv.ParseScript("BlankClip"); string vsf = AviSynthFunctions.getVSFilterPath(avsClip); if (vsf != null) avsClip.AviSynthInvoke(avsClip.GetAVS(), 0, "LoadPlugin", false, vsf); switch (OpenSourceType) { case VideoSourceType.FFVideoSource: avsClip.AviSynthInvoke(avsClip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "ffms2.dll")); break; case VideoSourceType.DirectShowSource: avsClip.AviSynthInvoke(avsClip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "DirectShowSource.dll")); break; case VideoSourceType.DSS2: avsClip.AviSynthInvoke(avsClip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "avss.dll")); break; } avsClip.AviSynthInvoke(avsClip.GetAVS(), 0, OpenSourceType.ToString(), false, fname); avsClip.AviSynthInvoke(avsClip.GetAVS(), 0, "killaudio", false, "Nulo"); avsClip.AviSynthInvoke(avsClip.GetAVS(), 0, "converttorgb32", false, "Nulo"); avsClip.AviSynthInvoke(avsClip.GetAVS(), 1, OpenSourceType.ToString(), false, fname); avsClip.AviSynthInvoke(avsClip.GetAVS(), 1, "killaudio", false, "Nulo"); avsClip.AviSynthInvoke(avsClip.GetAVS(), 1, "converttorgb32", false, "Nulo"); try { if (OpenAudioSourceType != AudioSourceType.None) { switch (OpenAudioSourceType) { case AudioSourceType.FFAudioSource: avsaudio.AviSynthInvoke(avsaudio.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "ffms2.dll")); break; case AudioSourceType.DirectShowSource: avsaudio.AviSynthInvoke(avsaudio.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "DirectShowSource.dll")); break; } avsaudio.AviSynthInvoke(avsaudio.GetAVS(), 0, OpenAudioSourceType.ToString(), false, fname); avsaudio.AviSynthInvoke(avsaudio.GetAVS(), 0, "killvideo", false, "Nulo"); } } catch { } updatePreviewAVS(); } catch (AviSynthException x) { errorMsg("No se puede entrar en el modo AviSynth. Comprueba que tienes instalado el AviSynth, que tienes registrado el VSFilter.dll (o mételo en la carpeta \\plugins del directorio de AviSynth), y que no intentas abrir nada raro.\nMensaje de error : " + x.Message); return; } isVideoLoaded = true; butClip.Enabled = true; updateMenuEnables(); videoInfo.Resolution = new Size(avsClip.VideoWidth, avsClip.VideoHeight); videoInfo.FrameTotal = avsClip.num_frames; setStatus("Vídeo " + fname + " cargado. [AviSynth (V: " + OpenSourceType.ToString() + ", A:" + OpenAudioSourceType.ToString() + ")]"); script.GetHeader().SetHeaderValue("Video File", fname); if (isKeyframeGuessNeeded()) KeyframeGuess(false); } }
private VideoSourceType GetVideoSourceFilter(string filename) { bool AviSourceCompatible = filename.EndsWith(".avi", StringComparison.InvariantCultureIgnoreCase) || filename.EndsWith(".divx", StringComparison.InvariantCultureIgnoreCase) || filename.EndsWith(".xvid", StringComparison.InvariantCultureIgnoreCase); bool ImportCompatible = filename.EndsWith(".avs", StringComparison.InvariantCultureIgnoreCase) || filename.EndsWith(".avsi", StringComparison.InvariantCultureIgnoreCase); AviSynthClip avsclip = null, avsclip_test; AviSynthScriptEnvironment avsenv, avsenv_test; avsenv_test = new AviSynthScriptEnvironment(); avsclip_test = avsenv_test.ParseScript("BlankClip"); avsclip_test.AviSynthInvoke(avsclip_test.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "ffms2.dll")); avsclip_test.AviSynthInvoke(avsclip_test.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "DirectShowSource.dll")); avsclip_test.AviSynthInvoke(avsclip_test.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "avss.dll")); foreach (string sfilter in VideoFilterPriority) //Enum.GetNames(typeof(VideoSourceType)) { if (sfilter.Equals(VideoSourceType.AviSource.ToString())) { if (AviSourceCompatible) // avisource es un core filter, existe siempre. { try { avsenv = new AviSynthScriptEnvironment(); avsclip = avsenv.ParseScript("AviSource(\"" + filename + "\")"); avsclip.cleanup(true); avsclip_test.cleanup(true); return VideoSourceType.AviSource; } catch { if (avsclip != null) avsclip.cleanup(true); } } } else if (sfilter.Equals(VideoSourceType.Import.ToString())) { if (ImportCompatible) { try { avsenv = new AviSynthScriptEnvironment(); avsclip = avsenv.ParseScript("Import(\"" + filename + "\")"); avsclip.cleanup(true); avsclip_test.cleanup(true); return VideoSourceType.Import; } catch { if (avsclip != null) avsclip.cleanup(true); } } } else { bool isFFMS2 = sfilter.Equals(VideoSourceType.FFVideoSource.ToString()); bool isDSS = sfilter.Equals(VideoSourceType.DirectShowSource.ToString()); bool isDSS2 = sfilter.Equals(VideoSourceType.DSS2.ToString()); try { if (avsclip_test.FuncExists(avsclip_test.GetAVS(), sfilter))// || isFFMS2) { avsenv = new AviSynthScriptEnvironment(); avsclip = avsenv.ParseScript("BlankClip"); if (isFFMS2) { avsclip.AviSynthInvoke(avsclip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "ffms2.dll")); CheckIndexFile(filename); } if (isDSS) avsclip.AviSynthInvoke(avsclip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "DirectShowSource.dll")); if (isDSS2) avsclip.AviSynthInvoke(avsclip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "avss.dll")); //avsclip = avsenv.ParseScript(sfilter + "(\"" + filename + "\")"); avsclip.AviSynthInvoke(avsclip.GetAVS(), 0, sfilter, false, filename); avsclip.cleanup(true); avsclip_test.cleanup(true); return (VideoSourceType)Enum.Parse(typeof(VideoSourceType), sfilter); } else errorMsg("No encontrada la función ffvideosource"); } catch { if (avsclip != null) avsclip.cleanup(true); } } } if (avsclip != null) avsclip.cleanup(true); avsclip_test.cleanup(true); throw new AviSynthException("Imposible cargar el vídeo en modo AviSynth."); return VideoSourceType.AviSource; // codigo inalcanzable }
private AudioSourceType GetAudioSourceFilter(string filename) { bool AviSourceCompatible = filename.EndsWith(".avi", StringComparison.InvariantCultureIgnoreCase) || filename.EndsWith(".divx", StringComparison.InvariantCultureIgnoreCase) || filename.EndsWith(".xvid", StringComparison.InvariantCultureIgnoreCase); bool ImportCompatible = filename.EndsWith(".avs", StringComparison.InvariantCultureIgnoreCase) || filename.EndsWith(".avsi", StringComparison.InvariantCultureIgnoreCase); bool WavSourceCompatible = filename.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase); AviSynthClip avsclip = null, avsclip_test; AviSynthScriptEnvironment avsenv, avsenv_test; avsenv_test = new AviSynthScriptEnvironment(); avsclip_test = avsenv_test.ParseScript("BlankClip"); avsclip_test.AviSynthInvoke(avsclip_test.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "ffms2.dll")); avsclip_test.AviSynthInvoke(avsclip_test.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "DirectShowSource.dll")); avsclip_test.AviSynthInvoke(avsclip_test.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "avss.dll")); foreach (string sfilter in AudioFilterPriority)//Enum.GetNames(typeof(AudioSourceType))) { if (sfilter.Equals(AudioSourceType.AviSource.ToString())) { if (AviSourceCompatible) // avisource es un core filter, existe siempre. { try { avsenv = new AviSynthScriptEnvironment(); avsclip = avsenv.ParseScript("AviSource(\"" + filename + "\")"); if (avsclip.SamplesCount <= 0) { avsclip.cleanup(true); avsclip_test.cleanup(true); throw new AviSynthException("No puede abrirse un audio sin samples."); } avsclip.cleanup(true); avsclip_test.cleanup(true); return AudioSourceType.AviSource; } catch { if (avsclip != null) avsclip.cleanup(true); } } } else if (sfilter.Equals(AudioSourceType.Import.ToString())) { if (ImportCompatible) { try { avsenv = new AviSynthScriptEnvironment(); avsclip = avsenv.ParseScript("Import(\"" + filename + "\")"); if (avsclip.SamplesCount <= 0) { avsclip.cleanup(true); avsclip_test.cleanup(true); throw new AviSynthException("No puede abrirse un audio sin samples."); } avsclip.cleanup(true); avsclip_test.cleanup(true); return AudioSourceType.Import; } catch { if (avsclip != null) avsclip.cleanup(true); } } } else { bool isFFMS2 = sfilter.Equals(AudioSourceType.FFAudioSource.ToString()); bool isDSS = sfilter.Equals(AudioSourceType.DirectShowSource.ToString()); bool isWS = sfilter.Equals(AudioSourceType.WavSource.ToString()); try { if (!isWS || (isWS && WavSourceCompatible)) { if (avsclip_test.FuncExists(avsclip_test.GetAVS(), sfilter)) { avsenv = new AviSynthScriptEnvironment(); avsclip = avsenv.ParseScript("BlankClip"); if (isFFMS2) { avsclip.AviSynthInvoke(avsclip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "ffms2.dll")); CheckIndexFile(filename); } if (isDSS) avsclip.AviSynthInvoke(avsclip.GetAVS(), 0, "LoadPlugin", false, Path.Combine(Application.StartupPath, "DirectShowSource.dll")); avsclip.AviSynthInvoke(avsclip.GetAVS(), 0, sfilter, false, filename); if (avsclip.SamplesCount <= 0) { avsclip.cleanup(true); avsclip_test.cleanup(true); throw new AviSynthException("No puede abrirse un audio sin samples."); } else { avsclip.cleanup(true); avsclip_test.cleanup(true); return (AudioSourceType) Enum.Parse(typeof (AudioSourceType), sfilter); } } } } catch { if (avsclip != null) avsclip.cleanup(true); } } } if (avsclip != null) avsclip.cleanup(true); if (avsclip_test != null) avsclip_test.cleanup(true); return AudioSourceType.None; // codigo inalcanzable }