2

I was looking at a real time problem where we need to eliminate the redundant frames of a video.(May be a video with lyrics of a song) In my example, lyrics video song, we are not concerned about the audio. Only frames containing the lyrics. but the thing is 2 line of lyrics my end up with 20seconds ending up with multiple frames having the same lyrics. So I was interested in eliminating those redundant frames.

While searching, I have found this code to extract frames from a video by this - Python - Extracting and Saving Video Frames

 import cv2
 vidcap = cv2.VideoCapture('Compton.mp4')
 success,image = vidcap.read()
 count = 0
 success = True
 while success:
 success,image = vidcap.read()
 cv2.imwrite("frame%d.jpg" % count, image)     # save frame as JPEG file
 if cv2.waitKey(10) == 27:                     # exit if Escape is hit
  break
 count += 1

Can you please help me how to proceed in order to eliminate the redundant frames from here on.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
Arjun
  • 45
  • 1
  • 1
  • 8

2 Answers2

1

I have had some luck in removing redundant frames in video streams using pyscene detect

I'm gonna add the relevant method which you might find interesting -

Content-Aware Detector

The content-aware scene detector (-d content) works the way most people think of "cuts" between scenes in a movie - given two frames, do they belong to the same scene, or different scenes? The content-aware scene detector finds areas where the difference between two subsequent frames exceeds the threshold value that is set (a good value to start with is --threshold 30).

This allows you to detect cuts between scenes both containing content, rather than how most traditional scene detection methods work. With a properly set threshold, this method can even detect minor, abrupt changes, such as jump cuts in film.

Thalish Sajeed
  • 1,351
  • 11
  • 25
0

If you just need the frames(jpegs)then you can use ffmpeg video filter option and extract the frames at a given frame rate(fps)

ffmpeg -i "Compton.mp4" -vf fps=1 frame%04d.jpg -hide_banner

This will extract one frame a second. You can tweak it based on how frequently your lyrics change in the video.

If you want to use it in python then ffmpeg-python is a great tool.

Hope it helps.

Gatothgaj
  • 1,633
  • 2
  • 16
  • 27
  • 1
    i don't want to manually set the frequency of taking frames, becz each song will have a different one right? instead i thought i could have a code to do some comparison from the frames produced. (i hope my intention is in right direction) – Arjun Jul 31 '18 at 07:43