1.打印数据相关信息(音频时长等)
ffprobe -of xml -show_data xxx.mp3
# -of xml,指定输出格式为xml,也可指定为XML、INI、JSON、CSV、FLAT等格式
2.获取音频时长(借助第1步的命令)
def get_audio_time(filename):
# ffprobe -show_data xxx.mp3
command_str = 'ffprobe -show_data '+filename
print(command_str)
flag, res = subprocess.getstatusoutput(command_str)
if flag != 0:
print("Error: get_audio_time", filename)
reses = res.split('\n')
du = ''
for i in reses:
line = i.strip()
if line.startswith('Duration'):
print("Duration: ", line.split(',')[0].split(':')[1:])
du = ':'.join(line.split(',')[0].split(':')[1:])
break
return du.strip()
ref:
https://www.jianshu.com/p/e14bc2551cfd