Example #1
0
        /// <summary>
        /// make a OutputPackage with a MemoryStream of video and only
        /// a name de file with extension without path complete.
        /// </summary>
        /// <param name="inputFile">MemoryStream file video</param>
        /// <param name="Filename">only name file to save temporali without path</param>
        /// <returns></returns>
        public OutputPackage ConvertToFLV(MemoryStream inputFile, string Filename)
        {
            string     tempfile = Path.Combine(Temp, 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 new ConvertException(ex.ToString());
            }

            OutputPackage oo = ConvertToFLV(vf);

            //borra el fichero final.
            try {
                File.Delete(tempfile);
            } catch (Exception) {
            }

            return(oo);
        }
Example #2
0
        /// <summary>
        /// Retorna un OutPutPackage con un Memorystream, con el fichero .flv
        /// </summary>
        /// <param name="input">VideoFile info of video</param>
        /// <returns></returns>
        public OutputPackage ConvertToFLV(VideoFile input)
        {
            //si no tiene informacion, obtenerla
            if (!input.infoGathered)
            {
                GetVideoInfo(input);
            }
            OutputPackage ou = new OutputPackage();

            //set up the parameters for getting a previewimage
            string filename = System.Guid.NewGuid().ToString() + ".flv";

            string finalpath = Path.Combine(Temp, filename);
            string Params    = string.Format("-i \"{0}\" -ar 22050 -vf scale=230:-1 -f flv \"{1}\"", input.Path, finalpath);

            //-ar 22050 -f flv (o) -y -ar 22050 -ab 64 -f flv
            Debug.WriteLine("ConvertToFLV, Params:=> {0}" + Params);
            OnlyRunProcess(Params);

            if (File.Exists(finalpath))
            {
                ou.VideoStream = LoadMemoryStreamFromFile(finalpath);
                try {
                    File.Delete(finalpath);
                } catch (Exception ex) {
                    throw new ConvertException(ex.ToString());
                }
            }
            else
            {
                throw new ConvertException("No se pudo crear el fichero de video .flv");
            }
            return(ou);
        }
Example #3
0
        /// <summary>
        /// devuelve true si carga la imagen sin problemas
        /// </summary>
        /// <returns></returns>
        public bool loadImagen()
        {
            bool res = false;

            if (File.Exists(textBoxfile.Text))
            {
                trackBar.Enabled = false;
                t = Task.Factory.StartNew(new Action(() => {
                    videofile  = conv.GetVideoInfo(textBoxfile.Text);
                    outputpack = conv.StrackImages(videofile, 1);
                    if (InvokeRequired)
                    {
                        Invoke(new Action(() => {
                            trackBar.Maximum = videofile.DurationMs - 1;
                            trackBar.Enabled = true;
                            btnRun.Enabled   = true;
                        }));
                    }
                }));
                pictureBox.Image = conv.getImage(textBoxfile.Text);
                //pictureBox.Image = conv.getImage(videofile);
                ShowDataFromVideofile();
                res = true;
                return(res);
            }
            return(res);
        }
Example #4
0
        private void ThreadMakeFilmGif(VideoFile input)
        {
            OutputPackage oo = MakeFilmGif(input);

            if (MadeFilmGif != null)
            {
                MadeFilmGif(this, oo);
            }
            //MadeFilmGif?.Invoke(this, oo);
        }
Example #5
0
        public void ThreadMakeGif(VideoFile input, int num)
        {
            OutputPackage pack = MakeGif(input, num);

            if (MadeFilmGif != null)
            {
                MadeFilmGif(this, pack);
            }
            //MadeFilmGif?.Invoke(this, pack);
        }
Example #6
0
        public void ThreadMakeGif(string inputpath, int num)
        {
            OutputPackage pack = MakeGif(inputpath, num);

            if (MadeFilmGif != null)
            {
                MadeFilmGif(this, pack);
            }
            //MadeFilmGif?.Invoke(this, pack);
        }
