Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        /// <summary>
        /// If file is video, then convert it to FLV,
        /// delete the original file, update the database
        /// with new flv's attributes
        /// </summary>
        /// <param name="fileId"></param>
        /// <returns>Returns the file's full path</returns>
        void IfVideoConvertToFLV(long fileId)
        {
            try
            {
                //Get the file from DB
                awFile file = (from l in _context.awFiles
                               where l.fileId.Equals(fileId)
                               select l).FirstOrDefault();
                if (file == null)
                {
                    return;
                }

                string extension = GetFileExension(file.path);
                string path      = file.path;

                //Only Video Files, (flv won't be converted)
                if (!_videoLib.isVideoFile(extension))
                {
                    return;
                }

                //CONVERT and GET THE NEW FILES LOCATION
                OutputPackage videoPackage = _videoLib.ConvertToFLV(path);

                //GET THE NEW FILES INFO
                file.contentSize = videoPackage.Length;
                file.contentType = GetContentType(AWAPI_BusinessLibrary.library.ConfigurationLibrary.Config.fileMimeXMLPath, "flv");

                SAVED_FILE savedFile = new SAVED_FILE();
                if (FileAmazonS3.SaveOnAmazonS3())
                {
                    //load the flv file into byte array, and save it to amazon s3
                    FileStream fileStream = new FileStream(videoPackage.Path, System.IO.FileMode.Open);

                    //SAVE THE VIDEO FILE
                    string keyName = String.Format("{0}/{1}.flv", file.siteId, file.fileId);

                    savedFile = SaveFile(file.siteId, false, file.contentType, keyName, fileStream, "");
                    System.IO.File.Delete(videoPackage.Path);
                    file.path = savedFile.filePath;

                    //SAVE THE THUMB
                    if (videoPackage.PreviewImage != null && !String.IsNullOrEmpty(videoPackage.PreviewImagePath) &&
                        System.IO.File.Exists(videoPackage.PreviewImagePath))
                    {
                        string     thumbFile          = String.Format("{0}/{1}.jpg", file.siteId, file.fileId);
                        FileStream videoPreviewStream = new FileStream(videoPackage.PreviewImagePath, System.IO.FileMode.Open);
                        savedFile      = SaveFile(file.siteId, false, "image/jpeg", thumbFile, videoPreviewStream, "");
                        file.thumbnail = savedFile.filePath;

                        if (System.IO.File.Exists(videoPackage.PreviewImagePath))
                        {
                            System.IO.File.Delete(videoPackage.PreviewImagePath);
                        }
                    }
                    file.isOnLocal = false;
                }
                else
                {
                    file.isOnLocal = true;
                    file.path      = videoPackage.Path;
                    file.thumbnail = videoPackage.PreviewImagePath;
                }

                _context.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
        public OutputPackage ConvertToFLV(VideoFile input)
        {
            if (!input.infoGathered)
            {
                GetVideoInfo(input);
            }
            OutputPackage ou = new OutputPackage();

            string sourceExtension        = GetFileExension(input.Path);
            string sourceWithoutExtension = input.Path.Replace("." + sourceExtension, "");

            //GET PREVIEW IMAGE ---------------------------------------
            string previewPath   = sourceWithoutExtension + ".jpg";
            string processParams = string.Format(" -i \"{0}\" -f mjpeg -t 0.001 -ss 5 -y \"{1}\" ", input.Path, previewPath);
            string output        = RunProcess(processParams);

            ou.RawOutput = output;

            if (File.Exists(previewPath))
            {
                ou.PreviewImage     = LoadImageFromFile(previewPath);
                ou.PreviewImagePath = previewPath;
            }
            else
            { //try running again at frame 1 to get something
                processParams = string.Format("-i \"{0}\" \"{1}\" -vcodec mjpeg -ss {2} -vframes 1 -an -f rawvideo", input.Path, previewPath, 1);
                output        = RunProcess(processParams);

                ou.RawOutput = output;

                if (File.Exists(previewPath))
                {
                    ou.PreviewImage     = LoadImageFromFile(previewPath);
                    ou.PreviewImagePath = previewPath;
                }
            }

            //CONVERT THE FILE --------------------------------------------------------------------------------
            if (sourceExtension == "flv")
            {
                ou.Path   = input.Path;
                ou.Length = 0;

                byte[]       fileBytes = File.ReadAllBytes(input.Path);
                MemoryStream mems      = new MemoryStream(fileBytes);
                ou.VideoStream = mems;
                ou.Length      = (int)ou.VideoStream.Length;
            }
            else
            {
                string flvPath = sourceWithoutExtension + ".flv";
                //processParams = string.Format("-i {0} -s 480x360 -y -ar 44100 -ab 64 -f flv {1}", input.Path, flvPath);
                //string videoParam = "-b 512k -f flv -s 480x270 -vcodec libx264 -vpre hq";
                //string autidoParam = "-ar 44100 -ac 2 -ab 93k -acodec aac";
                // Params = String.Format("-i \"{0}\" {1} {2} -y \"{3}\"",
                // input.Path, videoParam, autidoParam, flvPath);

                //medium quality
                processParams = string.Format("-i \"{0}\" -acodec mp3 -ab 48k -ac 1 -ar 44100 -f flv -deinterlace -nr 500 -r 25 -b 270k -me_range 25 -i_qfactor 0.71 -g 500 \"{1}\" ",
                                              input.Path, flvPath);

                ////high quality
                //processParams = string.Format("-i \"{0}\" -acodec mp3 -ab 64k -ac 2 -ar 44100 -f flv -deinterlace -nr 500 -r 25 -b 650k -me_range 25 -i_qfactor 0.71 -g 500 \"{1}\"",
                //            input.Path, flvPath);


                Process proc = new Process();
                proc.StartInfo.Arguments              = processParams;
                proc.StartInfo.FileName               = this._ffExe;
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError  = true;

                proc.Start(); // start !
                proc.WaitForExit();

                //output = RunProcess(processParams);

                if (File.Exists(flvPath))
                {
                    ou.Path        = flvPath;
                    ou.VideoStream = LoadMemoryStreamFromFile(flvPath);
                    ou.Length      = (int)ou.VideoStream.Length;

                    try
                    {
                        File.Delete(input.Path);
                    }
                    catch (Exception) { }
                }
            }
            ou.Success = true;

            return(ou);
        }