Last active
August 28, 2021 22:56
-
-
Save PinheiroCosta/b293750fbcb8c8a297ed8e6ad7526504 to your computer and use it in GitHub Desktop.
FFmpeg functions
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
#!/usr/bin/env bash | |
# ======================================================================================== | |
# Convert your media files into several formats, | |
# add subtitles to your videos and more. | |
# ======================================================================================== | |
wavtomp3() { | |
# Convert wav files to mp3 | |
# Usage: wavtomp3 file.wav output.mp3 | |
filename=$1 | |
output=$2 | |
ffmpeg -i "$filename" -acodec mp3 "$output" | |
} # ------- End of wavtomp3() ----------- | |
webmtogif () { | |
# Convert webm files to gif | |
# Usage: webmtogif file.webm | |
filename=$1 | |
tempfolder=$(mktemp -d) | |
trap 'rm -vfr $tempfolder' EXIT | |
# Check if extension is webm | |
if [[ ${filename##*.} == 'webm' ]]; | |
then | |
ffmpeg -y -i "$filename" -vf palettegen "$tempfolder/palette.png" | |
ffmpeg -y -i "$filename" -i "$tempfolder/palette.png" \ | |
-filter_complex paletteuse -r 10 "$PWD/${filename/%webm/gif}" | |
else | |
echo "the file must be a webm extension type." | |
fi | |
} # ------------------------- End of webmtogif() -------------------------- | |
addsubtomp4() { | |
# add subtitles to mp4 | |
# Usage: addsubtomp4 filename.mp4 subtitle.srt | |
filename=$1 | |
subtitle=$2 | |
ffmpeg -i "$filename" -f srt -i "$subtitle" \ | |
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \ | |
-c:s mov_text "$PWD/${filename/%.mp4/-subtitled.mp4}" | |
} # ------------ End of addsubtomp4() --------------- | |
addsubtomkv() { | |
# Add subtitles to mkv | |
# Usage: addsubtomkv filename.mkv subtitle.srt | |
filename=$1 | |
subtitle=$2 | |
ffmpeg -i "$filename" -f srt -i "$subtitle" \ | |
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \ | |
-c:s srt "$PWD/${filename/%.mkv/-subtitled.mkv}" | |
} # ------------- End of addsubtomkv() -------------- | |
cropvideo() { | |
# Crop the gnome status bar from the full screen video | |
# iw = input width, ih = input height | |
# Usage: cropvideo filename | |
filename="$1" | |
extension="${filename##*.}" | |
ffmpeg -i "$filename" -filter:v "crop=iw:ih-30:0:30" \ | |
"${filename/%.*/-cropped.$extension}" | |
} # ------------- End of cropvideo() -------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment