Created
January 14, 2021 11:13
-
-
Save nmanikiran/2cc2ca28625577c73e0f4f97bc8e77f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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