0

I'm struggling to find a way to normalize a specific audio channel in a video file via ffmpeg (I'm open to other suggestions). I have 20 or more video files with 5.1 audio tracks. My preference is to normalize just the FC channel of that audio track. Usually, I'm using Audacity to manually do that and then I use MKVToolNix to replace the original audio with the normalized one. It's all good, but when I have hundreds of videos it's just too much. I tried ffmped loudnorm filter and it's doing its job, but it normalizes all the audio channels which beats the purpose. Is there any way I can do this automatically in batches?

1 Answer 1

0
ffmpeg -i input -filter_complex "[0:a:0]channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR];[FC]loudnorm,aformat=sample_rates=44100:channel_layouts=mono[FC2];[FL]aformat=channel_layouts=mono[FL2];[FR]aformat=channel_layouts=mono[FR2];[LFE]aformat=channel_layouts=mono[LFE2];[BL]aformat=channel_layouts=mono[BL2];[BR]aformat=channel_layouts=mono[BR2];[FL2][FR2][FC2][LFE2][BL2][BR2]join=inputs=6:channel_layout=5.1" -c:v copy output
  1. Extract channels with channelsplit.
  2. Use loudnorm.
  3. Reset sample rate with aresample or aformat (loudnorm makes it 192000 Hz).
  4. Set each channel as mono (needed for join filter) with aformat.
  5. Join all channels with join.
  6. Stream copy the video.

Also see FFmpeg Wiki: Audio Channels.

6
  • Greatly appreciate your help. The line works but with a couple of quirks. 1. For some reason after processing the channels are in a different order. Original Processed Obviously, this is not a big deal, but it will be a potential problem in the future if you want to edit the file again and don't check the channel layout. 2. The final result is re-encoded audio into vorbis. My preference here is AAC. I was wondering if I could use -c:a libfdk_aac -vbr 3. Can you help me with this too? Thank you in advance! Jun 11, 2021 at 11:44
  • 1
    I managed to resolve the issues. The final line looks like this: -i {source} -filter_complex "[0:a:0]channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR];[FC]loudnorm,aformat=sample_rates=44100:channel_layouts=mono[FC2];[FL]aformat=channel_layouts=mono[FL2];[FR]aformat=channel_layouts=mono[FR2];[LFE]aformat=channel_layouts=mono[LFE2];[BL]aformat=channel_layouts=mono[BL2];[BR]aformat=channel_layouts=mono[BR2];[FL2][FR2][FC2][LFE2][BL2][BR2]join=inputs=6:channel_layout=5.1:map=0.0-FL|1.0-FR|2.0-FC|3.0-LFE|4.0-BL|5.0-BR" -c:v copy -c:a libfdk_aac -vbr 3 {outputfile} Thank you, again! Jun 11, 2021 at 14:19
  • It turns out that I didn't figure it out. The -c:a libfdk_aac -vbr 3 is not applied on the remapped and normalized audio stream but on the original one. So basically this whole line of arguments just converts the original audio to AAC. I can't seem to find the right syntax to convert the processed audio stream to AAC. Can you please help me with this!? Jun 16, 2021 at 23:25
  • @MiroslavPetrov Show full log from command.
    – llogan
    Jun 17, 2021 at 0:17
  • Input Output Log Obviously I was wrong. There is normalization on the output audio but it so subtle that I didn't notice it before and assumed the wrong thing. I'm sorry that I bothered you! Jun 18, 2021 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.