Exemplo n.º 1
0
        public static void GetSizeAsync(string file, Action <Size> callback)
        {
            FFProbeProcess ffprobe = CreateFFProbeProcess(true);

            ffprobe.StartInfo.FileName  = "ffprobe.exe";
            ffprobe.StartInfo.Arguments = $"-v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 \"{file}\"";
            ffprobe.callback            = callback;
            ffprobe.input   = file;
            ffprobe.Exited += FFProbeExited;

            ffprobe.Start();
        }
Exemplo n.º 2
0
        private static FFProbeProcess CreateFFProbeProcess(bool raiseEvents)
        {
            FFProbeProcess process = new FFProbeProcess();

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.CreateNoWindow         = true;

            process.EnableRaisingEvents = raiseEvents;

            return(process);
        }
Exemplo n.º 3
0
        private static void FFProbeExited(object sender, EventArgs e)
        {
            FFProbeProcess p = (FFProbeProcess)sender;

            var nums = p.StandardOutput.ToString().Split(new char[] { 'x' }, StringSplitOptions.RemoveEmptyEntries);

            if (nums.Length == 2)
            {
                p.callback.Invoke(new Size(int.Parse(nums[0]), int.Parse(nums[1])));
            }
            else
            {
                p.callback.Invoke(new Size(0, 0));
            }

            p.Close();
            p.Dispose();
        }
Exemplo n.º 4
0
        public static Size GetSizeWait(string filepath)
        {
            FFProbeProcess process = CreateFFProbeProcess(false);

            process.StartInfo.FileName  = "ffprobe.exe";
            process.StartInfo.Arguments = $"-v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 \"{filepath}\"";
            process.input = filepath;

            process.Start();

            var nums = process.StandardOutput.ReadLine().Split(new char[] { 'x' }, StringSplitOptions.RemoveEmptyEntries);

            process.StandardOutput.ReadToEnd();     //Fully read both of these buffers to prevent a hand on WaitForExit().
            process.StandardError.ReadToEnd();

            process.WaitForExit();

            process.Close();
            process.Dispose();

            return(new Size(int.Parse(nums[0]), int.Parse(nums[1])));
        }