Skip to content

Instantly share code, notes, and snippets.

@Stunner

Stunner/convert.sh

Created Jan 3, 2017
Embed
What would you like to do?
This script recurses through the file hierarchy, converting .MOD video files into .mp4 files with ffmpeg.
#!/bin/bash
# This script recurses through the file heirarchy, converting .MOD video files into .mp4 files with ffmpeg.
# usage: cd into the directory that you want to perform this script, then run "./convert.sh ."
MODext=MOD
MP4ext=mp4
# walk through a directory recusively,
recurse_dir() {
for i in "$1"/*; do
if [ -d "$i" ]; then
echo -e "searching dir: $i...\n"
recurse_dir "$i"
elif [ -f "$i" ]; then
if [[ ${i: -4} == ".MOD" ]]; then
dest=${i%.$MODext}.$MP4ext
echo -e "\nconverting file: $i..."
# feel free to tweak ffmpeg parameters below according to your needs
`ffmpeg -i "$i" -vcodec mpeg4 -b:v 2800k -acodec aac -ab 384k -ar 48000 "$dest" -n -nostdin`
RC=$? # get the return code from ffmpeg
if [ "${RC}" -ne "0" ]; then
# Do something to handle the error.
echo -e "ERROR code from ffmpeg: $RC\n"
else
# Everything was ok.
echo -e "removing file: $i...\n"
rm "$i"
fi
fi
fi
done
}
# try get path from param
path=""
if [ -d "$1" ]; then
path=$1;
else
path="/tmp"
fi
echo -e "base path: $path"
recurse_dir $path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.