AAC VBR 32 kbps from MP4, possibly 2 pass

Questions involving a Windows version of FFmpeg.
Post Reply
DynV
Posts: 5
Joined: Sun May 12, 2019 6:04 pm

AAC VBR 32 kbps from MP4, possibly 2 pass

Post by DynV » Sun May 12, 2019 6:20 pm

I've been using FFMPEG indirectly for a while as I was using MediaCoder. Well it has bugs, uses an old version of FFMPEG and is bloated. One of my main uses was to make AAC VBR 32 kbps from MP4 with an AAC audio track, which the vast majority of the time is of higher quality; I don't remember if it allowed 2 pass (or more) but I'd like that if possible. I made a couple searches on how I could do that in vain.

Thank you kindly for assistance.

Oh! Once the former is dealt with, perhaps there's commands to find out the MP4 audio track quality and if it's not high enough to warrant being compressed (to VBR 32 kbps, perhaps anything < 64 kbps would yield little gain (size-quality ratio)), then extract it as is.

at2010
Posts: 10
Joined: Sun Apr 28, 2019 10:31 pm

Re: AAC VBR 32 kbps from MP4, possibly 2 pass

Post by at2010 » Thu May 16, 2019 2:22 am

Referencing the docs:

Code: Select all

https://ffmpeg.org/ffmpeg-codecs.html#aac
The closest two pass option is the twoloop option of aac_coder. The -cutoff 0 option to me sounded better at this low bitrate on movie/tv audio tracks. -cutoff 0 sets it to a dynamic cutoff. It also sounded better with the twoloop option. Your mileage may vary. Set to suit your ears.

Audio only AAC file. The .aac extension of the output file is in an ADTS container but you can use .mp4 instead.

Code: Select all

ffmpeg -i "input.mkv" -map 0:a -acodec aac -ab 32k -ac 2 -aac_coder twoloop -cutoff 0 "output.aac"
Video + audio:

Code: Select all

ffmpeg -i "input.mkv"  -map 0:v -vcodec copy -map 0:a -acodec aac -ab 32k -ac 2 -aac_coder twoloop -cutoff 0 "output.mp4"

DynV
Posts: 5
Joined: Sun May 12, 2019 6:04 pm

Re: AAC VBR 32 kbps from MP4, possibly 2 pass

Post by DynV » Thu May 16, 2019 3:03 am

The input is mp4, not mkv, does it change anything to your suggested commands?

at2010
Posts: 10
Joined: Sun Apr 28, 2019 10:31 pm

Re: AAC VBR 32 kbps from MP4, possibly 2 pass

Post by at2010 » Thu May 16, 2019 3:42 am

change "input.mkv" to "input.mp4" or even "input.mov" or "input.flv". All of them often contain h264 (or hevc) video and since the audio is transcoded, it doesn't matter what the original audio format was.

DynV
Posts: 5
Joined: Sun May 12, 2019 6:04 pm

Re: AAC VBR 32 kbps from MP4, possibly 2 pass

Post by DynV » Thu May 16, 2019 10:14 am

So the 1st track I converted was fine but the 2nd sounds bad but its (2nd track) original (MP4) sounds fine. Following is the console output for both of them. Both tracks were downloaded from The Orb - U.F.Orb (Deluxe Edition) - YouTube. I'm listening to both versions on VLC. Any idea what went wrong?

