1、处理视频时需要的几个类:
VlcInstance,VlcMedia(连接视频)
VlcMediaPlayer(控制播放)
VlcVideoStream(视频抽帧)
2、视频抽帧:
从VlcVideoStream派生一个类,比如VideoStreaming ,实现virtual void frameUpdated(),但是发现控件VlcWidgetVideo上就不显示了,我理解的是图片被VlcVideoStream截获,因此不能在VlcWidgetVideo显示。获得的图是YUV格式的,需要转换为RGB才可以方便自定义的图片处理。
3、VlcVideoStream子类化
class VideoStreaming : public VlcVideoStream { Q_OBJECT signals: void sendImage(QImage); public: explicit VideoStreaming(Vlc::RenderFormat format, QObject *parent = 0); ~VideoStreaming(); void frameUpdated(); };
4、VideoStreaming
VideoStreaming::VideoStreaming(Vlc::RenderFormat format, QObject *parent) : VlcVideoStream(format, parent){ } VideoStreaming::~VideoStreaming(){ } void VideoStreaming::frameUpdated() { std::shared_ptrpframe = std::dynamic_pointer_cast (renderframe()); if (!pframe){ qDebug()<<"frame err"; return; // LCOV_EXCL_LINE } int rows = pframe->height + pframe->height / 2; int cols = pframe->width; int matType = CV_8UC1 ; cv::Mat myuv(rows,cols,matType,(void*)pframe->frameBuffer.data()); cv::Mat mrgb(pframe->height, pframe->width, CV_8UC3); cv::cvtColor(myuv, mrgb, CV_YUV2RGB_I420); QImage img((const unsigned char *)(mrgb.data), mrgb.cols, mrgb.rows, mrgb.cols * 3, QImage::Format_RGB888); img.rgbSwapped(); emit sendImage(img); }
5、创建对象
m_video_stream= new VideoStreaming(Vlc::YUVFormat);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)