1 打开设备
对于FFMpeg编程,首先要打开相关设备,这里我们打开的是linux下的webCam,也就是笔记本摄像头 。在Linux下的ffmpeg里面,需要梳理两个东西:
a Video4linux2(简称V4L2),是linux中关于视频设备的内核驱动
b /dev/video0 /dev/video1 都是代表目标录制设备
其中帧率跟图像大小都是需要进行设置的,然后按照如下代码进行设备打开。
static AVFormatContext* open_dev() {
//注册所有设备
avdevice_register_all();
//获得格式
const AVInputFormat* iformat = av_find_input_format("video4linux2");
//打开设备
AVFormatContext* fmt_ctx = NULL;
//const char* device_name = "hw:0,0";//这个是音频
const char* device_name = "/dev/video0";
AVDictionary* options = NULL;
//视频就需要做options了
av_dict_set(&options, "video_size", "640*480", 0);
av_dict_set(&options, "framerate", "30", 0);
int ret = avformat_open_input(&fmt_ctx, device_name, iformat, &options);
//判断是否成功
char errors[1024] = {0, };
if(ret < 0) {
av_strerror(ret, errors, 1024);
std::cout << "Faile to open Device : " <<errors<<std::endl;
re

本文介绍了如何使用FFmpeg在Linux环境下打开Video4Linux2(V4L2)设备,如/dev/video0,进行摄像头录制。通过设置帧率和图像大小,然后调用avformat_open_input打开设备,并将数据保存到文件。在记录过程中,需要注意在不同平台上pkt.size可能存在的差异,并使用av_packet_unref释放内存。
——Linux下ffmpeg编程实现摄像头捕捉&spm=1001.2101.3001.5002&articleId=117900567&d=1&t=3&u=043566bbad6e486bb6bada83bd84c59e)
8743

被折叠的 条评论
为什么被折叠?



