Saving images to PNG first seems to produce different ffmpeg encodes. Running this test code
from PIL import Image
import cv2
import ffmpeg
import hashlib
ffmpeg.input('test.jpg').output('testff.png').run()
cv2.imwrite('testcv.png',cv2.imread('test.jpg'))
Image.open('test.jpg').save('testpil.png')
hashes=[]
for suf in ['.jpg','ff.png','cv.png','pil.png']:
dest='test'+suf.replace('.','')+'.mp4'
ffmpeg.input('test'+suf).output(dest).run()
hashes.append(hashlib.file_digest(open(dest,'rb'),'md5').hexdigest())
print(hashes)
I get
['a5b744a8ac0f6de9ec4de43ff737c46e'
,'ab62474f2160899e064ba24890047372'
,'baa788d5e4ef212ab610b8b5cf7772cb'
,'baa788d5e4ef212ab610b8b5cf7772cb']
As you can see, the only two that match are the cv2 and pillow conversions, and none of them match the original. In terms of file size, the results that passed to png first seem to be about 10% smaller than the direct-from-jpg result.
Why is this happening and how can I avoid changing image data until I'm ready to encode?