[英]h.264 encoding directly from numpy
I want to directly encode videos from numpy arrays of video frames.我想直接从 numpy 视频帧数组中编码视频。 Open-cv offers such functionality via the cv2.VideoWriter
, however I need the h.264 codec which is not available. Open-cv 通过cv2.VideoWriter
提供此类功能,但是我需要不可用的 h.264 编解码器。 The best I have so far is using open-cv to write the video and then reencode it via:到目前为止,我最好的方法是使用 open-cv 编写视频,然后通过以下方式重新编码:
# write video from numpy arrays via cv2
out = cv2.VideoWriter("/tmp/video.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, size)
for frame in frames:
out.write(frame)
out.release()
# reencode video with ffmpeg
os.system("ffmpeg -y -i /tmp/video.mp4 -vcodec libx264 /tmp/video2.mp4")
However, I think that the first encoding is not loss less, so I am instead looking for a solution where I can directly encode videos from python.但是,我认为第一个编码的损失并不小,所以我正在寻找一种可以直接从 python 编码视频的解决方案。
Thanks for your help!谢谢你的帮助!
scikit-video provides the feature: scikit-video 提供了以下功能:
import skvideo.io
outputfile = "/tmp/video.mp4"
writer = skvideo.io.FFmpegWriter(outputfile, outputdict={'-vcodec': 'libx264'})
for frame in frames:
writer.writeFrame(frame)
writer.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.