MarshalSHI
MarshalSHI

Reputation: 625

Create video into buffer with python

I have several images which took from a video. For now, I want to convert images to a video. But I don't want to save this video on my disk, I just want to save it to buffer (e.g.: StringIO, BytesIO, etc.).

I tried PyAV to write a video.

output = av.open('test.mp4', 'w')
stream = output.add_stream('mpeg4', 30)
for image in images:
    frame = av.VideoFrame.from_ndarray(image, format='rgb24')
    packet = stream.encode(frame)
    output.mux(packet)
output.close()

The former code can generate the test.mp4 file. But how to write it into buffer instead of a file? Use openCV?

Thanks.

Upvotes: 3

Views: 2019

Answers (1)

Anshul
Anshul

Reputation: 360

PyAV Documentation Specify That, you need to call decode from packet, even to get encoded data

Packet() A packet of encoded data within a Stream.

This may, or may not include a complete object within a stream. decode() must be called to extract encoded data.

Upvotes: 1

Related Questions