0

I'm currently trying to solve a problem in C++ using QT. I am trying to grab a video Frame from a video running in the output stream of a QMediaPlayer and add grayscale to that frame and then send it back to the video Output stream of the mediaplayer.

Grab video Frame ----> Add Gray Scale to frame ---->Send back to output stream

For now I am able to grab the videoFrame using QVideoFrame in QT and modify it. However i am not sure on how to send it back to the media player output stream. I am going through the QT source code but so far no luck.

The same problem can be solved usinng QML however I don't want to go ahead with using QML and instead solve this using C++.

I hope some one here has an Idea on how to do it. Thank you

1 Answers1

1

Use QAbstractVideoSurface

Quoting the documentation:

The QAbstractVideoSurface class defines the standard interface that video producers use to inter-operate with video presentation surfaces. You can subclass this interface to receive video frames from sources like decoded media or cameras to perform your own processing.

Also, here is a quick overview of how you would use this class.

ch200c
  • 46
  • 4
  • Hey Thank you for the quick reply. I have tried using QAbstractVideo Surfaca. However if you see the source code mentioned in your link "https://doc.qt.io/qt-5/videooverview.html#working-with-low-level-video-frames" The function bool present defines the VideoFrame as a Constant and thus I'm unable to modify the frame. Is there a work around for this? – Ayush Gupta Apr 10 '19 at 10:31
  • @AyushGupta Unfortunately you can't modify it directly, however you can just copy the pixel contents of that video frame and handle it elsewhere. You will need to call `QVideoFrame::map()` and then access the pixel contents via `QVideoFrame::bits()`. There is a nice example in [this](https://stackoverflow.com/a/26231772/7063763) answer. – ch200c Apr 10 '19 at 10:52
  • Thanks for your help and from the link I understood that the Frame is being drawn as an Image into a Label. Is there any way to add this QImage into the QMediaPlayer? – Ayush Gupta Apr 16 '19 at 04:18
  • @AyushGupta As I have mentioned previously, you can't _send_ the frame back to the stream. The intended usage is to use the acquired frame elsewhere, e.g. set the pixmap of a `QLabel`. – ch200c Apr 16 '19 at 12:45
  • I get it now, Thank you very much for clearing this out for me. – Ayush Gupta Apr 17 '19 at 09:22