# Encode the frame as jpeg, tiff, webp image
# Set the quality (optional)
encode_param_jpeg = [int(cv2.IMWRITE_JPEG_QUALITY), 50]
result_jpeg, encimg_jpeg = cv2.imencode('.jpg', frame, encode_param_jpeg)
#tiff
encode_param_tiff = [int(cv2.IMWRITE_TIFF_COMPRESSION), 50]
result_tiff, encimg_tiff = cv2.imencode('.tif', frame)
#webp
encode_param_webp = [int(cv2.IMWRITE_WEBP_QUALITY), 50]
result_webp, encimg_webp = cv2.imencode('.webp', frame, encode_param_webp)
print("frame size: ", frame.shape)
# #avif
# encode_param_avif = [int(cv2.IMWRITE_AVIF_QUALITY), 50]
# result_avif, encimg_avif = cv2.imencode('.avif', frame, encode_param_avif)
#comparethe size of the frame and encoded image
print("jpeg size: ", len(encimg_jpeg))
print("tiff size: ", len(encimg_tiff))
print("webp size: ", len(encimg_webp), "\n")
# decode the jpeg encoded image
decimg_jpeg = cv2.imdecode(encimg_jpeg, 1)
decimg_tiff = cv2.imdecode(encimg_tiff, 1)
decimg_webp = cv2.imdecode(encimg_webp, 1)
# merge the images side by side
merged_image = np.hstack((decimg_jpeg, decimg_tiff, decimg_webp))
# Display the frame
cv2.imshow('frame', merged_image)
cv2.waitKey(1) # Adjust as needed to display the frame
I am trying to reduce the amount of data in video transmission.
If you try to compress the image with the AVIF codec by activating lines 29-30 in the above code, the following error occurs.