简体   繁体   English

获取音频python ffmpeg

[英]Get audio frequency python ffmpeg

I need to get audio frequency from a flac file and save it in a variable. 我需要从flac文件获取音频频率并将其保存在变量中。

I know the ffmpeg approach allowing to display info about the file: 我知道ffmpeg方法可以显示有关文件的信息:

print(os.system('ffmpeg -i '+ file_path + ' -hide_banner'))

The result looks like this: 结果看起来像这样:

  Duration: 00:00:11.12, start: 0.000000, bitrate: 134 kb/s
    Stream #0:0: Audio: flac, 16000 Hz, mono, s16

So the output shows the frequency, but what would be a good method to retrieve only the value of 16000 to save it in a variable? 因此输出显示了频率,但是什么是仅检索16000的值并将其保存在变量中的好方法呢?

Using pydub : 使用pydub

>>> from pydub import AudioSegment
>>> song = AudioSegment.from_mp3(file_path)
>>> song.frame_rate
48000
from pydub.utils import mediainfo

inf = mediainfo(file_path)
print(inf['sample_rate'])

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

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