Skip to content

Instantly share code, notes, and snippets.

@HackingGate
Created December 9, 2020 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HackingGate/d6f8545682a25c3ec1fabddf42d443d9 to your computer and use it in GitHub Desktop.
Save HackingGate/d6f8545682a25c3ec1fabddf42d443d9 to your computer and use it in GitHub Desktop.
Use ffmpeg to convert multiple videos(in any path) to MP4. Output in the same filename in the current path.
#!/bin/bash
FILEPATH=""
for arg in $@
do
FILEPATH="${FILEPATH}${arg}"
if [[ -f $FILEPATH ]]; then
echo "Converting $FILEPATH to mp4"
FILENAME_W_EXTENSION=$(basename "$FILEPATH")
FILENAME="${FILENAME_W_EXTENSION%.*}"
ffmpeg -i "${FILEPATH}" -pix_fmt yuv420p "${FILENAME}.mp4"
# clear $FILEPATH when success
FILEPATH=""
else
# prepare space for next arg
FILEPATH="${FILEPATH} "
fi
done
@HackingGate
Copy link
Author

HackingGate commented Dec 9, 2020

Bug:
If an original filename has continuous spaces. It will not recognised as a file because the limitation of for arg in $@.
Please don't use continuous spaces, if you have to, use only 1 continuous space in your original files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment