If you are using VideoWriter to write out the video file with frames you get from im2frame, use an uncompressed or lossless compression profile. The default 'Motion JPEG AVI' profile and any MPEG-4 profile will have a quality parameter that typically allows for improved compression at the expense of artifacts or blurring of edges.
'Archival'
Motion JPEG 2000 file with lossless compression
'Motion JPEG AVI'
AVI file using Motion JPEG encoding
'Motion JPEG 2000'
Motion JPEG 2000 file
'MPEG-4'
MPEG-4 file with H.264 encoding (systems with Windows 7 or later, or macOS 10.7 and later)
'Uncompressed AVI'
Uncompressed AVI file with RGB24 video
'Indexed AVI'
Uncompressed AVI file with indexed video
'Grayscale AVI'
Uncompressed AVI file with grayscale video