Exemple #1
0
        public OutputPackage ConvertToFLV(MemoryStream inputFile, string Filename)
        {
            string     tempfile = Path.Combine(this.WorkingPath, System.Guid.NewGuid().ToString() + Path.GetExtension(Filename));
            FileStream fs       = File.Create(tempfile);

            inputFile.WriteTo(fs);
            fs.Flush();
            fs.Close();
            GC.Collect();

            VideoFile vf = null;

            try
            {
                vf = new VideoFile(tempfile);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            OutputPackage oo = ConvertToFLV(vf);

            try
            {
                File.Delete(tempfile);
            }
            catch (Exception)
            {
            }

            return(oo);
        }
Exemple #2
0
        public OutputPackage MakeFilmGif(string inputpath)
        {
            VideoFile vf = null;

            try
            {
                vf = new VideoFile(inputpath);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            OutputPackage oo = MakeFilmGif(vf);

            return(oo);
        }
Exemple #3
0
        private void ThreadMakeFilmGif(string inputpath)
        {
            VideoFile vf = null;

            try
            {
                vf = new VideoFile(inputpath);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            OutputPackage oo = MakeFilmGif(vf);

            MadeFilmGif?.Invoke(this, oo);
        }
Exemple #4
0
        public OutputPackage StrackImages(string inputpath, int num)
        {
            VideoFile vf = null;

            try
            {
                vf = new VideoFile(inputpath);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            OutputPackage oo = StrackImages(vf, num);

            return(oo);
        }
Exemple #5
0
        public OutputPackage ConvertToFLV(string inputPath)
        {
            VideoFile vf = null;

            try
            {
                vf = new VideoFile(inputPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            OutputPackage oo = ConvertToFLV(vf);

            return(oo);
        }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        private void ThreadMakeFilmGif(VideoFile input)
        {
            OutputPackage oo = MakeFilmGif(input);

            MadeFilmGif?.Invoke(this, oo);
        }
Exemple #8
0
        /// <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.GetDirectoryName(input.Path), 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;

            //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}\"  \"{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($"{input.Path}_thumbs_0000.gif"))
                {
                    ou.VideoStream = LoadMemoryStreamFromFile($"{input.Path}_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(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 {input.Path}_thumbs_0000.gif from {input.Path}");
            return(ou);
        }
Exemple #9
0
        private void ThreadMakeGif(VideoFile input, int num)
        {
            OutputPackage pack = MakeGif(input, num);

            MadeFilmGif?.Invoke(this, pack);
        }
Exemple #10
0
        private void ThreadMakeGif(string inputpath, int num)
        {
            OutputPackage pack = MakeGif(inputpath, num);

            MadeFilmGif?.Invoke(this, pack);
        }
Exemple #11
0
        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  = "tmp-%d.jpg";
            string pathdir   = Path.GetDirectoryName(input.Path);
            string finalpath = Path.Combine(pathdir, 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(finalpath, $"tmp-*.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);
        }
Exemple #12
0
        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);
        }