I'm very new to codecs. I have 100 frames and I want to convert them into a video using H265 encoder. previously I tried with h264 and video generated with file size 2.5MB. Now when I tried with hvc1 and the output video file is much bigger(65MB). I also tried with hev1 still getting the same 65MB file. But heard that h265 will generate a lesser file compared to h264. Can anyone help me with this problem?
import cv2
import os
import re
image_folder = 'backend/data'
video_name = 'backend/h265/output.mp4'
images = [img for img in os.listdir(image_folder) if img.endswith(".jpg")]
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
return [
int(text)
if text.isdigit() else text.lower()
for text in _nsre.split(s)]
sorted_images = sorted(images, key=natural_sort_key)
frame = cv2.imread(os.path.join(image_folder, sorted_images[0]))
height, width, layers = frame.shape
fourcc = cv2.VideoWriter_fourcc(*'hev1') #hvc1 and hev1 are two codec ids of hevc
video = cv2.VideoWriter(video_name, fourcc, 27, (width,height))
for image in sorted_images:
video.write(cv2.imread(os.path.join(image_folder, image)))
cv2.destroyAllWindows()
video.release()
am I using the correct codec ids of hevc for in this code?