用于分割视频的Python库
我需要把一个很大的视频文件按时间分割成几个小片段。请给我一些建议,如果可以的话,也请分享一些使用库的技巧。谢谢!
2 个回答
1
你可以看看youtube-upload这个工具,它可以用ffmpeg来分割视频。
Youtube-upload是一个命令行脚本,用来把视频上传到Youtube。如果你的视频超过了Youtube的限制(比如大于2GB或者超过15分钟),它会在上传之前自动把视频分割开。这个工具在任何能运行Python和FFmpeg的平台上都能使用,比如GNU/Linux、BSD、OS X和Windows等。
8
OpenCV 有 Python 的封装。
如果你对视频输入输出感兴趣,可以看看 QueryFrame 以及相关的函数。
最后,你的代码大概会像这样(完全没有测试过):
import cv
capture = cv.CaptureFromFile(filename)
while Condition1:
# Need a frame to get the output video dimensions
frame = cv.RetrieveFrame(capture) # Will return None if there are no frames
# New video file
video_out = cv.CreateVideoWriter(output_filenameX,
CV_FOURCC('M','J','P','G'), capture.fps, frame.size(), 1)
# Write the frames
cv.WriteFrame(video_out, frame)
while Condition2:
# Will return None if there are no frames
frame = cv.RetrieveFrame(capture)
cv.WriteFrame(video_out, frame)
顺便说一下,还有一些方法可以 不写任何代码 来实现这个功能。