private void ThreadMakeFilmGif(VideoFile input) { OutputPackage oo = MakeFilmGif(input); MadeFilmGif?.Invoke(this, oo); }
/// <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); }
/// <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 MakeGif(VideoFile input, int num) { if (!input.infoGathered) { GetVideoInfo(input); } OutputPackage ou = new OutputPackage(); //double secs; //divide the duration in 3 to get a preview image in the middle of the clip //instead of a black image from the beginning. //secs = Math.Round(TimeSpan.FromTicks(input.Duration.Ticks / (num - 1)).TotalSeconds, 0); //double res = Math.Round(1 / secs, 4); //string valor = res.ToString().Replace(",", "."); //set up the parameters for getting a previewimage string filesearch = System.Guid.NewGuid().ToString(); string filename = $"{filesearch}%03d.png"; string finalpath = Path.Combine(Path.Combine(Path.GetDirectoryName(input.Path), "Thumbails"), filename); string Params = $"-y -i \"{input.Path}\" -vf scale=220:-1,fps=1/{num} \"{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; string videodir = Path.GetDirectoryName(input.Path); string videoname = Path.GetFileName(input.Path); string outfilegif = Path.Combine(Path.Combine(videodir, "Thumbails"), videoname); //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 {FrameRate} -i \"{finalpath}\" \"{outfilegif}_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($"{outfilegif}_thumbs_0000.gif")) { ou.VideoStream = LoadMemoryStreamFromFile($"{outfilegif}_thumbs_0000.gif"); } proc.Close(); //proc.Dispose(); } catch (Exception ex) { Debug.WriteLine(ex.Message); //output = string.Empty; } //Thread.Sleep(2000); /////// string[] files = Directory.GetFiles(Path.GetDirectoryName(outfilegif), $"{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 {outfilegif}_thumbs_0000.gif from {input.Path}"); return(ou); }
public void MakeFilmGifThread(VideoFile input) { t = Task.Factory.StartNew(() => ThreadMakeFilmGif(input)); }
public void ThreadMakeGif(VideoFile input, int num) { OutputPackage pack = MakeGif(input, num); MadeFilmGif?.Invoke(this, pack); }
public void MakeGifThread(VideoFile input, int num) { t = Task.Factory.StartNew(() => ThreadMakeGif(input, num)); }
public OutputPackage StrackImages(VideoFile input, int num) { if (!input.infoGathered) { GetVideoInfo(input); } OutputPackage ou = new OutputPackage(); double secs; //divide the duration in 3 to get a preview image in the middle of the clip //instead of a black image from the beginning. secs = Math.Round(TimeSpan.FromTicks(input.Duration.Ticks / (num - 1)).TotalSeconds, 0); double res = Math.Round(1 / secs, 4); string valor = res.ToString().Replace(",", "."); //set up the parameters for getting a previewimage //string filesearch = "\"%d thrumb\"";//System.Guid.NewGuid().ToString(); string filename = "%d.jpg"; string finalpath = Path.Combine(this.WorkingPath, filename); string Params = $"-y -i \"{input.Path}\" -vf fps={valor} \"{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(); proc.Close(); //proc.Dispose(); } catch (Exception ex) { Debug.WriteLine(ex.Message); //output = string.Empty; } Thread.Sleep(2000); /////// string[] files = Directory.GetFiles(this.WorkingPath, $"*.jpg"); //Array.Sort(files, StringComparer.Ordinal); 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); } } //if (File.Exists(finalpath)) //{ // //ou.PreviewImage = LoadImageFromFile(finalpath); // ou.ListImage.Add(LoadImageFromFile(finalpath)); // try // { // File.Delete(finalpath); // } // catch (Exception) { } //} Debug.WriteLine("fin de proceso de extraccion"); return(ou); }
public OutputPackage ConvertToFLV(VideoFile input) { if (!input.infoGathered) { GetVideoInfo(input); } OutputPackage ou = new OutputPackage(); //set up the parameters for getting a previewimage string filename = System.Guid.NewGuid().ToString() + ".jpg"; int secs; //divide the duration in 3 to get a preview image in the middle of the clip //instead of a black image from the beginning. secs = (int)Math.Round(TimeSpan.FromTicks(input.Duration.Ticks / 3).TotalSeconds, 0); string finalpath = Path.Combine(this.WorkingPath, filename); string Params = string.Format("-i \"{0}\" \"{1}\" -vcodec mjpeg -ss {2} -vframes 1 -an -f rawvideo", input.Path, finalpath, secs); string output = RunProcess(Params); ou.RawOutput = output; if (File.Exists(finalpath)) { ou.PreviewImage = LoadImageFromFile(finalpath); try { File.Delete(finalpath); } catch (Exception) { } } else { //try running again at frame 1 to get something Params = string.Format("-y -i \"{0}\" \"{1}\" -vcodec mjpeg -ss {2} -vframes 1 -an -f rawvideo", input.Path, finalpath, 1); output = RunProcess(Params); ou.RawOutput = output; if (File.Exists(finalpath)) { ou.PreviewImage = LoadImageFromFile(finalpath); try { File.Delete(finalpath); } catch (Exception) { } } } //-ar 22050 -f flv (o) -y -ar 22050 -ab 64 -f flv /* filename = System.Guid.NewGuid().ToString() + ".flv"; * finalpath = Path.Combine(this.WorkingPath, filename); * Params = string.Format("-i \"{0}\" -ar 22050 -qscale 4 -s 380x284 -f flv \"{1}\"", input.Path, finalpath); * output = RunProcess(Params); * * if (File.Exists(finalpath)) * { * ou.VideoStream = LoadMemoryStreamFromFile(finalpath); * try * { * File.Delete(finalpath); * } * catch (Exception) { } * } */ return(ou); }
public static void GetVideoInfo(VideoFile input) { string video = $"\"{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; }