0

I'm trying to write a function that detect all abnormal shot sound in a audio file extracted from the video file using moviepy. The result should be a dataframe that contains the frame count of video and in each frame whether an abnormal shot is detected. The wave form of an example of the audio file is shown in the photo:

sound wav

I wrote this following function but it predicts all frame to be not abnormal shot detected.This is wrong because at some frame there must be an amplitude that bigger than the 0.25t threshold. What is wrong with my code. I've checked the audio rate is 44100 and frame rate is 25.

def create_shot(PATH):
  rate=44100
  signal=VideoFileClip(PATH).audio.to_soundarray() #audio.to_soundarray normalize the amplitude
    
  signal=signal[:,0] #dual channel are identical so only select the first channel
  length = len(signal) / rate
  threshold=0.25 #manually set threshold, use 0.25 by analyzing the plotted normalized amplitude


   # downsample to match video frame rate
  downsampling_factor = int(rate / 25)
  signal = signal[::downsampling_factor]
  print(len(signal))
  # detect shots based on amplitude threshold
  shot_detected = (abs(signal) >= threshold).astype(int)
  
  # create pandas dataframe with shot detections
  shot = pd.DataFrame({'frame_count': range(1,len(shot_detected)+1),'shot_detected': shot_detected,'signal':signal})
  
  return shot

Thanks for any help.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
iw2fs
  • 19
  • 1
  • "abnormal shot" is defined to be those with high soundlevels? – Jon Nordby May 10 '23 at 19:55
  • Yes. what i want to get is a list of boolean value represents in each frame of the video whether the soundlevels are higher than a threshold but it fails to detect that. – iw2fs May 18 '23 at 03:29

0 Answers0