Skip to content

Instantly share code, notes, and snippets.

@azeemh
Created December 29, 2023 21:12
Show Gist options
  • Save azeemh/de280db7ba71e1d69ed55c0e5855de50 to your computer and use it in GitHub Desktop.
Save azeemh/de280db7ba71e1d69ed55c0e5855de50 to your computer and use it in GitHub Desktop.
Bash Function to convert webm to mp4
# Based on the command used in https://askubuntu.com/a/1462885
#
# ffmpeg -i screencast.webm -filter:v "scale=trunc(iw/2)*2:trunc(ih/2)*2,fps=30" screencast.mp4
#
# Easily call this lengthy command with webm2mp4 filename.webm
#
# Add this to your ~/.bashrc file to easily access
#function to convert webm to mp4 via ffmpeg
function webm2mp4() {
filename="${1%.*}"
outputname="$filename.mp4"
if test -f "$1"; then
printf "You chose the file: $1 \nWe'll use the name '$filename' to save it to $outputname in a moment.\n"
if test -f $outputname; then
while true; do
read -r -p "$outputname exists, would you like to overwrite? (Y/N): " answer
case $answer in
[Yy]* ) ffmpeg -i "$1" -filter:v "scale=trunc(iw/2)*2:trunc(ih/2)*2,fps=30" "$filename".mp4; break;;
[Nn]* ) printf "Not Overwriting. Please rename your file, if necessary. Exiting...\n"; return;;
* ) echo "Please answer Y or N.";;
esac
done
elif ! test -f "$outputname"; then
printf "$outputname does not exist, nothing to worry about overwriting -- rendering now via ffmpeg.\n"
ffmpeg -i "$1" -filter:v "scale=trunc(iw/2)*2:trunc(ih/2)*2,fps=30" "$filename".mp4;
fi
elif ! test -f "$1"; then
printf "The file does not exist.\n"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment