python-3.x - 如何使用 H265 编码视频?
问题描述
我对编解码器很陌生。我有 100 帧,我想使用 H265 编码器将它们转换为视频。以前我尝试过使用 h264 和文件大小为 2.5MB 的视频。现在,当我尝试使用 hvc1 并且输出视频文件更大(65MB)时。我还尝试使用 hev1 仍然获得相同的 65MB 文件。但是听说h265比h264生成的文件要小一些。谁能帮我解决这个问题?
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()
我是否在此代码中使用了正确的 hevc 编解码器 ID?
解决方案
推荐阅读
- javascript - 无法使用 webpack 在 GitHub Actions 中构建生产环境
- reporting-services - 自上次在 SSRS 中执行以来查询已更改
- php - 如何在 Laravel 中连接两个表
- java - Java 和 Python 合并排序
- javascript - Webpack 不会用 background-image 编译我的 SASS
- python - 类型错误:create_superuser() 缺少 2 个必需的位置参数:“first_name”和“last_name”
- assembly - Nasm - 程序如何跟踪哪个寄存器存储了负值或正值
- javascript - 作为本练习的解决方案,这两个循环之间的主要区别是什么?(学习javascript)
- clojure - 如何从clojure访问moa分类器中hoeffding树的treeRoot字段[受保护]
- python - 将简单的几何图形导出到 gltf?