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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With