FFmpegV4L2VideoSource
The FFmpegV4L2VideoSource is used to get data from sensors through the V4L2 interface. It supports setting the output data format and can convert one output into multiple outputs. V4L2 devices only support one data output at a time, but FFmpegV4L2VideoSource can provide multiple outputs.
API Instructions
namespace com { namespace sunplus { namespace media {
class FFmpegV4L2VideoSource : public FFmpegVideoSource {
public:
FFmpegV4L2VideoSource(std::string device);
~FFmpegV4L2VideoSource();
public:
int open(AVDictionary* options);
void close();
AVStream* getAVStream();
std::shared_ptr<FFmpegVideoProvider> creatVideoProvider(int maxQueueSize = 4);
void destroyVideoProvider(std::shared_ptr<FFmpegVideoProvider> provider);
void setVideoDataCallback(VideoPacketCallback callback);
};
}}}
Constructors
/*
* @device V4l2 device, such as "/dev/video0"
*/
FFmpegV4L2VideoSource(std::string device);
open
Open this V4L2 device and retrieve stream information.
Set output format by options. Such as width, height, pixel format, fps, etc.
If options is NULL, the default value will be used.
/**
* Open this V4L2 device and retrieve stream information.
* The device must be closed with close().
*
* @param options v4l2 demuxer-private options.
* May be NULL.
*
* @return 0 on success, < 0 on error.
*
*/
int open(AVDictionary* options);
You can get the formats the device supports by using the following command.
Sample
Close
Close this V4L2 device. Free all its contents.
The device must be closed with close().
getAVStream
You can get stream information through it, but it must be after the device is successfully opened. Such as time_base, start_time, codec, etc.
Sample
creatVideoProvider
Create a video provider to cache data. You can limit the size of the queue. Then the obtained data will be put into the queue of FFmpegVideoProvider.
Then you can get the data by FFmpegVideoProvider. FFmpegVideoProvider API Instructions please refer to here.
destroyVideoProvider
Free the FFmpegVideoProvider and all its cache data.
setVideoDataCallback
If you only need one output and do not want to use FFmpegVideoProvider, you can get the data by setting VideoPacketCallback.
Sample Code
This is a sample of creating two different frame rates YUV Video Provider through FFmpegV4L2VideoSource.
the flow of creating video providers:
create video source --> open video source --> create video provider --> provider prepare --> create the thread of get frame
Test Result
Â