Thank you kindly
[please note there's an update after the quote]
C:\Program Files\ffmpeg-20190514-58d167b-win64-static\bin>ffmpeg -i "C:\youtube\
f0f75394ffa14e148d5d6e5e9bef0b01.mp4" -map 0:a -acodec aac -ab 32k -ac 2 -aac_co
der twoloop -cutoff 0 "C:\Music\AAC\The_Orb-O.O.B.E..aac"
ffmpeg version N-93863-g58d167bcd5 Copyright (c) 2000-2019 the FFmpeg developers

built with gcc 8.3.1 (GCC) 20190414
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi
g --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libb
luray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --e
nable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable
-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 -
-enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enab
le-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --en
able-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --en
able-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --e
nable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 27.100 / 56. 27.100
libavcodec 58. 52.101 / 58. 52.101
libavformat 58. 27.103 / 58. 27.103
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 53.100 / 7. 53.100
libswscale 5. 4.101 / 5. 4.101
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\youtube\f0f75394ffa14e148d5d6e5e9bef
0b01.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
creation_time : 2018-08-18T12:13:29.000000Z
Duration: 00:12:51.13, start: 0.000000, bitrate: 127 kb/s
Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, flt
p, 0 kb/s (default)
Metadata:
creation_time : 2018-08-18T12:13:29.000000Z
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, adts, to 'C:\Music\AAC\The_Orb-O.O.B.E..aac':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
encoder : Lavf58.27.103
Stream #0:0(eng): Audio: aac (LC), 44100 Hz, stereo, fltp, 32 kb/s (default)

Metadata:
creation_time : 2018-08-18T12:13:29.000000Z
handler_name : SoundHandler
encoder : Lavc58.52.101 aac
size= 3264kB time=00:12:51.13 bitrate= 34.7kbits/s speed=25.7x
video:0kB audio:3037kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 7.476056%
[aac @ 00000000003f0c80] Qavg: 411.093

C:\Program Files\ffmpeg-20190514-58d167b-win64-static\bin>ffmpeg -i "C:\youtube\
7a99df6923754716a0aae1cf74c11655.mp4" -map 0:a -acodec aac -ab 32k -ac 2 -aac_co
der twoloop -cutoff 0 "C:\Music\AAC\The_Orb-U.F.Orb.aac"
ffmpeg version N-93863-g58d167bcd5 Copyright (c) 2000-2019 the FFmpeg developers

built with gcc 8.3.1 (GCC) 20190414
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi
g --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libb
luray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --e
nable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable
-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 -
-enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enab
le-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --en
able-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --en
able-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --e
nable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 27.100 / 56. 27.100
libavcodec 58. 52.101 / 58. 52.101
libavformat 58. 27.103 / 58. 27.103
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 53.100 / 7. 53.100
libswscale 5. 4.101 / 5. 4.101
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\youtube\7a99df6923754716a0aae1cf74c1
1655.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
creation_time : 2018-08-18T12:13:35.000000Z
Duration: 00:06:13.14, start: 0.000000, bitrate: 127 kb/s
Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, flt
p, 1 kb/s (default)
Metadata:
creation_time : 2018-08-18T12:13:35.000000Z
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, adts, to 'C:\Music\AAC\The_Orb-U.F.Orb.aac':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
encoder : Lavf58.27.103
Stream #0:0(eng): Audio: aac (LC), 44100 Hz, stereo, fltp, 32 kb/s (default)

Metadata:
creation_time : 2018-08-18T12:13:35.000000Z
handler_name : SoundHandler
encoder : Lavc58.52.101 aac
size= 1539kB time=00:06:13.14 bitrate= 33.8kbits/s speed=20.3x
video:0kB audio:1429kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 7.687041%
[aac @ 0000000000587ec0] Qavg: 513.308
Update 1:

I tried a 2nd time with the problematic file (2nd in the above quote) with a similar sounding result (bad) and result exactly the same size. There were few differences in the console output: output file name (excluding the extension) appended "-2", speed=19.6x, for the aac @ (in last line) s/587/137/.

at2010
Posts: 10
Joined: Sun Apr 28, 2019 10:31 pm

Re: AAC VBR 32 kbps from MP4, possibly 2 pass

Post by at2010 » Fri May 17, 2019 9:41 pm

A bitrate of 32k is the lowest usable value for an AAC 2 channel mix. Changing to 64k will improve the quality. Or if you really need 32k AAC, try reducing the audio channels to 1 (mono). See examples below.
The output depends on the quality of the source audio. The audio you posted uses variable bitrate of 127k which is already pretty low. Transcoding to a very low value from a low source is guaranteed to give mixed results.
On the output file size: A 32k encode will reduce the file size from, e.g. 12MB (@127k) to about 3MB. 64k puts the output around 6MB. This means about 85 12MB files (original 127k) per Gigabyte, 170 6MB files (@64k) or 340 3MB files (@32k).

Increase bit rate to 64k (could also use 80k, 96k, etc):

Code: Select all

ffmpeg -i "input.mp4" -map 0:a -acodec aac -ab 64k -ac 2 -aac_coder twoloop -cutoff 0 "output.m4a"
Reduce audio channels to mono:

Code: Select all

ffmpeg -i "input.mp4" -map 0:a -acodec aac -ab 32k -ac 1 -aac_coder twoloop -cutoff 0 "output.m4a"
Since you are using VLC you may want to try the OPUS codec for low bitrates. It sounds better than AAC 2 channels at 32k:
32k opus audio stereo:

Code: Select all

ffmpeg -i "input.mp4" -map 0:a -acodec libopus -ab 32k -ac 2  "output.mka"
Note: .m4a is an audio only MP4 file. .mka is an audio only MKV file. You can use either extension. VLC will play them all.

DynV
Posts: 5
Joined: Sun May 12, 2019 6:04 pm

Re: AAC VBR 32 kbps from MP4, possibly 2 pass

Post by DynV » Fri May 17, 2019 10:20 pm

Good point about mono! That's what I was using on the bloatware in the OP but I forgot writing this. Is there a way for both channels to be merged together? Like if I put a regular microphone in front of a stereo, the result will not be affected that part of the source audio was only/mostly from a single speaker beyond that part being a lower volume (the total output of 2 speakers is louder than 1). Also hopefully both content will fully be included, unlike if I was to toggle which channel I preferred throughout the duration, but if only the latter can be done, it's better than having to pick a single track (toggling would likely be done multiple times but choosing is once).

DynV
Posts: 5
Joined: Sun May 12, 2019 6:04 pm

Re: AAC VBR 32 kbps from MP4, possibly 2 pass

Post by DynV » Sat May 25, 2019 4:38 am

Where can I find out how to select a stereo -> mono conversion type (I tried to show 3 types in my last post) ?

Post Reply