Ejemplo n.º 1
0
        public FFmpegCommandLineResult <MemoryStream> GetFrameStreamForVideoFile(string fileName, TimeSpan frameTime)
        {
            //ffmpeg -v quiet -ss 00:00:01.000 -i "filename" -an -frames:v 1 -f image2  pipe:
            //
            var args = new CommandLineArgumentsBuilder();

            args.AppendArguments("-v", "quiet", "-ss");
            args.AppendArgumentFormat(@"{0:hh\:mm\:ss\.fff}", frameTime);
            args.AppendArgument("-i");
            args.AppendArgumentInDoubleQuotes(fileName);
            args.AppendArguments("-an", "-frames:v 1", "-f image2", "pipe:");

            var psi = StdioUtils.CreateBaseStartInfo(_app);

            psi.Arguments = args.ToString();

            var process = new Process
            {
                StartInfo = psi
            };

            process.Start();


            var    memoryStream = StdioUtils.ReadProcessStandardOutput(process);
            string errorText    = process.StandardError.ReadToEnd();
            var    ret          = new FFmpegCommandLineResult <MemoryStream>(memoryStream, errorText);

            return(ret);
        }
Ejemplo n.º 2
0
        public FFmpegCommandLineResult <TimeSpan?> GetContainerDuration(string fileName)
        {
            //ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
            CommandLineArgumentsBuilder args = new CommandLineArgumentsBuilder();

            args.AppendArguments("-v error", "-show_entries", "format=duration -of default=noprint_wrappers=1:nokey=1");
            args.AppendArgumentInDoubleQuotes(fileName);

            var psi = StdioUtils.CreateBaseStartInfo(_app);

            psi.Arguments = args.ToString();

            var process = new Process();

            process.StartInfo = psi;
            process.Start();

            process.WaitForExit(1000);
            var result = process.StandardOutput.ReadToEnd().Trim(' ', '\r', '\n');
            var error  = process.StandardError.ReadToEnd();

            double seconds;

            if (double.TryParse(result,
                                NumberStyles.Float,
                                CultureInfo.InvariantCulture,
                                out seconds))
            {
                TimeSpan ret = TimeSpan.FromSeconds(seconds);
                return(new FFmpegCommandLineResult <TimeSpan?>(ret, error));
            }
            else
            {
                return(new FFmpegCommandLineResult <TimeSpan?>(null, error));
            }
        }