欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ffprobe/ffmpeg音频操作入门

程序员文章站 2022-03-15 15:02:20
打印数据相关信息(音频时长等)ffprobe -of xml -show_data xxx.mp3# -of xml,指定输出格式为xml,也可指定为XML、INI、JSON、CSV、FLAT等格式ref:https://www.jianshu.com/p/e14bc2551cfd...

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

本文地址:https://blog.csdn.net/u010212101/article/details/110928540