Created
December 9, 2020 03:31
-
-
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.
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.