0

I'm creating a code that outputs arrays that change over time per iteration. The details don't matter too much; I just need a way to get the arrays that are outputted, save them, and then stitch them into an mp4.

Here's the basic idea:

def display(A):
    %matplotlib qt 
    plt.rcParams['figure.figsize'] = [6, 6/maxX*splitmarker] #maxX and splitmarker are the dimensions of the array
    plt.imshow(A, interpolation = 'nearest', cmap = 'Blues');
    
    plt.axis('off'); 
    plt.show()
    plt.draw()
    plt.pause(0.2)

to actually display the array A. Then, for a previously defined number of iterations,

for i in iterations:
    #the array is changed
    display(A)

This displays a new array A for every i. I'm trying to find a way to get all of those displays and stitch them together in a single mp4 file (so you can see how A progresses in time). There are 2 main obstacles I'm running into:

1: I don't know how to save the arrays as individual PNGs.

2: Even if I did know how to do that, I don't know how to convert the PNGs into an mp4 using Python.

I've already tried using FFMpegWriter and OpenCV3, but I can't figure out how to actually implement them into my code. Ideally, I'd like to do something like this example FFMpegWriter function, but it doesn't really work (since I can't define a DPI that works for the array).

Thanks in advance!

Stephen
  • 35
  • 8
  • I don't quite follow - what should the mp4 look like, and how would the video correspond to the content of your arrays? Also, you understand that video formats like mp4 do lossy compression, yes? – Karl Knechtel Dec 02 '20 at 09:25
  • Well, display(A) displays an array. Each array visually looks something like this: (https://i.stack.imgur.com/z1uYP.png), format-wise. The mp4 would take each displayed array and stitch them together. It would basically look like a bunch of PNGs, one after the other, at a rate of around 15 fps. I do know that mp4s have lossy compression, but that's a limitation I'm stuck with. – Stephen Dec 02 '20 at 09:31

0 Answers0