c# - X264 捕获视频时出现错误消息

标签 c# opencv video-capture codec x264

我正在编写一个程序来将一些网络摄像头视频保存到文件中。我正在使用此处找到的 x264 编解码器 x264

当我尝试将帧写入文件时,会弹出此错误消息。 error

x264vfw [warning]: Few frames probably would be lost. Ways to fix this:

x264vfw [warning]: -if you use VirtualDub or its fork than you can enable 'VirtualDub Hack' option

x264vfw [warning]: -you can enable 'File' output mode

x264vfw [warning]: -you can enable 'Zero Latency' option

我找到了这个VirtualDub Hack但我没有使用虚拟配音。 我不确定文件输出模式和零延迟是什么意思。

我认为问题与编解码器有关,因为当我更改为使用不同的编解码器时,一切正常。我正在使用 C# 和 emgu,但我不认为这就是问题所在。

编辑

如果代码有帮助

public static void StartCapture()
{
    try
    {
        capture = new Capture();
        capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1920);  //1920
        capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1080); //1080

        CaptureOutput = new VideoWriter
        (
            "capture output.avi",
            CvInvoke.CV_FOURCC('X','2','6','4'),
            50, //fps
            (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH), 
            (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT), 
            true
        );

        if (capture != null)
        {
            capture.ImageGrabbed += SaveFrame;
            capture.Start();
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(e.ToString());
    }
}

static void SaveFrame(System.Object sender, EventArgs e)
{
    Image<Bgr, Byte> video;
    video = capture.RetrieveBgrFrame();
    CaptureOutput.WriteFrame(video);
}

最佳答案

我知道有点晚了,但我已经弄清楚了。解决方案(在Windows上)是设置-1而不是编解码器的fourcc。这会弹出一个对话框,您可以在其中选择编解码器,如果您选择 x264wfv,则会有一个配置按钮,可让您配置这些选项(零延迟对我有用)。下次编解码器将使用完全相同的设置,因此您可以使用 fourcc 代码运行您的程序。

关于c# - X264 捕获视频时出现错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21034131/

相关文章:

opencv - 如何从 OCR 图像中过滤纹理

opencv - OpenCV 中 RotatedRect 尺寸相对大小的歧义

iOS AVFoundation 视频捕获方向选项

c++ - mediafoundation 能否允许多个客户端同时访问单个网络摄像头设备?

c# - 列表场景的 AutoMapper 似乎只重复映射列表中的第一个对象

c# - 如何使用 ExecuteScalar() 获取值并将其赋给您的 textbox.text?

c# - 获取带有描述的 Excel 宏名称

c# - Unity - 调整一个游戏对象的大小以匹配另一个

python - cvtColor “code”用于16位灰度图像

linux - 自动化电视捕获 Linux