Closed sugizo closed 4 months ago
The frames that are yielded are bytes
objects. You need to convert them to a numpy array first.
The size is the meta
dict can help with that. With .reshape(meta.size[1], meta.size[0], -1)
you convert an rgb or rgba image. For grayscale you can leave out the -1
(it adds the color-dimension, whit whatever size is needed to get the total number of elements matching).
When sending the frames, it can accept a numpy array, but it needs to be contiguous, you can use np.ascontiguousarray()
for that, which is a no-op if it's already contiguous.
So without testing it, (something like) this should work:
import numpy as np
for frame in reader:
image = np.frombuffer(frame, np.uint8).reshape(meta.size[1], meta.size[0], -1)
flipped = np.ascontiguousarray(np.flipud(image))
writer.send(flipped)
code
from imageio_ffmpeg import read_frames, write_frames
import numpy as np
input_file = 'audio_video.mp4'
output_file = 'flipud.mp4'
audio_file = 'audio_video.mp4' # audio or video file
reader = read_frames(input_file)
meta = reader.__next__()
writer = write_frames(output_file, audio_path = audio_file,
size = meta['size'], fps = meta['fps'],
input_params = ['-y', ],
output_params = ['-r', '60', ] )
writer.send(None)
for frame in reader:
image = np.frombuffer(frame, np.uint8).reshape(meta.size[1], meta.size[0], -1)
flipped = np.ascontiguousarray(np.flipud(image) )
writer.send(flipped)
writer.close()
result
WARNING:imageio_ffmpeg:No frames have been written; the written video is invalid.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[<ipython-input-7-915cb117e138>](https://localhost:8080/#) in <cell line: 14>()
13
14 for frame in reader:
---> 15 image = np.frombuffer(frame, np.uint8).reshape(meta.size[1], meta.size[0], -1)
16 flipped = np.ascontiguousarray(np.flipud(image))
17 writer.send(flipped)
AttributeError: 'dict' object has no attribute 'size'
best regards
Ah, I should've said meta['size']
:)
objective have image filter effect
code
result
any idea how to face this error ?
best regards