private void ThreadMakeFilmGif(string inputpath) { VideoFile vf = null; try { vf = new VideoFile(inputpath); } catch (Exception ex) { Debug.WriteLine(ex.Message); } OutputPackage oo = MakeFilmGif(vf); if (MadeFilmGif != null) { MadeFilmGif(this, oo); } //MadeFilmGif?.Invoke(this, oo); }
public OutputPackage StrackImages(VideoFile input, int num) { if (!input.infoGathered) { GetVideoInfo(input); } OutputPackage ou = new OutputPackage(); string temp = Path.GetTempPath(); Debug.WriteLine(temp); int valor = input.DurationMs / (num + 1); //esto es en segundos. if (valor <= 0) { valor = 60; } string fil = System.Guid.NewGuid().ToString(); string filename = fil + "%04d.jpg"; string finalpath = Path.Combine(temp, filename); string Params = String.Format("-ss {1} -i \"{0}\" -vf fps=1/{1} -vframes {2} \"{3}\" -hide_banner", input.Path, valor, num, finalpath); Debug.WriteLine(Params); OnlyRunProcess(Params); string[] files = Directory.GetFiles(temp, fil + "*.jpg"); if (files != null) { Array.Sort(files, CompareDinosByLength); } foreach (var file in files) { ou.ListImage.Add(LoadImageFromFile(file)); try { File.Delete(file); } catch (Exception ex) { Debug.WriteLine(ex.Message); throw new ConvertException(ex.ToString()); } } Debug.WriteLine("fin de proceso de extraccion"); return(ou); }
public void TreadShowImagens(CancellationTokenSource cs) { int minimo = 1; int maximo = trackBar.Maximum; VideoFile video = videofile; OutputPackage outpackge = outputpack; while (minimo < maximo) { cs.Token.ThrowIfCancellationRequested();//cancelamos si es requerido Image img = conv.getImage(video, minimo); if (InvokeRequired) { Invoke(new Action(() => pictureBox.Image = img)); Invoke(new Action(() => trackBar.Value = minimo)); //da error x doble llamada } Thread.Sleep(10); minimo++; } }
/// <summary> /// Make a Gif animate with framerate 1. /// one image for second. /// </summary> /// <param name="input">VideoFile data input</param> /// <param name="num">one frame for each second</param> /// <returns></returns> public OutputPackage MakeFilmGif(VideoFile input) { if (!input.infoGathered) { GetVideoInfo(input); } OutputPackage ou = new OutputPackage(); //set up the parameters for getting a previewimage //string filesearch = System.Guid.NewGuid().ToString(); string filename = $"{input.Path}_thumbs_0000.gif"; string finalpath = filename; string Params = $"-y -i \"{input.Path}\" -vf scale=220:-1 \"{finalpath}\""; Debug.WriteLine(Params); //string output = RunProcess(Params); //ou.RawOutput = output; //// //create a process info string ffexe = $"\"{FFExe}\""; ProcessStartInfo oInfo = new ProcessStartInfo(ffexe, Params); oInfo.UseShellExecute = false; oInfo.CreateNoWindow = true; oInfo.RedirectStandardOutput = false; oInfo.RedirectStandardError = false; //Create the output and streamreader to get the output //string output = null; StreamReader srOutput = null; //try the process try { //run the process Process proc = System.Diagnostics.Process.Start(oInfo); proc.WaitForExit(); //get the output //srOutput = proc.StandardError; //now put it in a string //output = srOutput.ReadToEnd(); //ahora montamos el gif con las imagenes creadas en fichero. //Params = $"-y -framerate 1 -i \"{finalpath}\" \"{input.Path}_thumbs_0000.gif\""; //oInfo = new ProcessStartInfo(ffexe, Params); //oInfo.UseShellExecute = false; //oInfo.CreateNoWindow = true; //oInfo.RedirectStandardOutput = false; //oInfo.RedirectStandardError = false; //proc = System.Diagnostics.Process.Start(oInfo); //proc.WaitForExit(); if (File.Exists(finalpath)) { ou.VideoStream = LoadMemoryStreamFromFile(finalpath); } proc.Close(); //proc.Dispose(); } catch (Exception ex) { Debug.WriteLine(ex.Message); //output = string.Empty; } //Thread.Sleep(2000); // //string[] files = Directory.GetFiles(Path.GetDirectoryName(input.Path), $"{filesearch}*.png"); // //Array.Sort(files, CompareDinosByLength); //foreach (var file in files) //{ // try // { // File.Delete(file); // } // catch (Exception ex) // { // Debug.WriteLine(ex.Message); // } //} //if (File.Exists(finalpath)) //{ // //ou.PreviewImage = LoadImageFromFile(finalpath); // ou.ListImage.Add(LoadImageFromFile(finalpath)); // try // { // File.Delete(finalpath); // } // catch (Exception) { } //} Debug.WriteLine("create gif {finalpath} from {input.Path}"); //MadeFilmGif?.Invoke(this, ou); return(ou); }
public void MakeFilmGifThread(VideoFile input) { t = Task.Factory.StartNew(() => ThreadMakeFilmGif(input)); }
public void MakeGifThread(VideoFile input, int num) { t = Task.Factory.StartNew(() => ThreadMakeGif(input, num)); }
/// <summary> /// Pasando un VideoFile Info, creado solo con la ruta completa /// del fichero, realiza proceso para rrellenar con la informacion /// el objeto VideoFile, que pone a true su variable infoGathered /// </summary> /// <param name="input">VideoFile</param> public void GetVideoInfo(VideoFile input) { //la ruta del fichero de imagen string video = String.Format("\"{0}\"", input.Path); //set up the parameters for video info string Params = string.Format("-i {0}", video); string output = RunProcess(Params); input.RawInfo = output; //get duration Regex re = new Regex("[D|d]uration:.((\\d|:|\\.)*)"); Match m = re.Match(input.RawInfo); if (m.Success) { string duration = m.Groups[1].Value; string[] timepieces = duration.Split(new char[] { ':', '.' }); if (timepieces.Length == 4) { input.Duration = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3])); } } //get audio bit rate re = new Regex("[B|b]itrate:.((\\d|:)*)"); m = re.Match(input.RawInfo); double kb = 0.0; if (m.Success) { Double.TryParse(m.Groups[1].Value, out kb); } input.BitRate = kb; //get the audio format re = new Regex("[A|a]udio:.*"); m = re.Match(input.RawInfo); if (m.Success) { input.AudioFormat = m.Value; } //get the video format re = new Regex("[V|v]ideo:.*"); m = re.Match(input.RawInfo); if (m.Success) { input.VideoFormat = m.Value; } //get the video format re = new Regex("(\\d{2,3})x(\\d{2,3})"); m = re.Match(input.RawInfo); if (m.Success) { int width = 0; int height = 0; int.TryParse(m.Groups[1].Value, out width); int.TryParse(m.Groups[2].Value, out height); input.Width = width; input.Height = height; } input.infoGathered = true; }