首页 > 技术知识 > 正文

环境

ubuntu 16.04

ffmpeg 4.1 主要三个函数 av_find_input_format(); //让ffmpeg选择适当的输入格式(是文件?还是v4l2设备) avformat_open_input();//打开v4l2设备 av_read_frame();//获得视频帧 代码如下 int get_video() { int ret; AVFormatContext *fmtCtx{}; AVPacket *packet{}; AVInputFormat *inputFmt{}; avdevice&#95;register_all(); inputFmt = av_find_input_format (“video4linux2”); if (inputFmt == NULL){ printf(“can not find_input_format\n”); return; } ret =avformat_open_input(&fmtCtx, “/dev/video0”, inputFmt, NULL); if(ret < 0){ printf(“can not open_input_file\n”); return; } packet = (AVPacket *)av_malloc(sizeof(AVPacket)); while(1){ av_read_frame(fmtCtx, packet); cou<<“read a frame”<<endl; } av_free(packet); avformat_close&#95;input(&fmtCtx); return 0; }
<
如果想要设置帧率和大小尺寸之类的可以使用av_dict_set进行配置。

猜你喜欢