Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Audio encoding

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd September 2024, 15:12   #1  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 98
best options for mono encoding ffmpeg libpous.

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.

Code:
#/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

Code:
-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.

Code:
-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.
rupeshforu3 is offline   Reply With Quote
Old 2nd September 2024, 15:49   #2  |  Link
microchip8
ffx264/ffhevc author
 
microchip8's Avatar
 
Join Date: May 2007
Location: /dev/video0
Posts: 1,868
Why are you encoding lossy audio files to another lossy audio codec? That's not recommended!
__________________
ffx264 || ffhevc || ffxvid || microenc
microchip8 is offline   Reply With Quote
Old 2nd September 2024, 17:06   #3  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 98
These files are not important but I want to keep them for future listening.

Quality is not important.
rupeshforu3 is offline   Reply With Quote
Old 2nd September 2024, 19:25   #4  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 65
You can remove vbr on, application audio, and mapping_family because they're already set to those defaults. For the resampler, use:

Code:
-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.

Last edited by GeoffreyA; 2nd September 2024 at 19:40.
GeoffreyA is offline   Reply With Quote
Old 3rd September 2024, 09:16   #5  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 65
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:

Code:
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.
GeoffreyA is offline   Reply With Quote
Old 3rd September 2024, 11:24   #6  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 98
The following options are invalid

-af resample=48000:resampler=soxr

The correct options are

-af aresample=48000:resampler=soxr
rupeshforu3 is offline   Reply With Quote
Old 3rd September 2024, 12:16   #7  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 65
Quote:
Originally Posted by rupeshforu3 View Post
The following options are invalid

-af resample=48000:resampler=soxr

The correct options are

-af aresample=48000:resampler=soxr
My mistake.
GeoffreyA is offline   Reply With Quote
Old 3rd September 2024, 15:04   #8  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 98
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.
rupeshforu3 is offline   Reply With Quote
Old 3rd September 2024, 16:10   #9  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 65
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.

Last edited by GeoffreyA; 3rd September 2024 at 16:16.
GeoffreyA is offline   Reply With Quote
Old 3rd September 2024, 16:33   #10  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 98
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.,.
rupeshforu3 is offline   Reply With Quote
Old 3rd September 2024, 17:11   #11  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 65
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.
GeoffreyA is offline   Reply With Quote
Old 3rd September 2024, 17:17   #12  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 98
Okay can you suggest documentation for libopus.

What is the meaning of mapping_family.
rupeshforu3 is offline   Reply With Quote
Old 3rd September 2024, 18:39   #13  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 65
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.
GeoffreyA is offline   Reply With Quote
Old 5th September 2024, 10:22   #14  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 98
Thanks for your suggestions.
rupeshforu3 is offline   Reply With Quote
Old 5th September 2024, 18:42   #15  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 65
No problem! I hope it works.
GeoffreyA is offline   Reply With Quote
Reply

Tags
ffmpeg, libopus, mono, options

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:23.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.