Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

How do I get one random frame from an mp4 video in Python?

$
0
0

I have an mp4 video in my directory that I need to capture one random frame from in Python. How can I go about doing that?

I'm currently using this code, but it's grabbing the first frame. I need it to randomly pick out of all the frames.

mp4_directory = 'video.mp4'frames = 324000random_frame = random.randrange(0, frames)vidcap = cv2.VideoCapture(mp4_directory)success,image = vidcap.read()count = random_frame - 1while count < random_frame:    cv2.imwrite("frame%d.jpg" % count, image)     # save frame as JPEG file          success,image = vidcap.read()    print('Read a new frame: ', success)    count += 1

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>