Exporting pyqtgraph to video

Question:

I want to export a pyqtgraph to a video. Is there any easy way to do this? The plot is not much different from this example except it contains about 10000 frames:

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg

app = QtGui.QApplication([])

win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
pg.setConfigOptions(antialias=True)
p6 = win.addPlot(title="0")
curve = p6.plot(pen='y')
data = np.random.normal(size=(10,1000))
ptr = 0
def update():
    global curve, data, ptr, p6
    data_ptr = ptr%10
    p6.setTitle("%d" % data_ptr)
    curve.setData(data[data_ptr])
    if ptr == 0:
        p6.enableAutoRange('xy', False)
    ptr += 1
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(50)
Asked By: Joost

||

Answers:

Every frame is simply a single image. So you could use the imageexporter to generate an image for each of the frames. The toBytes argument of the export function will return the *.png file in memory, though you could also number them and save them in a temporary directory.
An example of exporting the graph to a file is given in the pyqtgraph userguide.

You could then use ffmpeg to sequence them together.

If you went with the export to separate files option, you could use the ffmpeg command line as shown in:
How to create a video from images with FFmpeg?

However, if you stored all frames in memory, the ffmpeg python bindings could be used for that, though I have no example for that.

Answered By: Lanting
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.