X264 Error message when capturing video

2019-02-28 07:33发布

问题:

I'm writing a program to save some webcam video to a file. I'm using the x264 codec found here x264

When I try writing frames to a file I get this error message poping up.

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

I found this VirtualDub Hack but then I'm not using virtual dub. I'm not sure what the File output mode and zero latency mean.

I think the problem is related to the codec since when I change to using a different codec, everything works fine. I'm using C# and emgu but I dont think thats where the problem lies.

EDIT

In case the code helps

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);
}

回答1:

I know is's a bit late but I figured this out. The solution(on windows) is to set -1 instead of codec's fourcc. This pops up a dialog where you can choose a codec and if you choose x264wfv, there's a configure button which lets you configure those options(zero latency works for me). Next time codec will use exact same settings, so you can run your program with fourcc code.