From b5d9c6263c7d93669515d8abb1b927c1a7a7061c Mon Sep 17 00:00:00 2001 From: fabian Date: Mon, 20 Feb 2023 19:13:25 +0100 Subject: [PATCH] parameter- und zielordnerhandling verbessert --- scripts/reencode_audio.sh | 10 ++++++++-- scripts/reencode_m4a.sh | 36 ++++++++++++++++++++++-------------- scripts/transcode_m4a.sh | 30 +++++++++++++++++++----------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/scripts/reencode_audio.sh b/scripts/reencode_audio.sh index eba3054..70e1fbd 100755 --- a/scripts/reencode_audio.sh +++ b/scripts/reencode_audio.sh @@ -1,7 +1,13 @@ #!/usr/bin/env bash set -euo pipefail +# ensure existence of destination folder +dest=../reencode +if [[ !(-d $dest) ]]; then + mkdir $dest +fi + for file in ./*.$1; do - echo "ffmpeg -i '$file' -c:a copy -map 0:0 '../reencode/$file'"; - ffmpeg -i "$file" -c:a copy -map 0:0 "../reencode/$file"; + echo "ffmpeg -i '$file' -c:a copy -map 0:0 '$dest/$file'"; + ffmpeg -i "$file" -c:a copy -map 0:0 "$dest/$file"; done diff --git a/scripts/reencode_m4a.sh b/scripts/reencode_m4a.sh index 9d74d93..a12029b 100755 --- a/scripts/reencode_m4a.sh +++ b/scripts/reencode_m4a.sh @@ -1,21 +1,29 @@ #!/usr/bin/env bash set -euo pipefail +# evaluate options through given arguments +map= +vbr= +while [[ $# > 0 ]]; do + case $1 in + -map) map='-map 0:0'; shift;; + -vbr) vbr='libfdk_aac -profile:a aac_he -b:a 64k'; shift;; + * ) break ;; # Anything else stops command line processing. + esac +done + +# if no variable bitrate, just copy audio +if [[ -z $vbr ]]; then + map="$map copy" +fi + +# ensure existence of destination folder +dest=../reencode +if [[ !(-d $dest) ]]; then + mkdir $dest +fi + for file in ./*.m4a; do - map=''; - if [[ $# > 0 && $1 == 'map' ]]; then - map='-map 0:0'; - fi - vbr=''; - if [[ $# > 1 && $2 == 'vbr' ]]; then - vbr='libfdk_aac -profile:a aac_he -b:a 64k'; - else - map="$map copy" - fi - dest=../reencode - if [[ !(-d $dest) ]]; then - mkdir $dest - fi echo "ffmpeg -i '$file' -c:a $vbr $map -movflags +faststart '$dest/$file'"; ffmpeg -i "$file" -c:a $vbr $map -movflags +faststart "$dest/$file"; done diff --git a/scripts/transcode_m4a.sh b/scripts/transcode_m4a.sh index 8990753..ee2aa95 100755 --- a/scripts/transcode_m4a.sh +++ b/scripts/transcode_m4a.sh @@ -1,16 +1,24 @@ #!/usr/bin/env bash set -euo pipefail -for file in ./*.$1; do - map=''; - if [[ $# > 1 && $2 == 'map' ]]; then - map='-map 0:0'; - fi - dest=../transcode_m4a - if [[ !(-d $dest) ]]; then - mkdir $dest - fi - echo "ffmpeg -i '$file' -c:a libfdk_aac -profile:a aac_he -b:a 64k -movflags +faststart $map '$dest/${file%$1}m4a'"; - ffmpeg -i "$file" -c:a libfdk_aac -profile:a aac_he -b:a 64k -movflags +faststart $map "$dest/${file%$1}m4a"; +# evaluate options through given arguments +file_suffix= +map= +while [[ $# > 0 ]]; do + case $1 in + -t | --type) file_suffix=$2; shift 2;; + -map ) map='-map 0:0'; shift;; + * ) break ;; # Anything else stops command line processing. + esac done +# ensure existence of destination folder +dest=../transcode_m4a +if [[ !(-d $dest) ]]; then + mkdir $dest +fi + +for file in ./*.$file_suffix; do + echo "ffmpeg -i '$file' -c:a libfdk_aac -profile:a aac_he -b:a 64k $map -movflags +faststart '$dest/${file%$file_suffix}m4a'"; + ffmpeg -i "$file" -c:a libfdk_aac -profile:a aac_he -b:a 64k $map -movflags +faststart "$dest/${file%$file_suffix}m4a"; +done