Jongho Choi
Jongho Choi

Reputation: 1

How do I get frames one by one from the video in Qt framework?

I got a video input with QMediaPlayer and then I wanted to read frames one by one and process all frames with other vision algorithms. But I didn't know how do I get frames one by one from the video and access each pixel of the frame...

In OpenCV library, I'm easily able to solve that problem with cv::VideoCapture and cv::Mat.

cv::VideoCapture capture(filename);
cv::Mat img;

capture >> img; // 'img' contains the first frame of the video.
capture >> img; // 'img' contains the second frame of the video.

If someone has already handle with this kind of problem, please help me.

Thanks a lot.

Upvotes: 0

Views: 1894

Answers (2)

Diego Victor de Jesus
Diego Victor de Jesus

Reputation: 3003

A suggestion: you could use OpenCV. That would make things easier to play videos and process them without QImage->Mat conversion.

In order to process videos with OpenCV + Qt you must create a QThread connected to a QTimer signal. The QTimer signal emits every few milliseconds signals to a slot in the worker thread to fetch the next video frame from VideoCapture and work on the data.

Upvotes: 1

Gert Wollny
Gert Wollny

Reputation: 529

You could write your own implementation of the QAbstractVideoSurface and override its present method to handle the video frame by frame. Then you will have to set the video output of the QMediaPlayer via setVideoOutput.

For details how to access the frame data you should consult the QVideoFrame documentation.

Upvotes: 2

Related Questions