C++ 如何利用vlc-qt从视频中获取帧
我使用vlc qt解码h264视频流,但我需要视频(流)中的每一帧进行进一步处理。我找到了这个描述解决方案的链接: 我创建了一个从VlcVideoStream类继承的类,并重新实现了frameUpdated()函数,如下所示:C++ 如何利用vlc-qt从视频中获取帧,c++,qt,vlc,vlc-qt,C++,Qt,Vlc,Vlc Qt,我使用vlc qt解码h264视频流,但我需要视频(流)中的每一帧进行进一步处理。我找到了这个描述解决方案的链接: 我创建了一个从VlcVideoStream类继承的类,并重新实现了frameUpdated()函数,如下所示: void MyVideoStream::frameUpdated() { qDebug() << "frame" ; int rows, cols, matType; // convert to shared pointer to const frame
void MyVideoStream::frameUpdated() {
qDebug() << "frame" ;
int rows, cols, matType;
// convert to shared pointer to const frame to avoid crash
std::shared_ptr<const VlcYUVVideoFrame> frame = std::dynamic_pointer_cast<const VlcYUVVideoFrame>(renderFrame());
if (!frame) {
return; // LCOV_EXCL_LINE
}
rows = frame->height + frame->height/2;
cols = frame->width;
}
其中_player是VlcMediaPlayer对象引用。但当我运行程序时,什么也没发生。我不知道是什么问题 当您将VlcVideoStream子类化并重新实现frameUpdated()时,您可以在每次更新YUV帧时访问它。 如果您熟悉Opencv,只需将以下代码添加到frameUpdated()函数中,即可看到灰色图像:
void MyVideoStream::frameUpdated()
{
std::shared_ptr<const VlcYUVVideoFrame> frame= std::dynamic_pointer_cast<const VlcYUVVideoFrame>(renderFrame());
if (!frame) {
return; // LCOV_EXCL_LINE
}
int width = frame->width;
int height = frame->height;
cv::Mat result = cv::Mat(height, width, CV_8UC1, (void*)frame->frameBuffer.data());
imshow("result", result);
waitKey(2);
}
void MyVideoStream::frameUpdated()
{
std::shared_ptr frame=std::dynamic_pointer_cast(renderFrame());
如果(!帧){
return;//LCOV\u EXCL\u行
}
整数宽度=帧->宽度;
int height=帧->高度;
cv::Mat result=cv::Mat(高度、宽度、cv_8UC1,(void*)帧->帧缓冲区.data());
imshow(“结果”,result);
等待键(2);
}
void MyVideoStream::frameUpdated()
{
std::shared_ptr<const VlcYUVVideoFrame> frame= std::dynamic_pointer_cast<const VlcYUVVideoFrame>(renderFrame());
if (!frame) {
return; // LCOV_EXCL_LINE
}
int width = frame->width;
int height = frame->height;
cv::Mat result = cv::Mat(height, width, CV_8UC1, (void*)frame->frameBuffer.data());
imshow("result", result);
waitKey(2);
}