Example #1
0
        private void OnFFMpegOutput(Process sender, DataReceivedEventArgs e, ref FFMpegProgressData data)
        {
            if (e.Data == null)
            {
                return;
            }
            //Debug.WriteLine("data: " + e.Data);
            //LogDebug(e.Data);
            Match m = DurationR.Match(e.Data);

            if (m.Success)
            {
                Util.TimeSpanLargeTryParse(m.Groups[1].Value, out TimeSpan time);
                data.Duration = time;
            }

            Match t = TimeR.Match(e.Data);

            if (t.Success)
            {
                Util.TimeSpanLargeTryParse(t.Groups[1].Value, out TimeSpan time);
                data.Time = time;
                OnProgress?.Invoke(this, new ProgressEventArgs(time.Ticks, data.Duration.Ticks, "f", data.StartTime));
            }
            else if (!m.Success)
            {
                LogDebug(e.Data);
            }
        }
Example #2
0
        public void Execute(string[] args)
        {
            string args2 = string.Join(" ", args);

            LogDebug("Final ffmpeg command args: " + args2);
            ProcessStartInfo i = new ProcessStartInfo(Filename, args2)
            {
                CreateNoWindow         = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            using (Process p = new Process
            {
                EnableRaisingEvents = true,
                StartInfo = i
            })
            {
                if (TrackProgress)
                {
                    FFMpegProgressData data = new FFMpegProgressData();
                    p.ErrorDataReceived += (sender, e) => OnFFMpegOutput((Process)sender, e, ref data);
                }
                p.Start();
                if (TrackProgress)
                {
                    p.BeginErrorReadLine();
                }
                p.WaitForExit();

                if (p.ExitCode != 0)
                {
                    throw new FFMpegException("FFMpeg Error: Exited with error code " + p.ExitCode);
                }
            }
        }
Example #3
0
        public async Task ExecuteAsync(string[] args, CancellationToken token = default)
        {
            string args2 = string.Join(" ", args);

            LogDebug("Final ffmpeg command args: " + args2);
            ProcessStartInfo i = new ProcessStartInfo(Filename, args2)
            {
                CreateNoWindow         = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            using (Process p = new Process
            {
                EnableRaisingEvents = true,
                StartInfo = i
            })
            {
                if (TrackProgress)
                {
                    FFMpegProgressData data = new FFMpegProgressData();
                    p.ErrorDataReceived += (sender, e) => OnFFMpegOutput((Process)sender, e, ref data);
                }
                p.Start();
                if (TrackProgress)
                {
                    p.BeginErrorReadLine();
                }

                if (await p.WaitForExitAsync(token).ConfigureAwait(false) != 0)
                {
                    //Debug.WriteLine("Error:" + p.StandardOutput.ReadToEnd());
                    throw new FFMpegException("FFMpeg Error: Exited with error code " + p.ExitCode);
                }
            }
        }