c# - 如何从 FFMPEG 获取 c# 中的帧进度

标签 c# .net-core ffmpeg

我是第一次在 c# 中使用 Process 命名空间,我正在使用 FFMPEG 在视频中添加水印。我已成功添加水印,但我也想在我的程序控制台中显示进度。如何获得 frame目前FFmpeg上没有。
为了实现这一点,我还使用 ffprobe 来获取总帧数,然后,我将它与当前帧数相除,以便获得进度。问题是我不知道如何在 ffmpeg 对视频进行处理时获取帧。

最佳答案

几年前,我为这样的事情写了一些帮助类。有趣的部分是:


        private Process _ffmpeg = null;

        public override void StartRecording()
        {
            ProcessStartInfo psi = new ProcessStartInfo
            {
                FileName = PATH_TO_FF_HERE,
                Arguments = ARGS_FOR_FF_HERE,
                WindowStyle = ProcessWindowStyle.Hidden,
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true
            };

            _ffmpeg = System.Diagnostics.Process.Start(psi);
            _ffmpeg.OutputDataReceived += Ffmpeg_OutputDataReceived;
            _ffmpeg.ErrorDataReceived += Ffmpeg_ErrorDataReceived;
            _ffmpeg.BeginOutputReadLine();
            _ffmpeg.BeginErrorReadLine();

            _ffmpeg.PriorityClass = ProcessPriorityClass.High;
        }

        void Ffmpeg_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data != null && e.Data.StartsWith("frame="))
            {
                //for example, e.Data might look like:
                //frame=113987 fps= 10 q=-1.0 Lsize=  204000kB time=03:09:58.50 bitrate= 146.6kbits/s

                //do something here
            }
        }
        void Ffmpeg_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data != null && e.Data.StartsWith("frame="))
            {
                //do something here
            }
        }

出于我的目的,我对帧数据不感兴趣,所以我忽略了任何以“frame =”开头的字符串,但是如果您看到一个确实的数据,听起来您想采取行动,如果某个帧计数器是,则可能会激活一个事件比以前高 100 (我认为您不需要在处理的每一帧上引发一个事件..但是您可以自由地做您想做的事!)

关于c# - 如何从 FFMPEG 获取 c# 中的帧进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70182490/

相关文章:

c# - 将部分填充的 DTO 映射到域对象

javascript - 想要在我的按钮单击事件中使用 ajax 多个文件上传

ffmpeg - 在 CentOS 上安装 ffmpeg-php

bash - 如何从powershell中为bash设置环境变量?

c# - JWT 承载身份验证不从 header 读取 token

android - Linux 中的 aac-eld 解码

ruby-on-rails - 可卡因::CommandNotFoundError

c# - 如何使用 C# 在 WinForm 中手动绑定(bind)到低功耗蓝牙设备?

c# - 你可以从它的路径访问一个选择的 StorageFile 吗? - UWP

asp.net - 扩展现有 ABP Controller