Log in

View Full Version : best options for mono encoding ffmpeg libpous.


rupeshforu3
2nd September 2024, 15:12
Hi i I am Rupesh from India and I brought a new pc with AMD Ryzen zen3 5500GT APU and Asus prime b450 motherboard and installed Linux Fedora 40 and I have some aac m4a music files and I want to convert them to opus files.

I installed libopus and libfdk-aac and compiled ffmpeg with options successfully using the following command

--enable_libopus and --enable_libfdk-aac

I want to convert aac m4a music files to opus using ffmpeg and libopus and so I have created a small bash script as follows.


#/bin/bash

for i in *.mp4;
do name="${i%????}";
echo $name;

ffmpeg -y -i "$i" -f mp4 -vn -ac 1 -c:a libopus -vbr on -application audio -mapping_family 0 -b:a 20k -af aresample=resampler=soxr -ar 48000 "${name}.opus";

done


For the opusenc command line encoder we have option as --downmix-mono but in ffmpeg along with libopus we don't have this option.

So for encoding from stereo to mono I have chosen option which is implied to libopus as


-ac 1 mapping_family 0


I used soxr resampler because I think it produces more quantity output audio file.


I have even choosen the following options which are related to vbr mode and the output audio is music not speech.


-vbr on -application audio

Kindly try to examine the above script and tell whether I have chosen the best options for encoding aac m4a music files to opus using ffmpeg and libopus.

If you think some other options need to be added to the above script suggest them also.

Regards,
Rupesh.

microchip8
2nd September 2024, 15:49
Why are you encoding lossy audio files to another lossy audio codec? That's not recommended!

rupeshforu3
2nd September 2024, 17:06
These files are not important but I want to keep them for future listening.

Quality is not important.

GeoffreyA
2nd September 2024, 19:25
You can remove vbr on, application audio, and mapping_family because they're already set to those defaults. For the resampler, use:

-af resample=48000:resampler=soxr

However, at such a low bitrate, 20 kbps, resampling quality won't matter, if it ever does, compared to compression artefacts. Indeed, one might wish to use a lower sampling rate; but yes, Opus uses 48 kHz internally, and I'm not sure what it does with the sampling rate at such bitrates.

I believe xHE-AAC beats Opus in the lower-bitrate domain, but is more difficult to encode and decode, from a compatability point of view.

GeoffreyA
3rd September 2024, 09:16
I did some quick testing this morning. Firstly, one doesn't need to set 48 kHz because it is converted to that implicitly. (Add "-loglevel debug" for more insight into what the filtergraph is doing behind the scenes.) So, a shorter, cleaner command might be:

ffmpeg -i INPUT -ac 1 -af aresample=resampler=soxr -c:a libopus -b:a 20k OUTPUT

I found that lowering the sampling rate does make a difference. At 24-kHz stereo, 32 kbps, and a moderately-challenging file, it sounded reasonable. Indeed, with the way Opus works, it seems that using mono doesn't lead to a big increase in quality.

rupeshforu3
3rd September 2024, 11:24
The following options are invalid

-af resample=48000:resampler=soxr

The correct options are

-af aresample=48000:resampler=soxr

GeoffreyA
3rd September 2024, 12:16
The following options are invalid

-af resample=48000:resampler=soxr

The correct options are

-af aresample=48000:resampler=soxr

My mistake.

rupeshforu3
3rd September 2024, 15:04
Hi as you suggested to try xheaac and I am interested and I want to try.

Kindly try to suggest how to compile xheaac along with ffmpeg.

GeoffreyA
3rd September 2024, 16:10
Being on Windows, I'm not sure how to compile FFmpeg with Exhale support, Exhale being the USAC/xHE-AAC encoder. Perhaps try to find an Exhale build for Linux. Note that compatibility is still a problem. At any rate, audio below 64 kbps will not be that good.

https://gitlab.com/ecodis/exhale

If you get hold of an Exhale build, you could pipe the audio from FFmpeg.

rupeshforu3
3rd September 2024, 16:33
I think that xheaac is not fully implemented I mean development and testing work is going on and it takes few years to get full support.

I have searched Google for xheaac but unfortunately I found few results which are considerable.

If you search for other encoders for example lame, aac you can get thousands of webpages related to documentation, operating systems support etc.,.

GeoffreyA
3rd September 2024, 17:11
Yes. Support is poor and the encoders, such as Exhale, are still in the heat of development. FFmpeg only recently implemented a decoder, and not all features have been added.

rupeshforu3
3rd September 2024, 17:17
Okay can you suggest documentation for libopus.

What is the meaning of mapping_family.

GeoffreyA
3rd September 2024, 18:39
https://www.ffmpeg.org/ffmpeg-codecs.html#libopus-1

According to the documentation, mapping_family controls how the codec works with mono, stereo, or surround-sound input. A value of 0 is for mono and stereo input; 1 for surround, or more than two channels; and 255 for independent streams with an unspecified layout. By default, mapping_family has a value of -1, which, if the input is mono or stereo, picks the right setting of 0 automatically. But if your audio has more than two channels, set it to 1, which will turn on surround-sound masking and LFE optimisations.

rupeshforu3
5th September 2024, 10:22
Thanks for your suggestions.

GeoffreyA
5th September 2024, 18:42
No problem! I hope it works.