python - FFMPEG Loudnorm 读取 JSON 数据

标签 python audio ffmpeg

我尝试使用 FFMPEG Loudnorm 规范化一些音频文件,如 here 所述。 .
但是,在 Python 中,我不明白如何从第一遍读取数据信息。
我的代码:

getLoud =  subprocess.Popen(f"ffmpeg -i {file_path} -filter:a loudnorm=print_format=json -f null NULL", shell=True, stdout=subprocess.PIPE).stdout
getLoud =  getLoud.read().decode()
# parse json_str:
jsonstr_loud = json.loads(getLoud)
这给了我"errorMessage": "Expecting value: line 1 column 1 (char 0)"我也试过这个:
os.system(f"ffmpeg -i {file_path} -filter:a loudnorm=print_format=json -f null NULL")
它输出:
ffmpeg version N-60236-gffb000fff8-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2022 the FFmpeg developers...
...
[Parsed_loudnorm_0 @ 0x5921940] 
{
    "input_i" : "-9.33",
    "input_tp" : "-0.63",
    "input_lra" : "0.60",
    "input_thresh" : "-19.33",
    "output_i" : "-24.08",
    "output_tp" : "-15.40",
    "output_lra" : "0.60",
    "output_thresh" : "-34.08",
    "normalization_type" : "dynamic",
    "target_offset" : "0.08"
}
在 Python 中,如何使用这些参数,例如 input_i , input_tp等等,我需要第二次通过吗?
我无法使用 ffmpeg-normalize因为我在 Lambda 中使用 FFMPEG 作为图层。

最佳答案

有点 hacky,可能是片状的,但我这样做了,它已经以每小时 1GB 的速度插入,至少 24 小时没有问题。

first_step_output = subprocess.run(
    "ffmpeg "
    f"-i \"{full_path}\" "
    "-af loudnorm=print_format=json "
    "-f null "
    "-",
    shell=True,
    stderr=subprocess.PIPE
)
if first_step_output.returncode == 0:
    output = json.loads(
        "{" + first_step_output.stderr.decode().split("{")[1]
    )

关于python - FFMPEG Loudnorm 读取 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71791529/

相关文章:

c# - 控制谁可以使用XP中的音频输出 channel

ios - iPhone 上不显示音频播放锁屏控件

php - ffmpeg 在本地主机上的 wamp 中设置

ffmpeg - 如何使用 ffmpeg 确定传入 RTMP 流的分辨率?

多次执行 Python 脚本运行速度变慢

python - 在带有 django-rest-framework 的过滤器中使用自定义方法

python - 比 if-elif 语句更快

python - 在 python 中循环遍历列表

c++ - 为什么我缺少 Qt 多媒体功能?

c - 如何在 C/C++ 中设置 ffmpeg qscale 进行图像编码