如何设置时间间隔以从输入视频中获取帧?
How to set time interval to get frames from input video?
我正在尝试从特定时间的输入视频中获取帧 interval.so 向我建议任何对 me.Tell 我如何在以下代码中设置时间限制有帮助的解决方案。
import cv2
vidcap = cv2.VideoCapture('baahubali2.mp4')
vidcap.set(cv2.CAP_PROP_POS_MSEC,1000)
success, image = vidcap.read()
count = 0
success = True
while success:
success, image = vidcap.read()
print('Read a new frame: ', success)
cv2.imwrite("/home/kapil/Documents/major/image/frame%d.jpg" % count, image)
count += 1
这是一种解决方案:
import cv2
start_time_ms = 1000
stop_time_ms = 2000
vidcap = cv2.VideoCapture('baahubali2.mp4')
count = 0
success = True
while success and vidcap.get(cv2.cv.CV_CAP_PROP_POS_MSEC) < start_time_ms:
success, image = vidcap.read()
while success and vidcap.get(cv2.cv.CV_CAP_PROP_POS_MSEC) <= stop_time_ms:
success, image = vidcap.read()
print('Read a new frame: ', success)
cv2.imwrite("/home/kapil/Documents/major/image/frame%d.jpg" % count, image)
count += 1
开始和停止时间以毫秒为单位指定。在 start_time_ms
之前读取帧什么也不做,然后将帧作为图像写入,直到 stop_time_ms
或视频结束。
import cv2
start_time_ms = 120000
stop_time_ms = 150000
vidcap = cv2.VideoCapture('/content/Players Hunting on Neymar Lionel Messi
Cristiano Ronaldo ● Horror Fouls & Tackles HD.mp4')
count = 0
success = True
vidcap.set(cv2.CAP_PROP_POS_MSEC,start_time_ms)
while success and vidcap.get(cv2.CAP_PROP_POS_MSEC) <= stop_time_ms:
success, image = vidcap.read()
print('Read a new frame: ', success)
cv2.imwrite("/content/image/frame%d.jpg" % count, image)
count += 1
这是我用来获取输出的解决方案,我认为它会有所帮助
import cv2
import os
cap = cv2.VideoCapture(vidoname)
time_skips = float(2000) #skip every 2 seconds. You
need to modify this
count = 0
success,image = cap.read()
while success:
cv2.imwrite("frame%d.jpg" % count, image)
cap.set(cv2.CAP_PROP_POS_MSEC,
(count*time_skips))
# move the time
success,image = cap.read()
count += 1
# release after reading
cap.release()
我正在尝试从特定时间的输入视频中获取帧 interval.so 向我建议任何对 me.Tell 我如何在以下代码中设置时间限制有帮助的解决方案。
import cv2
vidcap = cv2.VideoCapture('baahubali2.mp4')
vidcap.set(cv2.CAP_PROP_POS_MSEC,1000)
success, image = vidcap.read()
count = 0
success = True
while success:
success, image = vidcap.read()
print('Read a new frame: ', success)
cv2.imwrite("/home/kapil/Documents/major/image/frame%d.jpg" % count, image)
count += 1
这是一种解决方案:
import cv2
start_time_ms = 1000
stop_time_ms = 2000
vidcap = cv2.VideoCapture('baahubali2.mp4')
count = 0
success = True
while success and vidcap.get(cv2.cv.CV_CAP_PROP_POS_MSEC) < start_time_ms:
success, image = vidcap.read()
while success and vidcap.get(cv2.cv.CV_CAP_PROP_POS_MSEC) <= stop_time_ms:
success, image = vidcap.read()
print('Read a new frame: ', success)
cv2.imwrite("/home/kapil/Documents/major/image/frame%d.jpg" % count, image)
count += 1
开始和停止时间以毫秒为单位指定。在 start_time_ms
之前读取帧什么也不做,然后将帧作为图像写入,直到 stop_time_ms
或视频结束。
import cv2
start_time_ms = 120000
stop_time_ms = 150000
vidcap = cv2.VideoCapture('/content/Players Hunting on Neymar Lionel Messi
Cristiano Ronaldo ● Horror Fouls & Tackles HD.mp4')
count = 0
success = True
vidcap.set(cv2.CAP_PROP_POS_MSEC,start_time_ms)
while success and vidcap.get(cv2.CAP_PROP_POS_MSEC) <= stop_time_ms:
success, image = vidcap.read()
print('Read a new frame: ', success)
cv2.imwrite("/content/image/frame%d.jpg" % count, image)
count += 1
这是我用来获取输出的解决方案,我认为它会有所帮助
import cv2
import os
cap = cv2.VideoCapture(vidoname)
time_skips = float(2000) #skip every 2 seconds. You
need to modify this
count = 0
success,image = cap.read()
while success:
cv2.imwrite("frame%d.jpg" % count, image)
cap.set(cv2.CAP_PROP_POS_MSEC,
(count*time_skips))
# move the time
success,image = cap.read()
count += 1
# release after reading
cap.release()