简介
在开始的时候,使用一个v4l2的lib example代码,用起来不错,但是后来使用sony的相机之后发现需要解码(MJPG),但是试了很多方法都不行,其中包括opencv的videoCapture, 使用ffmpeg解码,后来采用libav,的方式可以成功。
Libav是ffmpeg的devel版本。
在使用的时候包含
LIBS += -L -lavcodec -lavformat -lavutil -lavdevice -lswscale -lx264
由于调用的是c程序,因此需要使用extern c.
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
#define UINT64_C
extern "C" {
#include <libavformat/avformat.h>
#include "libavcodec/avcodec.h"
#include "libavutil/mathematics.h"
#include "libavutil/samplefmt.h"
#include "libswscale/swscale.h"
#include <libavdevice/avdevice.h>
#include <libswscale/swscale.h>
}
使用流程
1. 注册
av_register_all();
avdevice_register_all();