Skip to content

Instantly share code, notes, and snippets.

@nmanikiran
Created January 14, 2021 11:13
Show Gist options
  • Save nmanikiran/2cc2ca28625577c73e0f4f97bc8e77f1 to your computer and use it in GitHub Desktop.
Save nmanikiran/2cc2ca28625577c73e0f4f97bc8e77f1 to your computer and use it in GitHub Desktop.
#!/bin/bash
STARTFOLDER="./"
MARKER="converted"
echo -n "Finding candidate files .."
FILELIST=$(find "$STARTFOLDER" -type f -name '*.mp4')
echo ".. "$(echo -e "$FILELIST" | wc -l)" found"
while read FILEPATH; do
# A bit of healthy paranoia
test -z "$FILEPATH" && continue
test -f "$FILEPATH" || continue
echo -n "Working on $FILEPATH .."
# New file name
BN=$(basename "$FILEPATH" '.mp4')
BP=$(dirname "$FILEPATH")
NEWFILEPATH="$BP/$BN-$MARKER.mp4"
# Skip result files
ISRESULT=$(echo "$BN" | grep -e "$MARKER\\.mp4\$")
if test -n "$ISRESULT"; then
echo ".. skipping (is a result file)"
continue
fi
# Skip processed files
if test -f "$NEWFILEPATH"; then
echo ".. skipping (result file exists)"
continue
fi
# Process
echo -n ".. running ffmpeg .."
RES=$(ffmpeg -i "$FILEPATH" -vcodec h264 -acodec aac "$NEWFILEPATH" </dev/null 2>&1)
echo ".. done (exit code $?)"
done < <(echo -e "$FILELIST")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment