You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.7 KiB
111 lines
3.7 KiB
#include "basicLIBAV.h"
|
|
#ifdef WIN32
|
|
#pragma comment(lib, "avcodec.lib")
|
|
#pragma comment(lib, "avdevice.lib")
|
|
#pragma comment(lib, "avfilter.lib")
|
|
#pragma comment(lib, "avformat.lib")
|
|
#pragma comment(lib, "avutil.lib")
|
|
//#pragma comment(lib, "postproc.lib")
|
|
#pragma comment(lib, "swresample.lib")
|
|
//#pragma comment(lib, "avresample.lib")
|
|
#pragma comment(lib, "swscale.lib")
|
|
//New Deps
|
|
#pragma comment( lib, "vfw32.lib")
|
|
#pragma comment( lib, "ws2_32.lib")
|
|
//#pragma comment( lib, "libeay32.lib")
|
|
//#pragma comment( lib, "ssleay32.lib")
|
|
#pragma comment( lib, "Secur32.lib")
|
|
#pragma comment( lib, "Bcrypt.lib")
|
|
#endif
|
|
|
|
#define LOG( X ) basicLogCollection::getInstance()->Log( "basicLibAV", NULL, X )
|
|
|
|
static bool _FFD_REGISTER_ALL_FLAG = false;
|
|
|
|
FrameAspectRatio detectAspectRatio(int width, int height){
|
|
FrameAspectRatio RetVal = FAR_UNKNOWN;
|
|
/*if (((width / 4) * 3) == height) RetVal = FAR_4X3;
|
|
if (((width / 5) * 4) == height) RetVal = FAR_5X4;
|
|
if (((width / 16) * 9) == height) RetVal = FAR_16X9;
|
|
if (RetVal == FAR_UNKNOWN)RetVal = FAR_NOT_STANDARD;
|
|
*/
|
|
RetVal = (float) width / (float)height;
|
|
return RetVal;
|
|
};
|
|
|
|
bool initLibAV(void){
|
|
if (!_FFD_REGISTER_ALL_FLAG){
|
|
char Buffer[256];
|
|
_FFD_REGISTER_ALL_FLAG = true;
|
|
LOG("Init LIBAV");
|
|
sprintf(Buffer, "LibAV Codec: %d.%d.%d", LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO);
|
|
LOG(Buffer);
|
|
sprintf(Buffer, "LibAV Device: %d.%d.%d", LIBAVDEVICE_VERSION_MAJOR, LIBAVDEVICE_VERSION_MINOR, LIBAVDEVICE_VERSION_MICRO);
|
|
LOG(Buffer);
|
|
sprintf(Buffer, "LibAV Format: %d.%d.%d", LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO);
|
|
LOG(Buffer);
|
|
sprintf(Buffer, "LibAV SWScale: %d.%d.%d", LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
|
|
LOG(Buffer);
|
|
av_register_all();
|
|
avcodec_register_all();
|
|
avdevice_register_all();
|
|
avformat_network_init();
|
|
};
|
|
return _FFD_REGISTER_ALL_FLAG;
|
|
};
|
|
|
|
//************************************
|
|
// Method: avframeToCvmat
|
|
// Access: public
|
|
// Returns: cv::Mat
|
|
// Qualifier:
|
|
// Parameter: const AVFrame * frame
|
|
// Description: AVFrame?MAT
|
|
//************************************
|
|
cv::Mat avframeToCvmat(const AVFrame *frame) {
|
|
int width = frame->width;
|
|
int height = frame->height;
|
|
cv::Mat image(height, width, CV_8UC3);
|
|
int cvLinesizes[1];
|
|
cvLinesizes[0] = image.step1();
|
|
SwsContext *conversion = sws_getContext(
|
|
width, height, (AVPixelFormat)frame->format, width, height,
|
|
AVPixelFormat::AV_PIX_FMT_BGR24, SWS_FAST_BILINEAR, NULL, NULL, NULL);
|
|
sws_scale(conversion, frame->data, frame->linesize, 0, height, &image.data,
|
|
cvLinesizes);
|
|
sws_freeContext(conversion);
|
|
return image;
|
|
}
|
|
|
|
//************************************
|
|
// Method: cvmatToAvframe
|
|
// Access: public
|
|
// Returns: AVFrame *
|
|
// Qualifier:
|
|
// Parameter: cv::Mat * image
|
|
// Parameter: AVFrame * frame
|
|
// Description: MAT?AVFrame
|
|
//************************************
|
|
AVFrame *cvmatToAvframe(cv::Mat *image, AVFrame *frame) {
|
|
int width = image->cols;
|
|
int height = image->rows;
|
|
int cvLinesizes[1];
|
|
cvLinesizes[0] = image->step1();
|
|
if (frame == NULL) {
|
|
frame = av_frame_alloc();
|
|
av_image_alloc(frame->data, frame->linesize, width, height,
|
|
AVPixelFormat::AV_PIX_FMT_YUV420P, 1);
|
|
}
|
|
SwsContext *conversion = sws_getContext(
|
|
width, height, AVPixelFormat::AV_PIX_FMT_BGR24, width, height,
|
|
(AVPixelFormat)frame->format, SWS_FAST_BILINEAR, NULL, NULL, NULL);
|
|
sws_scale(conversion, &image->data, cvLinesizes, 0, height, frame->data,
|
|
frame->linesize);
|
|
sws_freeContext(conversion);
|
|
return frame;
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOG
|