直接从 numpy 进行 h.264 编码
h.264 encoding directly from numpy
我想直接对来自 numpy 视频帧数组的视频进行编码。 Open-cv 通过 cv2.VideoWriter
提供了这样的功能,但是我需要 h.264 编解码器,它不可用。到目前为止,我最好的方法是使用 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")
但是,我认为第一次编码并没有减少损失,所以我正在寻找一种可以直接编码来自 python 的视频的解决方案。
感谢您的帮助!
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()
我想直接对来自 numpy 视频帧数组的视频进行编码。 Open-cv 通过 cv2.VideoWriter
提供了这样的功能,但是我需要 h.264 编解码器,它不可用。到目前为止,我最好的方法是使用 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")
但是,我认为第一次编码并没有减少损失,所以我正在寻找一种可以直接编码来自 python 的视频的解决方案。
感谢您的帮助!
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()