Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        private void DoConversion(object commandLine)
        {
            var exePath = FFmpegDownloadHelper.FullPathToFFmpegForSayMoreExe;

            _conversionOutput = new StringBuilder(exePath);
            _conversionOutput.Append(commandLine);

            try
            {
                // ffmpeg always seems to write the output to standarderror.
                // I don't understand why and that's wrong, but we'll deal with it.
                _process = ExternalProcess.StartProcessToMonitor(exePath, commandLine as string,
                                                                 HandleProcessDataReceived, HandleProcessDataReceived, null);
            }
            catch (Exception e)
            {
                ErrorReport.ReportNonFatalException(e);
                return;
            }

            try
            {
                _process.PriorityClass = ProcessPriorityClass.BelowNormal;
            }
            catch (InvalidOperationException)
            {
                // process probably already exited
            }
            _process.WaitForExit();

            if (_conversionReportingAction != null)
            {
                _conversionReportingAction(TimeSpan.FromSeconds(int.MaxValue), null);
            }
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        public static Image GetImageFromVideo(string videoPath, float seconds)
        {
            Image img = null;

            videoPath = videoPath.Replace('\\', '/');
            var prs       = new ExternalProcess(MPlayerPath);
            var tmpFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(tmpFolder);
            var tmpFile = Path.Combine(tmpFolder, "00000001.jpg");

            try
            {
                prs.StartInfo.Arguments =
                    string.Format("-nocache -nofontconfig -really-quiet -frames 1 -ss {0} -nosound -vo jpeg:outdir=\"\"\"{1}\"\"\" \"{2}\"",
                                  seconds, tmpFolder, videoPath);

                prs.StartProcess();
                prs.WaitForExit();
                prs.Close();

                // I'm hesitant to comment out this line, but because of SP-248, we'll see what happens.
                //ComponentFile.WaitForFileRelease(videoPath);

                if (File.Exists(tmpFile))
                {
                    // I could use Image.FromFile, but that leaves
                    // a lock on the file, for some reason.
                    var stream = new FileStream(tmpFile, FileMode.Open);
                    img = Image.FromStream(stream);
                    stream.Close();
                }
            }
            finally
            {
                if (File.Exists(tmpFile))
                {
                    File.Delete(tmpFile);
                }

                try { Directory.Delete(tmpFolder); }
                catch { }
            }

            return(img);
        }