Anmol Monga
Anmol Monga

Reputation: 321

How to get frames from video using python 3.5

I am try to get frames with OpenCV but its not working with python 3.5.

I used the following code,this is working fine with python 2.7 but not with 3.5 :

import cv2
vidcap = cv2.VideoCapture('myvideo.mp4')
success,image = vidcap.read()
success = True
while success:
  success,image = vidcap.read()
  # print 'Read a new frame: ', success
  cv2.imwrite("frame%d.jpg" % count, image)   # save frame as JPEG 

is there changes in syntax.?? Thanks

Upvotes: 1

Views: 1420

Answers (1)

Anmol Monga
Anmol Monga

Reputation: 321

Install ffmpeg using:

sudo apt-get install ffmpeg

and then install ffmpy:

pip3 install ffmpy

import ffmpy

ff = ffmpy.FFmpeg(inputs={'path_of_video.mp4':None },outputs={'frame.jpg': '-ss 00:00:02 -t 00:00:2 -s 400x400 -r 1 -f mjpeg'})

ff.run()

Upvotes: 1

Related Questions