Created
December 20, 2025 15:38
-
-
Save Guiorgy/64ca9d77669a7ca9bb6f106ba2684679 to your computer and use it in GitHub Desktop.
Reencode all FLAC audio files in a source directory into OPUS and output them into a destination directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # ============================================================================= # | |
| # Copyright © 2025 Guiorgy # | |
| # # | |
| # This program is free software: you can redistribute it and/or modify it under # | |
| # the terms of the GNU General Public License as published by the Free Software # | |
| # Foundation, either version 3 of the License, or (at your option) any later # | |
| # version. # | |
| # # | |
| # This program is distributed in the hope that it will be useful, but WITHOUT # | |
| # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # | |
| # FOR A PARTICULAR PURPOSE. # | |
| # # | |
| # You can see the full GNU General Public License at # | |
| # <https://www.gnu.org/licenses/> for more details. # | |
| # ============================================================================= # | |
| set -eu | |
| SOURCE="${1-}" | |
| DESTINATION="${2-}" | |
| if [[ -z "$SOURCE" || -z "$DESTINATION" ]]; then | |
| cat >&2 <<EOF | |
| Source ('$SOURCE') and destination ('$DESTINATION') must not be empty" | |
| Usage: $(basename "$0") source destination | |
| EOF | |
| exit 1 | |
| fi | |
| convert_flac_to_opus() { | |
| flac="$1" | |
| dest="$2" | |
| opus="${dest%/}/$(basename "$flac" '.flac').opus" | |
| ffmpeg \ | |
| -y \ | |
| -i "$flac" \ | |
| -c:a libopus -b:a 128k \ | |
| -compression_level 10 -frame_duration 60 -threads 1 \ | |
| -map 0:a -map_metadata 0 -id3v2_version 3 \ | |
| "$opus" | |
| } | |
| export -f convert_flac_to_opus | |
| find "$SOURCE" -maxdepth 1 -name '*.flac' -print0 \ | |
| | xargs -0 -n 1 -P "$(nproc)" -I {} sh -c 'convert_flac_to_opus "$1" "$2"' -- {} "$DESTINATION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment