imageio / imageio-ffmpeg

FFMPEG wrapper for Python
BSD 2-Clause "Simplified" License
221 stars 50 forks source link

image output is broken #104

Closed sugizo closed 4 months ago

sugizo commented 4 months ago

code

from PIL import Image
from imageio_ffmpeg import read_frames, write_frames

def rotate_90(image):
    img = Image.frombytes("RGB", (meta['size'][0], meta['size'][1] ), image)
    im = img.transpose(Image.ROTATE_90)
    return np.ascontiguousarray(im)

video_file = 'merge_audio_ffmpeg.mp4'
fps_v = '10' # 60 for production
output_file = 'rotate_90.mp4'

reader = read_frames(video_file)
meta = reader.__next__()

writer = write_frames(output_file, audio_path = video_file,
                      size = meta['size'], fps = meta['fps'],
                      input_params = ['-y', ],
                      output_params = ['-r', fps_v, ] )
writer.send(None)

for frame in reader:
    filter = rotate_90(frame)
    writer.send(filter)

writer.close()

IPython.display.Video(output_file, embed = True)

result not expected

https://github.com/imageio/imageio-ffmpeg/assets/2418295/e50f9046-092e-45d2-aabd-59c7b4c0271d

expected result output video rotated 90 degree

how to achieve it using imageio-ffmpeg ?

best regards

almarklein commented 4 months ago

I suspect there's something off with the shapes of the frames. I'd recommend reading one frame and checking its shape and appearance at each step, to see where it goes wrong.