简体   繁体   English

直接从 numpy 编码 h.264

[英]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.

相关问题 从rtsp H.264视频流捕获单张图像 - Capturing a SINGLE image from an rtsp H.264 video stream 视频转换:h.264从UDP套接字到Mat对象 - Video conversion: h.264 from a UDP socket to a Mat object 使用来自 pi 相机的 python 解码并显示 H.264 卡盘视频序列 - decode and show H.264 chucked video sequence with python from pi camera 在h.264中以低延迟从Python中的opencv流rtsp视频 - Stream rtsp video from opencv in python in h.264 with low latency 使用 websocket 从 h.264 视频流中捕获第一张图像 - Python - Capture first image from h.264 video streaming using websocket - Python 如何从 python 上的 wifi 摄像头压缩格式:h.264 获取 http stream? - How to get http stream from wifi camera compressed format: h.264 on python? Django,使用FileWrapper传输H.264视频(HTML5) - Django, streaming H.264 video with FileWrapper (HTML5) 如何使用 FFmpeg 从视频中剪切/删除特定的未解码 h.264(关键)帧? - How can I cut/drop specific undecoded h.264 (Key-)frames from a video using FFmpeg? 如何使用h.264参考软件在Python中提取运动矢量 - How to use h.264 Reference Software to extract motion vectors in Python 如何使用 pyav 或 opencv 对原始 H.264 数据的实时 stream 进行解码? - How to use pyav or opencv to decode a live stream of raw H.264 data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM