memo.xight.org

日々のメモ

ffmpegを利用した音量調整

Summary

音声吹き込みスライドから出力した動画を提出する必要があり、
CLIで音量調整を行う方法について調べてみた。

音量レベルの確認

ffmpeg -i input.mp4 -vn -af volumedetect -f null -


-i は入力ファイル。mp4 でも mp3 でも OK
-vn でビデオストリームを無視
-af でオーディオフィルタを指定 (volumedetect フィルタの指定)
-f null で出力ファイルを null に指定
最後の - はダミー

音量レベルの確認 (出力)

[Parsed_volumedetect_0 @ 0xc8ec20840] n_samples: 23422976
[Parsed_volumedetect_0 @ 0xc8ec20840] mean_volume: -42.1 dB
[Parsed_volumedetect_0 @ 0xc8ec20840] max_volume: -14.0 dB
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_14db: 10
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_15db: 39
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_16db: 146
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_17db: 350
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_18db: 714
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_19db: 1387
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_20db: 2477
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_21db: 4600
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_22db: 7370
[Parsed_volumedetect_0 @ 0xc8ec20840] histogram_23db: 11657


max_volume の値を確認。
0 dBになるように調整する。 (+14.0 dB)

ゲイン調整 (14dB上げる / 再エンコード実施、ファイルサイズが大幅に削減できた)

ffmpeg -i input.mp4 -af volume=14dB output.mp4


ゲイン調整 (14dB上げる / 再エンコード不要の場合)

ffmpeg -i input.mp4 -codec:v copy -af volume=14dB output.mp4


音量レベルの再確認 (出力)

[Parsed_volumedetect_0 @ 0x9e6c20a80] n_samples: 23422976
[Parsed_volumedetect_0 @ 0x9e6c20a80] mean_volume: -28.1 dB
[Parsed_volumedetect_0 @ 0x9e6c20a80] max_volume: -0.4 dB
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_0db: 8
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_1db: 36
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_2db: 142
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_3db: 354
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_4db: 698
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_5db: 1364
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_6db: 2455
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_7db: 4569
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_8db: 7318
[Parsed_volumedetect_0 @ 0x9e6c20a80] histogram_9db: 11626


Reference

Qiita - @mml - 2020-01-05 - 動画や音声ファイルの音量(ゲイン)を ffmpeg で調整するときのメモ
https://qiita.com/mml/items/c28d69ab889eb36dd522