我正在编写一个程序来将一些网络摄像头视频保存到文件中。我正在使用此处找到的 x264 编解码器 x264
当我尝试将帧写入文件时,会弹出此错误消息。
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/