Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get frames with timestamp where frames are converted from video in python

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
like image 395
amaresh hiremani Avatar asked Jul 02 '18 05:07

amaresh hiremani


People also ask

What is frame timestamp?

The time at which the frame was captured.


1 Answers

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)
like image 50
amaresh hiremani Avatar answered Sep 21 '22 10:09

amaresh hiremani