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.
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.
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.
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.