Example #7
0
        void BtnConvertClick(object sender, EventArgs e)
        {
            OutputPackage package = conv.ConvertToFLV(videofile);

            outputpack.VideoStream = package.VideoStream;
            string filename = Path.Combine(Environment.CurrentDirectory,
                                           string.Format("{0}.flv", System.Guid.NewGuid().ToString()));

            Converter.SaveMemoryStreamToFile(outputpack.VideoStream, filename);
            Debug.WriteLine("Name-File:=> " + filename);
            textBoxdatos.Text += newline + "Convert file: => " + filename + Environment.NewLine;
            btnConvert.Enabled = false;
        }
Example #8
0
 private void Conv_MadeFilmGif(object sender, OutputPackage package)
 {
     if (InvokeRequired)
     {
         Invoke(new Action(() => {
             btnmakeGif.Enabled = true;
             outputpack.ListImage.Add((Image)package.PreviewImage.Clone());
             pictureBox.Image   = (Image)package.PreviewImage.Clone();
             textBoxdatos.Text += newline + "Make-gif from file: => " +
                                  Path.GetFileName(videofile.Path) + Environment.NewLine;
         }));
     }
 }
Example #9
0
        /// <summary>
        /// Make a Gif animate with framerate num.
        /// one image for second.
        /// </summary>
        /// <param name="input">VideoFile data input</param>
        /// <param name="num">frames for each second</param>
        /// <returns></returns>
        public OutputPackage MakeGif(VideoFile input, int num)
        {
            if (!input.infoGathered)
            {
                GetVideoInfo(input);
            }
            OutputPackage ou = new OutputPackage();

            string filesearch = System.Guid.NewGuid().ToString();
            string filename   = filesearch + "%04d.png";
            string dirwork    = Path.Combine(Path.GetDirectoryName(input.Path), "Thumbails"); //directorio de trabajo.

            //comprobar que existe: si no crearlo.
            if (!Directory.Exists(dirwork))
            {
                Directory.CreateDirectory(dirwork);                             //lo creamos.
            }
            string finalpath = Path.Combine(Path.Combine(Path.GetDirectoryName(input.Path), "Thumbails"), filename);
            string Params    = String.Format("-y -i \"{0}\" -vf scale=220:-1,fps=1/{1} \"{2}\"", input.Path, num, finalpath);

            Debug.WriteLine(Params);
            OnlyRunProcess(Params);
            string videodir   = Path.GetDirectoryName(input.Path);
            string videoname  = Path.GetFileName(input.Path);
            string outfilegif = Path.Combine(Path.Combine(videodir, "Thumbails"), videoname);

            //ahora montamos el gif con las imagenes creadas en fichero.
            Params = String.Format("-y -framerate {0} -i \"{1}\"  \"{2}_thumbs_0000.gif\"", FrameRate, finalpath, outfilegif);
            Debug.WriteLine(Params);
            OnlyRunProcess(Params);
            //load image gif from file.
            if (File.Exists(outfilegif + "_thumbs_0000.gif"))
            {
                ou.PreviewImage = LoadImageFromFile(outfilegif + "_thumbs_0000.gif");
            }


            string[] files = Directory.GetFiles(Path.GetDirectoryName(outfilegif), filesearch + "*.png");
            //delete the files images.
            foreach (var file in files)
            {
                try {
                    File.Delete(file);
                } catch (Exception ex) {
                    Debug.WriteLine(ex.Message);
                }
            }

            Debug.WriteLine(String.Format("create gif {0}_thumbs_0000.gif from {1}", outfilegif, input.Path));
            return(ou);
        }
Example #10
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);
        }
Example #11
0
        public OutputPackage StrackImages(string inputpath, int num)
        {
            VideoFile vf = null;

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

            OutputPackage oo = StrackImages(vf, num);

            return(oo);
        }
Example #12
0
        /// <summary>
        /// return OutputPackage.
        /// </summary>
        /// <param name="inputPath">path complet of file video</param>
        /// <returns></returns>
        public OutputPackage ConvertToFLV(string inputPath)
        {
            VideoFile vf = null;

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

            OutputPackage oo = ConvertToFLV(vf);

            return(oo);
        }
Example #13
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);

            if (MadeFilmGif != null)
            {
                MadeFilmGif(this, oo);
            }
            //MadeFilmGif?.Invoke(this, oo);
        }
Example #14
0
        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);
        }
Example #15
0
        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++;
            }
        }
Example #16
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);
        }