This commit is contained in:
commit
799aad90b5
1 changed files with 48 additions and 0 deletions
48
recursive-m4v-convert.sh
Normal file
48
recursive-m4v-convert.sh
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Change this to specify a different handbrake preset. You can list them by running: "HandBrakeCLI --preset-list"
|
||||
#
|
||||
set +e
|
||||
PRESET="Very Fast 720p30" # or Fast 720p30 or Fast 1080p30
|
||||
if [ -z "$1" ] ; then
|
||||
TRANSCODEDIR="."
|
||||
else
|
||||
TRANSCODEDIR="$1"
|
||||
fi
|
||||
|
||||
abs_basefolder=`realpath "$TRANSCODEDIR"`
|
||||
folder_base=`dirname "$abs_basefolder"`
|
||||
folder_name=`basename "$abs_basefolder"`
|
||||
output_basedirectory="$folder_base/$folder_name-converted"
|
||||
mkdir -p "$output_basedirectory"
|
||||
|
||||
|
||||
function recursive_convert {
|
||||
find "$1" -type d -print0 |
|
||||
while IFS= read -rd '' directory_to_convert; do
|
||||
echo "Converting files in $directory_to_convert";
|
||||
output_directory=$output_basedirectory
|
||||
if [ "$directory_to_convert" != "$1" ]; then
|
||||
abs_subfolder=`realpath "$directory_to_convert"`
|
||||
rel_subfolder=${abs_subfolder#$abs_basefolder/}
|
||||
#Create output directory
|
||||
output_subdirectory="$output_basedirectory/$rel_subfolder"
|
||||
mkdir -p "$output_subdirectory"
|
||||
output_directory=$output_subdirectory
|
||||
fi
|
||||
echo "Converted files will be saved in $output_directory";
|
||||
find "$directory_to_convert" -maxdepth 1 -mindepth 1 -type f -print0 |
|
||||
while IFS= read -r -d '' file_to_convert; do
|
||||
file_to_convert_filename=$(basename "$file_to_convert")
|
||||
converted_filepath="$output_directory/${file_to_convert_filename%.*}.m4v"
|
||||
# If the file doesn't exist then convert
|
||||
if [ ! -e "$converted_filepath" ]; then
|
||||
echo "Converting $file_to_convert"
|
||||
HandBrakeCLI --input "$file_to_convert" --output "$converted_filepath" --preset="$PRESET" </dev/null
|
||||
fi
|
||||
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
recursive_convert "$abs_basefolder"
|
||||
Loading…
Reference in a new issue