gpt4 book ai didi

python - 通过仅拍摄某些帧但不将其写入文件来从另一个视频创建视频

转载 作者:行者123 更新时间:2023-12-02 17:52:19 25 4
gpt4 key购买 nike

我这里有一个奇怪的问题!

我的文件中有视频。我想从该视频中提取一些帧,然后从中提取视频,然后用它来显示(注意:我不想为此使用imshow())。我想做到这一点而不将其写入文件中。

Algorithm:
1. Read the video from file
2. extract the frames
3. make a video out of these frames(save it as a variable; do not write it into a file)
4. Use this variable which holds the new video for displaying

任何建议都会有很大帮助!

最佳答案

创建一个cap = cv2.VideoCapture(file_name)。通过获取电影的宽度和高度

h = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
w = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)

创建一个numpy数组
frames = np.zeros((h, w, 3, number_of_frames), np.uint8)

并将要保留的帧保存到此数组:
error, frame = cap.read()
frames[:,:,:,i] = frame

如果您不知道事先拥有多少帧,只需将它们串联在Python列表中即可。

然后,显示您的框架。

关于python - 通过仅拍摄某些帧但不将其写入文件来从另一个视频创建视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17877755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com