Important: Please read the Qt Code of Conduct -

Buffer/delay video frames from QCamera

  • Hi!
    I'm trying to implement a program which displays the output from a QCamera with a configurable delay. Lets say 30 sec. I have implemented an simple example code using the QAbstractVideoFilter class (see bellow). I'm pretty sure this is a really bad way to implement this, but it actually works on my desktop. I have tried on my Android phone also, but it crash when returning the buffered frames.

    Can someone help me with how to implement this in a "correct" way? Guess i should do a hard-copy of the input frame. Any suggestions of how to accomplish that?

    Should i use QAbstractVideoFilter is there better methods? Such as using the QAbstractVideoSurface class.

    class DelayFilterRunnable : public QVideoFilterRunnable {
        QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags)
            static std::list<QVideoFrame> buffer;
            if (buffer.size() >= 30)
                *input = buffer.front();
            return *input;
    class DelayFilter : public QAbstractVideoFilter {
        QVideoFilterRunnable *createFilterRunnable() { return new DelayFilterRunnable; }
        void finished(QObject *result);

    I use the filter in my QML-file.

        Camera {
            id: camera
            captureMode: Camera.CaptureVideo
        VideoOutput {
            id: viewfinder
            source: camera
            autoOrientation: true
            filters: [ delayBuffer ]
        DelayFilter {
            id: delayBuffer

  • Lifetime Qt Champion


    Did you check the memory consumption of your application ? Depending on your camera speed and captured image size, it makes quiet a lot.

  • @SGaist
    Hi! Thanks for the attention =) Yes, I have looked at it, but its not a problem (Not on the Desktop anyway).
    Is it "ok" to store QVideoFrames likes this, without doing a hard-copy?
    The phone crash when the list have stored its 30 frames and returns the first one. It does not matter if I shrink the list-size to less frames. I think it has to do with that the handle is a GLTextureHandle. Because it works on my desktop, and its frames has no handle. Any idé?

  • Lifetime Qt Champion

    The Android and Desktop backend don't necessarily work the same way since they rely on the platform multimedia APIs and they may use different types of data to store the video data.

    One thing that I find strange in your code is that you are overwriting input with the content of buffer rather than returning it.