Beispiel #1
0
        public OutputPackage ConvertToFLV(MemoryStream inputFile, string Filename)
        {
            string     tempfile = System.IO.Path.Combine(this.WorkingPath, System.Guid.NewGuid().ToString() + System.IO.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);
        }
Beispiel #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(videoFilePath.Text))
            {
                OutputPackage op = ffmpegConverter.ConvertToFLV(videoFilePath.Text);

                resultsTextbox.Text += videoFilePath.Text + " conversion to flv  " + op.Success + "\n";
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public bool ExtractAudio(string inputPath)
        {
            VideoFile input = null;

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

            if (!input.infoGathered)
            {
                GetVideoInfo(input);
            }

            OutputPackage ou = new OutputPackage();


            String filename = System.Guid.NewGuid().ToString() + ".wav";

            String finalpath = System.IO.Path.Combine(this.WorkingPath, filename);

            String Params = string.Format("-i {0} {1}", input.Path, finalpath);
            String output = RunProcess(Params);

            bool returnVal = false;

            if (File.Exists(finalpath))
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }

            return(returnVal);
        }
Beispiel #5
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 = System.IO.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("-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) { }
                }
            }

            filename = System.Guid.NewGuid().ToString() + ".flv";

            finalpath = System.IO.Path.Combine(this.WorkingPath, filename);

            Params = string.Format("-i {0} -y -ar 22050 -ab 64 -f flv {1}", input.Path, finalpath);
            output = RunProcess(Params);

            if (File.Exists(finalpath))
            {
                ou.VideoStream = LoadMemoryStreamFromFile(finalpath);
                ou.Success     = true;
                try
                {
                    //File.Delete(finalpath);
                }
                catch (Exception) { }
            }
            else
            {
                ou.Success = false;
            }
            return(ou);
        }