{
      #region Properties
        private string _ffExe;
        {
            {
                return _ffExe;
            }
            {
                = value;
            }
        }
        private string _WorkingPath;
        {
            {
                return _WorkingPath;
            }
            {
                = value;
            }
        }
        #endregion
        #region Constructors
        public Converter() {
            Initialize();
        }
        public Converter(string ffmpegExePath) {
            = ffmpegExePath;
            Initialize();
        }
        #endregion
        #region Initialization
        private void Initialize() {
            //first make sure we have a value for the ffexe file setting
            (string.IsNullOrEmpty(_ffExe)) {
                object = ConfigurationManager.AppSettings["ffmpeg:ExeLocation"];
                ( == null) {
                    throw new Exception("Could not find the location of the ffmpeg exe file.  The path for ffmpeg.exe " +
                    "can be passed in via a constructor of the ffmpeg class (this class) or by setting in the app.config or web.config file.  " +
                    "in the appsettings section, the correct property name is: ffmpeg:ExeLocation");
                } {
                    (string.IsNullOrEmpty(o.ToString())) {
                        throw new Exception("No value was found in the app setting for ffmpeg:ExeLocation");
                    }
                    = o.ToString();
                }
            }
            //Now see if ffmpeg.exe exists
            string = GetWorkingFile();
            (string.IsNullOrEmpty(workingpath)) {
                //ffmpeg doesn't exist at the location stated.
                throw new Exception("Could not find a copy of ffmpeg.exe");
            }
            = workingpath;
            //now see if we have a temporary place to work
            (string.IsNullOrEmpty(_WorkingPath)) {
                object = ConfigurationManager.AppSettings["ffmpeg:WorkingPath"];
                ( != null) {
                    = o.ToString();
                } {
                    = string.Empty;
                }
            }
        }
        private string GetWorkingFile() {
            //try the stated directory
            (File.Exists(_ffExe)) {
                return _ffExe;
            }
            //oops, that didn't work, try the base directory
            (File.Exists(Path.GetFileName(_ffExe))) {
                return Path.GetFileName(_ffExe);
            }
            //well, now we are really unlucky, let's just return null
            return null;
        }
        #endregion
        #region Get the File without creating a file lock
        public static System.Drawing.Image LoadImageFromFile(string fileName) {
            System.Drawing.Image = null;
            (FileStream = new FileStream(fileName, FileMode.Open,
            FileAccess.Read)) {
                byte[] img;
                = new byte[fileStream.Length];
                fileStream.Read(img, 0, img.Length);
                fileStream.Close();
                = System.Drawing.Image.FromStream(new MemoryStream(img));
                = null;
            }
            GC.Collect();
            return theImage;
        }
        public static MemoryStream LoadMemoryStreamFromFile(string fileName) {
            MemoryStream = null;
            (FileStream = new FileStream(fileName, FileMode.Open,
            FileAccess.Read)) {
                byte[] fil;
                = new byte[fileStream.Length];
                fileStream.Read(fil, 0, fil.Length);
                fileStream.Close();
                = new MemoryStream(fil);
            }
            GC.Collect();
            return ms;
        }
        #endregion
        #region Run the process
        private string RunProcess(string Parameters) {
            //create a process info
            ProcessStartInfo = new ProcessStartInfo(this._ffExe, Parameters);
            oInfo. = false;
            oInfo. = true;
            oInfo. = true;
            oInfo. = true;
            //Create the output and streamreader to get the output
            string = null; StreamReader = null;
            //try the process
            {
                //run the process
                Process = System.Diagnostics.Process.Start(oInfo);
                proc.WaitForExit();
                //get the output
                = proc.StandardError;
                //now put it in a string
                = srOutput.ReadToEnd();
                proc.Close();
            } (Exception) {
                = string.Empty;
            } {
                //now, if we succeded, close out the streamreader
                ( != null) {
                    srOutput.Close();
                    srOutput.Dispose();
                }
            }
            return output;
        }
        #endregion
        #region GetVideoInfo
        public VideoFile GetVideoInfo(MemoryStream inputFile, string Filename) {
            string = Path.Combine(this.WorkingPath, System.Guid.NewGuid().ToString() + Path.GetExtension(Filename));
            FileStream = File.Create(tempfile);
            inputFile.WriteTo(fs);
            fs.Flush();
            fs.Close();
            GC.Collect();
            VideoFile = null;
            {
                = new VideoFile(tempfile);
            } (Exception ex) {
                throw ex;
            }
            GetVideoInfo(vf);
            {
                File.Delete(tempfile);
            } (Exception) {
            }
            return vf;
        }
        public VideoFile GetVideoInfo(string inputPath) {
            VideoFile = null;
            {
                = new VideoFile(inputPath);
            } (Exception ex) {
                throw ex;
            }
            GetVideoInfo(vf);
            return vf;
        }
        public void GetVideoInfo(VideoFile input) {
            //set up the parameters for video info
            string = string.Format("-i {0}", input.Path);
            string = RunProcess(Params);
            input. = output;
            //get duration
            Regex = new Regex("[D|d]uration:.((\\d|:|\\.)*)");
            Match = re.Match(input.RawInfo);
            (m.Success) {
                string = m.Groups[1].Value;
                string[] = duration.Split( char[] { ':', '.' });
                (timepieces. == 4) {
                    input. = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3]));
                }
            }
            //get audio bit rate
            = new Regex("[B|b]itrate:.((\\d|:)*)");
            = re.Match(input.RawInfo);
            double = 0.0;
            (m.Success) {
                Double.TryParse(m.Groups[1].Value, out kb);
            }
            input. = kb;
            //get the audio format
            = new Regex("[A|a]udio:.*");
            = re.Match(input.RawInfo);
            (m.Success) {
                input. = m.Value;
            }
            //get the video format
            = new Regex("[V|v]ideo:.*");
            = re.Match(input.RawInfo);
            (m.Success) {
                input. = m.Value;
            }
            //get the video format
            = new Regex("(\\d{2,3})x(\\d{2,3})");
            = re.Match(input.RawInfo);
            (m.Success) {
                int = 0; int = 0;
                int.TryParse(m.Groups[1].Value, out width);
                int.TryParse(m.Groups[2].Value, out height);
                input. = width;
                input. = height;
            }
            input. = true;
        }
        #endregion
        #region Convert to FLV
        public OutputPackage ConvertToFLV(MemoryStream inputFile, string Filename) {
            string = Path.Combine(this.WorkingPath, System.Guid.NewGuid().ToString() + Path.GetExtension(Filename));
            FileStream = File.Create(tempfile);
            inputFile.WriteTo(fs);
            fs.Flush();
            fs.Close();
            GC.Collect();
            VideoFile = null;
            {
                = new VideoFile(tempfile);
            } (Exception ex) {
                throw ex;
            }
            OutputPackage = ConvertToFLV(vf);
            {
                File.Delete(tempfile);
            } (Exception) {
            }
            return oo;
        }
        public OutputPackage ConvertToFLV(string inputPath) {
            VideoFile = null;
            {
                = new VideoFile(inputPath);
            } (Exception ex) {
                throw ex;
            }
            OutputPackage = ConvertToFLV(vf);
            return oo;
        }
        public OutputPackage ConvertToFLV(VideoFile input) {
            (!input.infoGathered) {
                GetVideoInfo(input);
            }
            OutputPackage = new OutputPackage();
            //set up the parameters for getting a previewimage
            string = 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.
            = (int)Math.Round(TimeSpan.FromTicks(input.Duration. / 3).TotalSeconds, 0);
            string = Path.Combine(this.WorkingPath, filename);
            string = string.Format("-i {0} {1} -vcodec mjpeg -ss {2} -vframes 1 -an -f rawvideo", input.Path, finalpath, secs);
            string = RunProcess(Params);
            ou. = output;
            (File.Exists(finalpath)) {
                ou. = LoadImageFromFile(finalpath);
                {
                    File.Delete(finalpath);
                } (Exception) { }
            } { //try running again at frame 1 to get something
                = string.Format("-i {0} {1} -vcodec mjpeg -ss {2} -vframes 1 -an -f rawvideo", input.Path, finalpath, 1);
                = RunProcess(Params);
                ou. = output;
                (File.Exists(finalpath)) {
                    ou. = LoadImageFromFile(finalpath);
                    {
                        File.Delete(finalpath);
                    } (Exception) { }
                }
            }
            = Path.Combine(this.WorkingPath, filename);
            = System.Guid.NewGuid().ToString() + ".flv";
            = string.Format("-i {0} -y -ar 22050 -ab 64 -f flv {1}", input.Path, finalpath);
            = RunProcess(Params);
            (File.Exists(finalpath)) {
                ou. = LoadMemoryStreamFromFile(finalpath);
                {
                    File.Delete(finalpath);
                } (Exception) { }
            }
            return ou;
        }
        #endregion
    }
    {
        #region Properties
        private string _Path;
        {
            {
                return _Path;
            }
            {
                = value;
            }
        }
        { get; set; }
        { get; set; }
        { get; set; }
        { get; set; }
        { get; set; }
        { get; set; }
        { get; set; }
        { get; set; }
        #endregion
        #region Constructors
        public VideoFile(string path) {
            = path;
            Initialize();
        }
        #endregion
        #region Initialization
        private void Initialize() {
            this. = false;
            //first make sure we have a value for the video file setting
            (string.IsNullOrEmpty(_Path)) {
                throw new Exception("Could not find the location of the video file");
            }
            //Now see if the video file exists
            (!File.Exists(_Path)) {
                throw new Exception("The video file " + + " does not exist.");
            }
        }
        #endregion
    }
    OutputPackage{
        { get; set; } public System.Drawing.Image { get; set; } { get; set; } { get; set; }
    }
}