Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
219c6f826c | 11 months ago |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
@ -0,0 +1,135 @@
|
||||
#include "FFVideoFormatConvert.h"
|
||||
#include "VideoObjNetwork.h"
|
||||
|
||||
CFFVideoFormatConvert::CFFVideoFormatConvert(void)
|
||||
: m_img_convert_ctx(NULL)
|
||||
, m_pFrame(NULL)
|
||||
, m_pBuffer(NULL), m_uBufferSize(0)
|
||||
, m_iWidth(0), m_iHeight(0)
|
||||
, m_pImage(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CFFVideoFormatConvert::~CFFVideoFormatConvert(void)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void CFFVideoFormatConvert::Close()
|
||||
{
|
||||
if (m_img_convert_ctx)
|
||||
{
|
||||
sws_freeContext(m_img_convert_ctx);
|
||||
m_img_convert_ctx = NULL;
|
||||
}
|
||||
|
||||
if (m_pFrame)
|
||||
{
|
||||
av_frame_free(&m_pFrame);
|
||||
m_pFrame = NULL;
|
||||
}
|
||||
|
||||
if (m_pBuffer)
|
||||
{
|
||||
av_free(m_pBuffer);
|
||||
m_pBuffer = NULL;
|
||||
m_uBufferSize = 0;
|
||||
}
|
||||
|
||||
if (m_pImage != NULL)
|
||||
{
|
||||
delete m_pImage;
|
||||
m_pImage = NULL;
|
||||
}
|
||||
|
||||
m_iWidth = 0;
|
||||
m_iHeight = 0;
|
||||
}
|
||||
|
||||
bool CFFVideoFormatConvert::RGB32toYUV420P(const QImage* pIn, AVFrame** pOut)
|
||||
{
|
||||
// reinitialize object if image width or height changed
|
||||
if (pIn->width() != m_iWidth || pIn->height() != m_iHeight)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
if (m_pBuffer == NULL)
|
||||
{
|
||||
m_iWidth = pIn->width();
|
||||
m_iHeight = pIn->height();
|
||||
m_uBufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pIn->width(), pIn->height(), 1);
|
||||
m_pBuffer = (uint8_t *) av_malloc(m_uBufferSize);
|
||||
}
|
||||
|
||||
if (m_pFrame == NULL)
|
||||
{
|
||||
m_pFrame = av_frame_alloc();
|
||||
m_pFrame->width = pIn->width();
|
||||
m_pFrame->height = pIn->height();
|
||||
av_image_fill_arrays(m_pFrame->data, m_pFrame->linesize,
|
||||
m_pBuffer, AV_PIX_FMT_YUV420P, pIn->width(), pIn->height(), 1);
|
||||
}
|
||||
|
||||
if (m_img_convert_ctx == NULL)
|
||||
{
|
||||
m_img_convert_ctx = sws_getContext(pIn->width(), pIn->height(),
|
||||
AV_PIX_FMT_RGB32,
|
||||
pIn->width(), pIn->height(),
|
||||
AV_PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
const uint8_t *const srcSlice[] = { pIn->bits() };
|
||||
const int srcStride[] = { pIn->bytesPerLine()};
|
||||
sws_scale(m_img_convert_ctx,
|
||||
srcSlice,
|
||||
srcStride, 0, pIn->height(),
|
||||
m_pFrame->data,
|
||||
m_pFrame->linesize);
|
||||
|
||||
*pOut = m_pFrame;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFFVideoFormatConvert::YUV420P2RGB32(const AVFrame* pIn, QImage** pOut)
|
||||
{
|
||||
// reinitialize object if image width or height changed
|
||||
if (pIn->width != m_iWidth || pIn->height != m_iHeight)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
if (m_pBuffer == NULL)
|
||||
{
|
||||
m_iWidth = pIn->width;
|
||||
m_iHeight = pIn->height;
|
||||
m_uBufferSize = av_image_get_buffer_size(AV_PIX_FMT_RGB32, pIn->width, pIn->height, 1);
|
||||
m_pBuffer = (uint8_t *)av_malloc(m_uBufferSize);
|
||||
}
|
||||
|
||||
if (m_pFrame == NULL)
|
||||
{
|
||||
m_pFrame = av_frame_alloc();
|
||||
av_image_fill_arrays(m_pFrame->data, m_pFrame->linesize,
|
||||
m_pBuffer, AV_PIX_FMT_RGB32, pIn->width, pIn->height, 1);
|
||||
}
|
||||
|
||||
if (m_img_convert_ctx == NULL)
|
||||
{
|
||||
m_img_convert_ctx = sws_getContext(pIn->width, pIn->height,
|
||||
AV_PIX_FMT_YUV420P,
|
||||
pIn->width, pIn->height,
|
||||
AV_PIX_FMT_RGB32, SWS_BICUBIC, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
sws_scale(m_img_convert_ctx,
|
||||
(uint8_t const * const *)pIn->data,
|
||||
pIn->linesize, 0, pIn->height,
|
||||
m_pFrame->data,
|
||||
m_pFrame->linesize);
|
||||
|
||||
*pOut = new QImage((uchar *)m_pFrame->data[0], m_iWidth, m_iHeight, QImage::Format_RGB32);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <QImage>
|
||||
|
||||
struct AVFrame;
|
||||
struct SwsContext;
|
||||
|
||||
class CFFVideoFormatConvert
|
||||
{
|
||||
public:
|
||||
CFFVideoFormatConvert(void);
|
||||
~CFFVideoFormatConvert(void);
|
||||
|
||||
bool RGB32toYUV420P(const QImage* pIn, AVFrame** pOut);
|
||||
bool YUV420P2RGB32(const AVFrame* pIn, QImage** pOut);
|
||||
private:
|
||||
void Close();
|
||||
private:
|
||||
SwsContext* m_img_convert_ctx;
|
||||
AVFrame* m_pFrame;
|
||||
|
||||
uint8_t* m_pBuffer;
|
||||
uint m_uBufferSize;
|
||||
int m_iWidth;
|
||||
int m_iHeight;
|
||||
|
||||
QImage* m_pImage;
|
||||
};
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
#ifndef QTCAMERACAPTURE_H
|
||||
#define QTCAMERACAPTURE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractVideoSurface>
|
||||
#include <QDebug>
|
||||
|
||||
class QtCameraCapture : public QAbstractVideoSurface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum PixelFormat {
|
||||
Format_Invalid,
|
||||
Format_ARGB32,
|
||||
Format_ARGB32_Premultiplied,
|
||||
Format_RGB32,
|
||||
Format_RGB24,
|
||||
Format_RGB565,
|
||||
Format_RGB555,
|
||||
Format_ARGB8565_Premultiplied,
|
||||
Format_BGRA32,
|
||||
Format_BGRA32_Premultiplied,
|
||||
Format_BGR32,
|
||||
Format_BGR24,
|
||||
Format_BGR565,
|
||||
Format_BGR555,
|
||||
Format_BGRA5658_Premultiplied,
|
||||
|
||||
Format_AYUV444,
|
||||
Format_AYUV444_Premultiplied,
|
||||
Format_YUV444,
|
||||
Format_YUV420P,
|
||||
Format_YV12,
|
||||
Format_UYVY,
|
||||
Format_YUYV,
|
||||
Format_NV12,
|
||||
Format_NV21,
|
||||
Format_IMC1,
|
||||
Format_IMC2,
|
||||
Format_IMC3,
|
||||
Format_IMC4,
|
||||
Format_Y8,
|
||||
Format_Y16,
|
||||
|
||||
Format_Jpeg,
|
||||
|
||||
Format_CameraRaw,
|
||||
Format_AdobeDng,
|
||||
|
||||
#ifndef Q_QDOC
|
||||
NPixelFormats,
|
||||
#endif
|
||||
Format_User = 1000
|
||||
};
|
||||
|
||||
Q_ENUM(PixelFormat)
|
||||
|
||||
explicit QtCameraCapture(QObject *parent = 0);
|
||||
|
||||
QList<QVideoFrame::PixelFormat> supportedPixelFormats(
|
||||
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
|
||||
|
||||
bool present(const QVideoFrame &frame) override;
|
||||
|
||||
signals:
|
||||
void frameAvailable(QImage frame);
|
||||
|
||||
};
|
||||
|
||||
#endif // QTCAMERACAPTURE_H
|
||||
|
Before Width: | Height: | Size: 526 B After Width: | Height: | Size: 526 B |
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#define GET_STR(x) #x
|
||||
#define A_VER 3
|
||||
#define T_VER 4
|
||||
|
||||
// vertex shader
|
||||
const char *vString = GET_STR(
|
||||
attribute vec4 vertexIn;
|
||||
attribute vec2 textureIn;
|
||||
varying vec2 textureOut;
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = vertexIn;
|
||||
textureOut = textureIn;
|
||||
}
|
||||
);
|
||||
|
||||
// texture shader
|
||||
const char *tString = GET_STR(
|
||||
varying vec2 textureOut;
|
||||
uniform sampler2D tex_y;
|
||||
uniform sampler2D tex_u;
|
||||
uniform sampler2D tex_v;
|
||||
void main(void)
|
||||
{
|
||||
vec3 yuv;
|
||||
vec3 rgb;
|
||||
yuv.x = texture2D(tex_y, textureOut).r;
|
||||
yuv.y = texture2D(tex_u, textureOut).r - 0.5;
|
||||
yuv.z = texture2D(tex_v, textureOut).r - 0.5;
|
||||
rgb = mat3(1.0, 1.0, 1.0,
|
||||
0.0, -0.39465, 2.03211,
|
||||
1.13983, -0.58060, 0.0) * yuv;
|
||||
gl_FragColor = vec4(rgb, 1.0);
|
||||
}
|
||||
);
|
||||
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavutil/avutil.h"
|
||||
#include "libswscale/swscale.h"
|
||||
#include "libavutil/imgutils.h"
|
||||
};
|
||||
|
||||
typedef void (*VideoDataCallback)(int iEncode, int iWidth, int iHeight, const char* pData, long lLen, long lPTS, void* pUserParam);
|
||||
|
||||
class VLKVideoWidget;
|
||||
class CVideoObjNetwork
|
||||
{
|
||||
public:
|
||||
CVideoObjNetwork();
|
||||
virtual ~CVideoObjNetwork();
|
||||
|
||||
virtual bool Open(const std::string& strURL, VLKVideoWidget* pVideoWidget);
|
||||
virtual bool IsOpen();
|
||||
void SetDataCallback(VideoDataCallback pVideoDataCB, long lUserParam);
|
||||
virtual void Clear();
|
||||
virtual void Close();
|
||||
virtual bool StartLocalRecord();
|
||||
virtual void StopLocalRecord();
|
||||
virtual void Capture();
|
||||
private:
|
||||
static void ThreadFunc(CVideoObjNetwork* pThis);
|
||||
virtual void OnThreadFunc();
|
||||
|
||||
bool OpenDemux(const std::string& strURL);
|
||||
void CloseDemux();
|
||||
void WriteLocalRecord(const AVPacket* pkt);
|
||||
static int interrupt_callback(void* para);
|
||||
void ReadPacketLoop();
|
||||
|
||||
bool OpenDecoder(const AVCodecParameters *para);
|
||||
void Send2Decode(const AVPacket* pkt);
|
||||
void Send2Display(const AVFrame* frame);
|
||||
void CloseDecoder();
|
||||
private:
|
||||
static bool m_bInit;
|
||||
std::mutex m_mutex;
|
||||
std::string m_strURL;
|
||||
VLKVideoWidget* m_pVideoWidget;
|
||||
|
||||
AVFormatContext* m_pAVFmtContext;
|
||||
int m_iVideoStreamIndex;
|
||||
int m_iAudioStreamIndex;
|
||||
int m_iWidth;
|
||||
int m_iHeight;
|
||||
|
||||
std::thread* m_pThread;
|
||||
bool m_bExit;
|
||||
|
||||
VideoDataCallback m_cbFunc;
|
||||
long m_lUserParam;
|
||||
|
||||
AVCodecContext* m_pCodecContext;
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue