尝试使用ffmpeg打开网络摄像头(ffplay -f video4linux2 / dev / video0正常工作
pFormatCtx = NULL;
av_register_all();
avcodec_register_all();
avformat_network_init();
const char device[] = "/dev/video0";
const char formatName[] = "video4linux";
if (!(pFormat = av_find_input_format(formatName))) {
printf("can't find input format %s\n", formatName);
return ;
}
if (avformat_open_input(&pFormatCtx, device, pFormat, NULL)!=0) {
printf("can't find open input file %s\n", device);
return ;
}
但pFormat始终为0;
更新:如何从网络摄像头获取mjpeg?
答案 0 :(得分:0)
你应该在开头调用avdevice_register_all()。
pFormatCtx = NULL;
av_register_all();
avdevice_register_all();
avcodec_register_all();
avformat_network_init();
const char device[] = "/dev/video0";
const char formatName[] = "video4linux";
if (!(pFormat = av_find_input_format(formatName))) {
printf("can't find input format %s\n", formatName);
return ;
}
if (avformat_open_input(&pFormatCtx, device, pFormat, NULL)!=0) {
printf("can't find open input file %s\n", device);
return ;
}