Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to normalize audio when downloading video (not extract mp3) #11025

Open
serenity-networks opened this issue Oct 25, 2016 · 14 comments
Open

How to normalize audio when downloading video (not extract mp3) #11025

serenity-networks opened this issue Oct 25, 2016 · 14 comments
Labels

Comments

@serenity-networks
Copy link

@serenity-networks serenity-networks commented Oct 25, 2016

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like that [x])
  • Use Preview tab to see how your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2016.10.25. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2016.10.25

Before submitting an issue make sure you have:

  • [s] At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your issue


Description of your issue, suggested solution and other information

I would like to use youtube-dl to download video's, normalizing the audio in the process. I understand how to extract an MP3 from the video stream and normalize that, but I would like to have the Video and normalized audio in the container. It seams plausible this could be accomplished during the download, I just don't know how. If not, it seems like it would be easy to incorporate. The reason this is needed is for downloading recordings of conference sessions, such as Blackhat 2016 briefings, and Defcon sessions. They tend to have microphone volumes all over the place, and when the mic is handed off to someone else you get the hell scared out of your because it's so loud. Help would be greatly appreciated. I'm posting this on behalf of myself, and 3 others in need of the same process. Thank you for your time.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 25, 2016

Are there programs with audio normalization algorithms? From Wikipedia, seems it requires some sort of signal processing. That's far beyond the scope of youtube-dl. If such a program requires only a filename, --exec can be used for offline processing.

@serenity-networks
Copy link
Author

@serenity-networks serenity-networks commented Oct 25, 2016

Yes, ffmpeg does it. The youtube-dl documentation explains how to do it, but only when you stip the mp3 from a video file. I don't want to strip the audio, I just want to normalize it and keep it in the video container or reinsert it in the video container. "normalization" is nothing more than audio compression.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 25, 2016

Yes, ffmpeg does it.

Could you share your command?

@serenity-networks
Copy link
Author

@serenity-networks serenity-networks commented Oct 25, 2016

I'm having trouble finding the information I read earlier. I will keep looking. I do know of another way to do it if the audio is piped to mp3gain and the following is ran:

mp3gain -r -T *.mp3

@serenity-networks
Copy link
Author

@serenity-networks serenity-networks commented Oct 25, 2016

Here is a normalization script that uses ffmpeg:

https://github.com/slhck/ffmpeg-normalize

@serenity-networks
Copy link
Author

@serenity-networks serenity-networks commented Oct 25, 2016

I'm wondering if youtube-dl could somehow pipe the video to the ffmpeg-normalize script (which can handle mkv, mp4, and avi files). I wish I could find the information I found earlier. This should be enough to get us moving in that direction.

@serenity-networks
Copy link
Author

@serenity-networks serenity-networks commented Oct 25, 2016

OK, I'm finding some of the information I found earlier. Although ffmpeg-normalize probably does a better job, here is what's built into ffmpeg as is:

Built-in Normalization Filters

Current ffmpeg has two filters that can be directly used for normalization – although they are already quite advanced, so they do not simply apply gain. Here they are:

  • loudnorm: loudness normalization according to EBU R128. You can set an integrated loudness target, a loudness range target, or maximum true peak. This is recommended for publishing audio and video.
  • dynaudnorm: “intelligent” loudness normalization without clipping, which applies normalization dynamically over windowed portions of the file. This may change the characteristics of the sound, so it should be applied with caution.

If we want a “simple” RMS-based normalization to 0 dBFS, that is what ffmpeg-normalize does.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 25, 2016

if youtube-dl could somehow pipe the video to the ffmpeg-normalize script

That's possible in general. Like this: youtube-dl <the URL> -o - | <ffmpeg or other programs>

@serenity-networks
Copy link
Author

@serenity-networks serenity-networks commented Oct 31, 2016

I will have to test this. I will post anything and everything I find here. Do you have any more specifics to offer on the ffmpeg side of the pipe? Thank you.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 31, 2016

Pipe protocol may be useful.

@markuman
Copy link

@markuman markuman commented Dec 23, 2017

in ffmpeg it's -filter:a loudnorm.

So it would be cool to have something like youtube-dl --prefer-ffmpeg --normalize

@yan12125 yan12125 added the request label Dec 23, 2017
@cyph84
Copy link

@cyph84 cyph84 commented Feb 14, 2020

It seems like youtube returns perceptualLoudnessDb, which can be passed to a ffmpeg audio filter like alimiter to achieve the same effect

@YipYup
Copy link

@YipYup YipYup commented Mar 12, 2020

I just wanted to contribute some information; documentation I came across while researching how to do this manually. There is a script you can use to automate this called ffmpeg-normalize. This may be a good utility to look at, for inspiration on how you want to implement such a task into youtube-dl.

Automatization with ffmpeg-normalize
To automate the normalization processes with ffmpeg without having to manually perform two passes, and run normalization on multiple files (including video), you can also use the ​ffmpeg-normalize Python program via pip install ffmpeg-normalize.

The script defaults to EBU R128 normalization with two passes, but peak and RMS normalization are also supported.

For details, run ffmpeg-normalize -h or see the README file.

Source: https://trac.ffmpeg.org/wiki/AudioVolume

@mbehm
Copy link

@mbehm mbehm commented Apr 22, 2020

I noticed there's an option to supply extra parameters to the postprocessor so you can do the normalization easily with --prefer-ffmpeg --postprocessor-args "-filter:a loudnorm"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.