I want to convert video into the frames before feeding it to the classification model. So I need frames on every unique timestamp converted from video here timestamp is the seconds in the video. The following code from opencv lets me convert for every 10 capturing of the frames but I need the timestamp of each frame in the video. Please let me know thanks
import cv2
vidcap = cv2.VideoCapture('testing.mp4');
success,image = vidcap.read()
count = 0
success = True
while success:
success,image = vidcap.read()
print('read a new frame:',success)
if count%10 == 0 :
cv2.imwrite('frame%d.jpg'%count,image)
print('success')
count+=1
The time at which the frame was captured.
Here first we have to get the FPS of the video and then capture the frames using opencv by incrementing the count variable. Then count variable/ fps of the video gives the time stamp of each frames in the video.
import cv2
vidcap = cv2.VideoCapture('testing.mp4')
fps = vidcap.get(cv2.CAP_PROP_FPS)
success,image = vidcap.read()
count = 0
success = True
while success:
success,frame = vidcap.read()
count+=1
print("time stamp current frame:",count/fps)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With