Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quality Loss In ImageIO

I have a series of high resolution images I want to convert to an MP4 file in Python(3.6) using ImageIO. Is there any way I can do it without compression or losing quality?

Currently I use the code :

fileList = []
path = "./Images/MP4/relu-3layers-32units-M1/"
name = "img"
for file in os.listdir(path):
    if file.startswith(name):
        complete_path = path + file
        fileList.append(complete_path)

 writer = imageio.get_writer('test.mp4', fps = 30)

 for im in fileList:
      writer.append_data(imageio.imread(im))
 writer.close()

It generates the video, but the quality is substantially reduced. Any way to fix this?

like image 663
Zohair Avatar asked Oct 23 '18 12:10

Zohair


1 Answers

For the best possible result, pick a proper codec like 'libx264' or 'mjpeg', definitely pick the maximum video quality, and possibly a pixel format like 'yuvj444p':

writer = imageio.get_writer('test.mp4', fps = 30,
    codec='mjpeg', quality=10, pixelformat='yuvj444p')

Codec mjpeg is suitable for jpg images. The default imageio choice libx264 should also work great (and probably make smaller videos), but I understand that it may be missing in the system.

Quality 10 is the top possible quality for any codec. The range is 0-10.

Finally, the pixel format yuvj444p (or yuv444p) records all three channels with the full resolution. Other options like yuvj420p and yuvj422p reduce the quality in "u" and/or "v" channels, and it should also be ok for regular images.

like image 199
etoropov Avatar answered Sep 22 '22 13:09

etoropov