7

I want to get the volume of sound of a video so I use the following:

import numpy as np # for numerical operations
from moviepy.editor import VideoFileClip, concatenate

clip = VideoFileClip("soccer_game.mp4")
cut = lambda i: clip.audio.subclip(i,i+1).to_soundarray(fps=22000)
volume = lambda array: np.sqrt(((1.0*array)**2).mean())
volumes = [volume(cut(i)) for i in range(0,int(clip.audio.duration-2))] 

But I get these errors:

Exception AttributeError: "VideoFileClip instance has no attribute 'reader'" in <bound method VideoFileClip.__del__ of <moviepy.video.io.VideoFileClip.VideoFileClip instance at 0x084C3198>> ignored

WindowsError: [Error 5] Access is denied

I am using IPython notebook and Python 2.7. I assume something doesn't have the appropriate permissions. I have changed run this program as an administrator for ffmpeg.exe, ffplay.exe, ffprobe.exe.

IordanouGiannis
  • 4,149
  • 16
  • 65
  • 99

2 Answers2

2

I fixed a bug today that may have caused your problem, would you mind upgrading and trying again ? If it still doesn't work, I'll need to know your windows version.

Zulko
  • 3,540
  • 1
  • 22
  • 18
0

Rather than doing own calculations, I would recommend to use an existing library or tool that considers the human-perceived loudness.

For example, ffmpeg can measure the loudness based on the EBU R 128 recommendation (in LUFS).

This discussion recommends pyloudnorm.

Gerd
  • 2,568
  • 1
  • 7
  • 20