Created
November 13, 2019 05:40
-
-
Save dbonates/c9afee953088e6e0e1490b185951de8b to your computer and use it in GitHub Desktop.
Some handy ffmpeg functions I use everyday.
This file contains hidden or 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
| # | |
| # VIDEO / IMAGE RELATED | |
| # | |
| # requires: ffmpeg | |
| # tip: put this funcion on your ~/.profile file | |
| # | |
| # Compress video files while keep their quality | |
| # Usage: compress video_file | |
| compress() { | |
| sourcefile=$(basename "$1") | |
| filename="${sourcefile%.*}" | |
| ffmpeg -i ${sourcefile} -c:v libx264 -crf 24 -b:v 1M -c:a aac -strict -2 "${filename}"_compressed.mp4 | |
| } | |
| # Convert video to gif file. | |
| # Usage: video2gif video_file (scale) (fps) | |
| video2gif() { | |
| sourcefile=$(basename "$1") | |
| filename="${sourcefile%.*}" | |
| ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${filename}.png" | |
| ffmpeg -i "${1}" -i "${filename}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${filename}".gif | |
| rm "${filename}.png" | |
| } | |
| # Rescale video to file. | |
| # Usage: rescale video_file desired_width | |
| # example, will rescale a video to width = 640 keeping aspect ratio: | |
| # rescale video_file 640 | |
| rescale() { | |
| sourcefile=$(basename "$1") | |
| filename="${sourcefile%.*}" | |
| ffmpeg -i ${sourcefile} -vf scale=${2:-320}:-1 "${filename}_scaled.mp4" | |
| } | |
| # Speed up video to file. | |
| # Usage: speedup video_file | |
| # tip: could be used to optimize file size too | |
| speedup() { | |
| sourcefile=$(basename "$1") | |
| filename="${sourcefile%.*}" | |
| ffmpeg -i ${sourcefile} -r 16 -filter:v "setpts=0.5*PTS" "${filename}"_faster.mp4 | |
| } | |
| # Speed down video to file. | |
| # Usage: speedup video_file | |
| # tip: could be used to optimize file size too | |
| speeddn() { | |
| sourcefile=$(basename "$1") | |
| filename="${sourcefile%.*}" | |
| ffmpeg -i ${sourcefile} -r 16 -filter:v "setpts=2*PTS" "${filename}"_slower.mp4 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment