Skip to content

Instantly share code, notes, and snippets.

@mandymozart
Last active July 28, 2023 10:26
Show Gist options
  • Save mandymozart/79300a9d6dc10cb1a9e0d0b7bded0616 to your computer and use it in GitHub Desktop.
Save mandymozart/79300a9d6dc10cb1a9e0d0b7bded0616 to your computer and use it in GitHub Desktop.
Batch convert all files in ${directory} from MPG Sony AVCHD and copy to ${out}.
#!/usr/bin/bash
# input files directory
directory=$1
# converted files directory
out=$2
echo "Batch convert all files in ${directory} from MPG Sony AVCHD and copy to ${out}"
echo "------------------------------------------------------------------------------"
[[ -z "$directory" ]] && { echo "Error: directory required"; exit 1; }
[[ -z "$out" ]] && { echo "Error: out required"; exit 1; }
mkdir -p $out
for f in $directory/*.MPG;
do
if [ -f "$f" ]
then
echo "Processing $f file..."
file_output=$(basename -- $f)
ffmpeg -i $f -c:v libx264 -vf yadif -c:a aac -crf 15 -preset:v veryslow "${out}/${file_output%.MPG}.mp4"
RC=$?
if [ "${RC}" -ne "0" ]; then
# Do something to handle the error.
exit 1
else
# Everything was ok.
echo "Copied file to ${out}/${file_output%.MPG}.mp4"
fi
else
echo "Warning: Some problem with \"$f\""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment