2

I need to compare 2 videos to check whether they are the same.

So I am planning to do the following:

  1. Split both the videos into individual frames
  2. Compare each frame with the corresponding frame of the ref video using Python Image Lib
  3. Count the number of different frames to decide whether they are same.

I would like to know whether there is any function in Python to help me with the first step, i.e., to split the video into individual frames. I do not want to use ffmpeg to do the splitting.

Thanks in advance for the help

Anju
  • 631
  • 2
  • 9
  • 25

2 Answers2

2

You can use opencv

import cv2
video_capture = cv2.VideoCapture("rtsp://admin:admin@192.168.0.94:554/stream3")


while True:
    # get frame by frame
    ret, frame = video_capture.read()
    cv2.imwrite('pic.png',frame)
    cv2.imshow('Video', frame)
mtt2p
  • 1,818
  • 1
  • 15
  • 22
  • I have tests where the streams would be long enough (like 4 hours or above). Will this method be apt in that scenario? Or is there a better option? – Mridula Madhusudan Feb 20 '15 at 09:59
  • Sorry if I'm asking a simple question.. But I'm a newbie to python and OpenCV. But what does the following line do? video_capture = cv2.VideoCapture("rtsp://admin:admin@192.168.0.94:554/stream3") – Mridula Madhusudan Feb 20 '15 at 10:06
  • This does not work. If I change it to save for every loop, it just makes thousands of blank images. – Rontron Oct 23 '15 at 20:32
0

Try this:

currentFrame = 0
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Saves image of the current frame in jpg file
    name = './data/frame' + str(currentFrame) + '.jpg'
    print ('Creating...' + name)
    cv2.imwrite(name, frame)

    # To stop duplicate images
    currentFrame += 1

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

#you can use this method
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
holla
  • 141
  • 1
  • 9