简体   繁体   English

如何使用moviepy在Python中获取视频的音量?

[英]How can I get the volume of sound of a video in Python using moviepy?

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.我正在使用 IPython 笔记本和 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.我更改了以管理员身份运行该程序的 ffmpeg.exe、ffplay.exe、ffprobe.exe。

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.如果它仍然不起作用,我需要知道你的 windows 版本。

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 ).例如, ffmpeg 可以根据EBU R 128 建议(在LUFS中)测量响度。

This discussion recommends pyloudnorm . 这个讨论推荐pyloudnorm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM