MyTetra Share
Делитесь знаниями!
Как сделать правильный уровень громкости для Youtube с помощью ffmpeg
Время создания: 22.09.2021 01:40
Текстовые метки: ffmpeg, youtube, уровень громкости, компрессор, компрессия
Раздел: Компьютер - Linux - Видео в Linux - FFmpeg
Запись: xintrea/mytetra_syncro/master/base/1632264030f1zmy5fk0g/text.html на raw.github.com

Многие пользователи Youtube часто замечают, что громкость в только что залитом на Ютуб видеоролике значительно меньше, чем в оригинальном видеофайле. Происходит это потому, что Ютуб в какой-то момент начал бороться с искусственно повышенной громкостью в видеороликах, которую делают создатели роликов чтобы продвинуть свой аудио-контент.


Поэтому звук в ролике надо подготовить: выровнять его по громкости, и не дать уровню шума подняться выше -6dB (цифра неточная). Тогда Youtube будет минимально вмешиваться в уровень громкости, и звук будет хорошо слышно.


Кратко, можно использовать следующие команды:



# Audio Normalize and YouTube Optimization with ffmpeg:


# Get the max volume of your out.ogv with:

ffmpeg -i out.ogv -af "volumedetect" -f null /dev/null


# then level up with the value you have under max-vol

# and prepare the stream for YouTube, e.g.:

ffmpeg -i out.ogv -c:v libx264 -preset fast -crf 18 -af "volume=13dB" -c:a aac -q:a 5 -pix_fmt yuv420p -strict -2 test.mp4



Еще один вариант команды с компрессором и изменением громкости:



ffmpeg -i sourceVideo.avi -c:v copy -af acompressor=threshold=-14dB:ratio=12:attack=200:release=750 -af "volume=volume=0.80" -c:a aac -q:a 1 -ab 256k video.avi



Да, в фильтре volume директива volume пишется два раза. Первый раз она обозначает имя фильтра, второй раз - параметр.


В любом случае, надо получить примерно следующие параметры звучания, замеряемые так же с помощью ffmpeg:



> ffmpeg -i video.avi -af "volumedetect" -vn -sn -dn -f null /dev/null


[Parsed_volumedetect_0 @ 0x5630c92d5740] n_samples: 153069568

[Parsed_volumedetect_0 @ 0x5630c92d5740] mean_volume: -19.9 dB

[Parsed_volumedetect_0 @ 0x5630c92d5740] max_volume: 0.0 dB

[Parsed_volumedetect_0 @ 0x5630c92d5740] histogram_0db: 32

[Parsed_volumedetect_0 @ 0x5630c92d5740] histogram_1db: 526

[Parsed_volumedetect_0 @ 0x5630c92d5740] histogram_2db: 3170

[Parsed_volumedetect_0 @ 0x5630c92d5740] histogram_3db: 12679

[Parsed_volumedetect_0 @ 0x5630c92d5740] histogram_4db: 39232

[Parsed_volumedetect_0 @ 0x5630c92d5740] histogram_5db: 101383



То есть, при средней громкости -18...-19dB и плавном распределении уровней громкости (когда более громких участков на 0 dB в разы меньше чем более тихих на -5dB), YouTube гарантированно не будет пережимать звуковой поток с уменьшением громкости.



Подробнее на английском:


Manually normalizing audio with ffmpeg

In ffmpeg you can use the volume filter to change the volume of a track. Make sure you download a recent version of the program.

This guide is for peak normalization, meaning that it will make the loudest part in the file sit at 0 dB instead of something lower. There is also RMS-based normalization which tries to make the average loudness the same across multiple files. To do that, do not try to push the maximum volume to 0 dB, but the mean volume to the dB level of choice (e.g. -26 dB).

Find out the gain to apply

First you need to analyze the audio stream for the maximum volume to see if normalizing would even pay off:

ffmpeg -i video.avi -af "volumedetect" -vn -sn -dn -f null /dev/null

Replace /dev/null with NUL on Windows.
The
-vn, -sn, and -dn arguments instruct ffmpeg to ignore non-audio streams during this analysis. This drastically speeds up the analysis.

This will output something like the following:

[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] mean_volume: -16.0 dB

[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] max_volume: -5.0 dB

[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] histogram_0db: 87861

As you can see, our maximum volume is -5.0 dB, so we can apply 5 dB gain. If you get a value of 0 dB, then you don't need to normalize the audio.

Apply the volume filter:

Now we apply the volume filter to an audio file. Note that applying the filter means we will have to re-encode the audio stream. What codec you want for audio depends on the original format, of course. Here are some examples:

  • Plain audio file: Just encode the file with whatever encoder you need:
  • ffmpeg -i input.wav -af "volume=5dB" output.mp3

    Your options are very broad, of course.

  • AVI format: Usually there's MP3 audio with video that comes in an AVI container:
  • ffmpeg -i video.avi -af "volume=5dB" -c:v copy -c:a libmp3lame -q:a 2 output.avi

    Here we chose quality level 2. Values range from 0–9 and lower means better. Check the MP3 VBR guide for more info on setting the quality. You can also set a fixed bitrate with -b:a 192k, for example.

  • MP4 format: With an MP4 container, you will typically find AAC audio. We can use ffmpeg's build-in AAC encoder.

ffmpeg -i video.mp4 -af "volume=5dB" -c:v copy -c:a aac -b:a 192k output.mp4

Here you can also use other AAC encoders. Some of them support VBR, too. See this answer and the AAC encoding guide for some tips.

In the above examples, the video stream will be copied over using -c:v copy. If there are subtitles in your input file, or multiple video streams, use the option -map 0 before the output filename.



Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования