From cbf75faa58014ef44871290aeeb01832851f08ec Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Thu, 4 Feb 2021 01:02:03 +0100 Subject: [PATCH 1/4] Added Compression levels for mp3, opus and flac --- AAXtoMP3 | 42 ++++++++++++++++++++++++++++++++++++++++-- README.md | 7 +++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 7a4368f..9c770e0 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,9 +5,10 @@ # Command Line Options # Usage Synopsis. -usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--chaptered]\n[-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ]{FILES}\n' +usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ]{FILES}\n' codec=libmp3lame # Default encoder. extension=mp3 # Default encoder extension. +level=-1 # Compression level. Can be given for mp3, flac and opus. -1 = default/not specified. mode=chaptered # Multi file output auth_code= # Required to be set via file or option. targetdir= # Optional output location. Note default is basedir of AAX file. @@ -56,6 +57,8 @@ while true; do -V | --validate ) VALIDATE=1; shift ;; # continue splitting chapters at chapter continueAt --continue ) continueAt="$2"; continue=1; shift 2 ;; + # Compression level + --level ) level="$2"; shift 2 ;; # Command synopsis. -h | --help ) printf "$usage" $0 ; exit ;; # Standard flag signifying the end of command line processing. @@ -263,6 +266,34 @@ if [[ "x${completedir}" != "x" ]]; then fi fi +# ----- +# If a compression level is given, check whether the given codec supports compression level specifiers and whether the level is valid. +if [ "${level}" != "-1" ]; then + if [ "${codec}" == "flac" ]; then + if [ "$((${level} < 0 || ${level} > 12 ))" = "1" ]; then + echo "ERROR Flac compression level has to be in the range from 0 to 12!" + echo "$usage" + exit 1 + fi + elif [ "${codec}" == "libopus" ]; then + if [ "$((${level} < 0 || ${level} > 10 ))" = "1" ]; then + echo "ERROR Opus compression level has to be in the range from 0 to 10!" + echo "$usage" + exit 1 + fi + elif [ "${codec}" == "libmp3lame" ]; then + if [ "$((${level} < 0 || ${level} > 9 ))" = "1" ]; then + echo "ERROR MP3 compression level has to be in the range from 0 to 9!" + echo "$usage" + exit 1 + fi + else + echo "ERROR This codec doesnt support compression levels!" + echo "$usage" + exit 1 + fi +fi + # ----- # Clean up if someone hits ^c or the script exits for any reason. trap 'rm -r -f "${working_directory}"' EXIT @@ -409,7 +440,13 @@ do # and coders wanting to extend the script. debug_vars "Book and Variable values" title auth_code mode aax_file container codec bitrate artist album_artist album album_date genre copyright narrator description output_file metadata_file working_directory - # ----- + # If level != -1 specify a compression level in ffmpeg. + compression_level_param="" + if [ "${level}" != "-1" ]; then + compression_level_param="-compression_level ${level}" + fi + + # ----- if [ "${continue}" == "0" ]; then # This is the main work horse command. This is the primary transcoder. # This is the primary transcode. All the heavy lifting is here. @@ -420,6 +457,7 @@ do -i "${aax_file}" \ -vn \ -codec:a "${codec}" \ + ${compression_level_param} \ -ab ${bitrate} \ -map_metadata -1 \ -metadata title="${title}" \ diff --git a/README.md b/README.md index 55e1631..78c4f10 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ Audible fails for some reason. * grep Some OS distributions do not have it installed. * sed Some OS versions will need to install gnu sed. * mp4art used to add cover art to m4a and m4b files. Optional -* mediainfo used to add additional media tags like narrator. Optional ## OSX Thanks to thibaudcolas, this script has been tested on OSX 10.11.6 El Capitan. YMMV, but it should work for @@ -30,7 +29,7 @@ Thanks to kbabioch, this script has also been packaged in the [AUR](https://aur. ## Usage(s) ``` -bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [-c|--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [-A|--authcode ] [-n|--no-clobber] [-t|--target_dir ] [-C|--complete_dir ] [-V|--validate] [-d|--debug] [-h|--help] [--continue ] ... +bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level ] [-c|--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [-A|--authcode ] [-n|--no-clobber] [-t|--target_dir ] [-C|--complete_dir ] [-V|--validate] [-d|--debug] [-h|--help] [--continue ] ... ``` * **<AAX INPUT_FILES>**... are considered input file(s), useful for batching! @@ -50,6 +49,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [-c|--chaptered] [ * **-s** or **--single** Output a single file for the entire book. If you only want a single ogg file for instance. * **-c** or **--chaptered** Output a single file per chapter. The `--chaptered` will only work if it follows the `--aac -e:m4a -e:m4b --flac` options. * **--continue <CHAPTERNUMBER>** If the splitting into chapters gets interrupted (e.g. by a weak battery on your laptop) you can go on where the process got interrupted. Just delete the last chapter (which was incompletely generated) and redo the task with "--continue <CHAPTERNUMBER>" where CHAPTERNUMBER is the chapter that got interrupted. +* **--level <COMPRESSIONLEVEL>** Set compression level. May be given for mp3, flac and opus. ### [AUTHCODE] @@ -74,11 +74,13 @@ __Note:__ At least one of the above must be exist. The code must also match the * The default mode is **chaptered** * If you want a mp3 file per chapter do not use the **--single** option. * A m3u playlist file will also be created in this instance in the case of **default** chaptered output. +* **--level** has to be in range 0-9, where 9 is fastest and 0 is highest quality. ### Ogg/Opus Encoding * Can be done by using the **-o** or **--opus** command line switches * The default mode is **chaptered** * Opus coded files are stored in the ogg container format for better compatibility. +* **--level** has to be in range 0-10, where 0 is fastest and 10 is highest quality. ### AAC Encoding * Can be done by using the **-a** or **--aac** command line switches @@ -92,6 +94,7 @@ __Note:__ At least one of the above must be exist. The code must also match the * The default mode is **single** * FLAC is an open format with royalty-free licensing * This will only produce 1 audio file as output. If you want a flac file per chapter do use **-c** or **--chaptered**. +* **--level** has to be in range 0-12, where 0 is fastest and 12 is highest compression. ### M4A and M4B Containers * These containers were created by Apple Inc. They were meant to be the successor to mp3. From fd8a51d474880d68f1203ca01b4c4df0b60dded8 Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Thu, 4 Feb 2021 01:06:33 +0100 Subject: [PATCH 2/4] Added Compression levels for mp3, opus and flac --- AAXtoMP3 | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 9c770e0..b589bda 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -446,7 +446,7 @@ do compression_level_param="-compression_level ${level}" fi - # ----- + # ----- if [ "${continue}" == "0" ]; then # This is the main work horse command. This is the primary transcoder. # This is the primary transcode. All the heavy lifting is here. diff --git a/README.md b/README.md index 78c4f10..0d6324b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Audible fails for some reason. * grep Some OS distributions do not have it installed. * sed Some OS versions will need to install gnu sed. * mp4art used to add cover art to m4a and m4b files. Optional +* mediainfo used to add additional media tags like narrator. Optional ## OSX Thanks to thibaudcolas, this script has been tested on OSX 10.11.6 El Capitan. YMMV, but it should work for From db65efaf67febf6421d1c922e1d5d79cb8f1a1f1 Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Thu, 4 Feb 2021 11:20:13 +0100 Subject: [PATCH 3/4] Added Compression levels for mp3, opus and flac --- AAXtoMP3 | 1 + 1 file changed, 1 insertion(+) diff --git a/AAXtoMP3 b/AAXtoMP3 index b589bda..e30127c 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -553,6 +553,7 @@ do -map 0:0 \ -map 1:0 \ -acodec "${codec}" ${id3_version_param} \ + ${compression_level_param} \ -metadata:s:v title="Album cover" \ -metadata:s:v comment="Cover (Front)" \ -metadata track="${chapternum}" \ From d11257410b5a46fcb50dd8734c16f43ebcfedbba Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Fri, 5 Feb 2021 01:09:51 +0100 Subject: [PATCH 4/4] Added remark, that quality can't be increased. Added a remark, that quality can't be increased over the quality of the original file. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0d6324b..ab3dd87 100644 --- a/README.md +++ b/README.md @@ -75,13 +75,13 @@ __Note:__ At least one of the above must be exist. The code must also match the * The default mode is **chaptered** * If you want a mp3 file per chapter do not use the **--single** option. * A m3u playlist file will also be created in this instance in the case of **default** chaptered output. -* **--level** has to be in range 0-9, where 9 is fastest and 0 is highest quality. +* **--level** has to be in range 0-9, where 9 is fastest and 0 is highest quality. Please note: The quality can **never** become higher than the qualitiy of the original aax file! ### Ogg/Opus Encoding * Can be done by using the **-o** or **--opus** command line switches * The default mode is **chaptered** * Opus coded files are stored in the ogg container format for better compatibility. -* **--level** has to be in range 0-10, where 0 is fastest and 10 is highest quality. +* **--level** has to be in range 0-10, where 0 is fastest and 10 is highest quality. Please note: The quality can **never** become higher than the qualitiy of the original aax file! ### AAC Encoding * Can be done by using the **-a** or **--aac** command line switches @@ -95,7 +95,7 @@ __Note:__ At least one of the above must be exist. The code must also match the * The default mode is **single** * FLAC is an open format with royalty-free licensing * This will only produce 1 audio file as output. If you want a flac file per chapter do use **-c** or **--chaptered**. -* **--level** has to be in range 0-12, where 0 is fastest and 12 is highest compression. +* **--level** has to be in range 0-12, where 0 is fastest and 12 is highest compression. Since flac is lossless, the quality always remains the same. ### M4A and M4B Containers * These containers were created by Apple Inc. They were meant to be the successor to mp3.