如何使用 FFmpeg 获取最终的 LUF 值?

如何使用 FFmpeg 获取最终的 LUF 值?

我正在使用 FFmpeg 从音频文件中获取 LUF 值,但得到了大量的输出。我只想要输出底部附近的最终集成阈值 LUF 值,并且使用 grep 和 regex 取得了一些成功,但我想知道是否有更好的方法只使用 FFmpeg?

这是我使用的命令:

ffmpeg -i test.mp4 -hide_banner -filter_complex ebur128 -f null -

输出为:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:05.02, start: 0.000000, bitrate: 780 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 644 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
[Parsed_ebur128_0 @ 0x7feb18604000] Summary:

  Integrated loudness:
    I:         -70.0 LUFS
    Threshold:   0.0 LUFS

  Loudness range:
    LRA:         0.0 LU
    Threshold:   0.0 LUFS
    LRA low:     0.0 LUFS
    LRA high:    0.0 LUFS
Stream mapping:
  Stream #0:1 (aac) -> ebur128 (graph 0)
  ebur128 (graph 0) -> Stream #0:0 (pcm_s16le)
  Stream #0:0 -> #0:1 (h264 (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.0999792  M:-120.7 S:-120.7     I: -70.0 LUFS     LRA:   0.0 LU
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.12.100
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      encoder         : Lavc58.18.100 pcm_s16le
    Stream #0:1(und): Video: wrapped_avframe, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      encoder         : Lavc58.18.100 wrapped_avframe
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.199979   M:-120.7 S:-120.7     I: -70.0 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.299979   M:-120.7 S:-120.7     I: -70.0 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.399979   M: -27.5 S:-120.7     I: -27.5 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.499979   M: -27.9 S:-120.7     I: -27.7 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.599979   M: -31.9 S:-120.7     I: -28.7 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.699979   M: -34.8 S:-120.7     I: -29.6 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.799979   M: -38.1 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.899979   M: -46.6 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 0.999979   M: -49.5 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.09998    M: -57.2 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.19998    M: -58.1 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.29998    M: -58.6 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.39998    M: -58.8 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.49998    M: -58.7 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.59998    M: -51.9 S:-120.7     I: -30.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.69998    M: -33.7 S:-120.7     I: -30.8 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.79998    M: -26.0 S:-120.7     I: -29.7 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.89998    M: -22.4 S:-120.7     I: -27.8 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 1.99998    M: -22.0 S:-120.7     I: -26.6 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.09998    M: -21.1 S:-120.7     I: -25.7 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.19998    M: -21.9 S:-120.7     I: -24.8 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.29998    M: -24.5 S:-120.7     I: -24.7 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.39998    M: -23.4 S:-120.7     I: -24.6 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.49998    M: -22.8 S:-120.7     I: -24.4 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.59998    M: -21.5 S:-120.7     I: -24.2 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.69998    M: -20.0 S:-120.7     I: -23.7 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.79998    M: -19.3 S:-120.7     I: -23.3 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.89998    M: -20.2 S:-120.7     I: -23.0 LUFS     LRA:   0.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 2.99998    M: -21.6 S: -24.8     I: -22.7 LUFS     LRA:  20.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.09998    M: -24.3 S: -24.8     I: -22.8 LUFS     LRA:  20.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.19998    M: -32.7 S: -25.0     I: -23.2 LUFS     LRA:  20.1 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.29998    M: -28.6 S: -24.8     I: -23.3 LUFS     LRA:  20.1 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.39998    M: -27.0 S: -24.8     I: -23.4 LUFS     LRA:   0.2 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.49998    M: -26.3 S: -24.7     I: -23.5 LUFS     LRA:   0.3 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.59998    M: -24.9 S: -24.5     I: -23.6 LUFS     LRA:   0.5 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.69998    M: -25.7 S: -24.4     I: -23.7 LUFS     LRA:   0.5 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.79998    M: -25.5 S: -24.3     I: -23.7 LUFS     LRA:   0.7 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.89998    M: -25.6 S: -24.3     I: -23.8 LUFS     LRA:   0.7 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 3.99998    M: -26.7 S: -24.2     I: -23.8 LUFS     LRA:   0.7 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.09998    M: -26.9 S: -24.1     I: -23.9 LUFS     LRA:   0.8 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.19998    M: -28.3 S: -24.1     I: -24.0 LUFS     LRA:   0.9 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.29998    M: -26.3 S: -23.9     I: -24.1 LUFS     LRA:   0.9 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.39998    M: -25.8 S: -23.8     I: -24.1 LUFS     LRA:   0.9 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.49998    M: -26.5 S: -23.8     I: -24.2 LUFS     LRA:   1.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.59998    M: -27.1 S: -23.8     I: -24.2 LUFS     LRA:   1.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.69998    M: -30.9 S: -23.9     I: -24.3 LUFS     LRA:   1.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.79998    M: -39.0 S: -24.2     I: -24.3 LUFS     LRA:   1.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.89998    M: -51.2 S: -24.7     I: -24.3 LUFS     LRA:   1.0 LU
[Parsed_ebur128_0 @ 0x7feb187009c0] t: 4.99998    M: -54.8 S: -24.8     I: -24.3 LUFS     LRA:   1.0 LU
frame=  150 fps=0.0 q=-0.0 Lsize=N/A time=00:00:05.01 bitrate=N/A speed=17.5x    
video:79kB audio:940kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_ebur128_0 @ 0x7feb187009c0] Summary:

  Integrated loudness:
    I:         -24.3 LUFS
    Threshold: -35.6 LUFS

  Loudness range:
    LRA:         1.0 LU
    Threshold: -44.4 LUFS
    LRA low:   -24.9 LUFS
    LRA high:  -23.8 LUFS

我想让-24.3LUFS 数值接近底部。我尝试过:

ffmpeg -i test.mp4 -hide_banner -filter_complex ebur128 -f null - 2<&1 | grep -E 'I:.+ LUFS$' | tail -1 | grep -E '\-[0-9\.]+'

取得了一些成功,但我正在寻找更有效的方法来做到这一点。

答案1

你可以使用awk

ffmpeg -i input -af ebur128=framelog=verbose -f null - 2>&1 | awk '/I:/{print $2}'

请注意,具有讽刺意味的是,添加后framelog=verbose,输出比默认的更简洁。

如果你更喜欢使用 JSON,你可以使用劳德诺尔过滤器改为使用print_format=json选项。请参阅loudnorm.rb举个例子。

答案2

过滤最后 12 行(包含来自的 JSON 日志loudnorm),您可以使用jq以一种比较理智的方式解析该值:

ffmpeg -hide_banner -f lavfi -i sine=duration=5 \
  -filter:a loudnorm=print_format=json -f null /dev/null 2>&1 \
  | tail -n 12 \
  | jq '.["input_i"]|tonumber'

仅返回-21.75,没有其他内容。

相关内容