我尝试使用 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/