简体   繁体   中英

How to get frame from video by using vlc-qt

I`m using vlc-qt for decode h264 video stream but I need every frame from video (stream) for further processing. I found this link that describes the solution :

https://discuss.tano.si/t/how-to-get-frame-from-video/253

I made a class that inherits from VlcVideoStream class and re-implement frameUpdated() function as bellow :

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;

}

and declared my class as :

MyVideoStream *_stream ;
_stream = new MyVideoStream(Vlc::YUVFormat,ui->video) ;
_stream->init(_player) ;

where _player is a VlcMediaPlayer object reference. but when I ran the program nothing happened. I don`t know what is the problem.

when you subclass the VlcVideoStream and re-implement frameUpdated(), you have access to YUV frame every time it is updated. if you are familiar with Opencv , just add these code to frameUpdated() function, then you can see the gray image :

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);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM