void WorkerClass_ProgressInfo(ProgressInfoEventArgs e)
 {
     //LogMessage(e.Message);
 }
 private void ProgressUpdated(object sender, ProgressInfoEventArgs e)
 {
     //  pBar.Value = e.Stat;
     // progText.Text = e.Stat.ToString() + "%";
 }
Beispiel #3
0
        private int executeFFmpeg(string args, EncodeObject eo)
        {
            ffmpeg_process = new Process
            {
                StartInfo =
                {
                    FileName               = ffmpeg_exe,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    Arguments      = args,
                    CreateNoWindow = true
                },
            };

            ffmpeg_process.Start();
            ffmpeg_process.PriorityClass = ProcessPriorityClass.BelowNormal;

            try
            {
                Regex progressRegex = new Regex(@"(?<KEY>[a-z]+)=\s*(?<VALUE>[^ ]+)\s*", RegexOptions.Compiled);
                Regex digRegex      = new Regex(@"\d+");
                Regex fltRegex      = new Regex(@"\d+(\.\d+)?");
                while (true)
                {
                    var line = ffmpeg_process.StandardError.ReadLine();
                    if (line == null || line == string.Empty)
                    {
                        break;
                    }

                    MatchCollection mc = progressRegex.Matches(line);
                    if (mc.Count == 0)
                    {
                        continue;
                    }

                    string[] groups = new string[] { "frame", "fps", "size", "time", "bitrate", "speed" };

                    Dictionary <string, string> info = new Dictionary <string, string>();
                    foreach (Match m in mc)
                    {
                        info[m.Groups["KEY"].Value] = m.Groups["VALUE"].Value;
                    }

                    Debug.WriteLine(line);
                    ProgressInfo pi = new ProgressInfo();
                    string       v;

                    info.TryGetValue("frame", out pi.frame);
                    if (info.TryGetValue("fps", out v))
                    {
                        Match m = fltRegex.Match(v);
                        if (m.Success)
                        {
                            float.TryParse(m.Groups[0].Value, out pi.fps);
                        }
                    }

                    if (info.TryGetValue("size", out v))
                    {
                        Match m = digRegex.Match(v);
                        if (m.Success)
                        {
                            int.TryParse(m.Groups[0].Value, out pi.size);
                        }
                    }
                    if (info.TryGetValue("time", out v))
                    {
                        TimeSpan.TryParse(v, out pi.time);
                    }
                    if (info.TryGetValue("bitrate", out v))
                    {
                        Match m = fltRegex.Match(v);
                        if (m.Success)
                        {
                            float.TryParse(m.Groups[0].Value, out pi.bitrate);
                            eo.NewBitrate = (int)pi.bitrate;
                        }
                    }
                    if (info.TryGetValue("speed", out v))
                    {
                        Match m = fltRegex.Match(v);
                        if (m.Success)
                        {
                            float.TryParse(m.Groups[0].Value, out pi.speed);
                        }
                    }

                    if (ProgressUpdate != null)
                    {
                        ProgressInfoEventArgs e = new ProgressInfoEventArgs();
                        e.Info = pi;
                        e.EO   = eo;
                        ProgressUpdate(this, e);
                    }
                }
            }
            finally { }

            if (!ffmpeg_process.WaitForExit(500))
            {
                ffmpeg_process.Kill();
                ffmpeg_process.WaitForExit();
            }
            int exitcode = ffmpeg_process.ExitCode;

            ffmpeg_process.Dispose();
            return(exitcode);
        }