Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I use Windows, so I need a little helper (we dont have /bin). Non-windows users don't need this
- function ffmpeg() {
- command '/c/Program Files/ffmpeg/bin/ffmpeg.exe' "$@"
- }
- # --------------------------------------------------------- #
- # ffmpeg_gif () #
- # Converts a video with ffmpeg to a 15fps optimized gif #
- # Parameters: $source_file $target_file #
- # Returns: target_file #
- # --------------------------------------------------------- #
- function ffmpeg_gif() {
- palette="/tmp/palette.png"
- # example filters: "fps=15,scale=320:-1:flags=lanczos"
- filters="fps=15"
- ffmpeg -v warning -i "$1" -vf "$filters,palettegen" -y $palette
- ffmpeg -v warning -i "$1" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
- }
- # ---------------------------------------------------------#
- # ffmpeg_the_works () #
- # Converts a video to mp4, webm & gif with ffmpeg #
- # Parameters: $source_file #
- # Returns: $file-comp.mp4, $file-comp.webm, $file-comp.gif #
- # ---------------------------------------------------------#
- function ffmpeg_the_works() {
- FILENAME="${1}"
- FILENAME_NO_EXT="${FILENAME%.*}"
- # old: ffmpeg -v warning -i "$FILENAME" -c:v libx264 -profile:v main -vf format=yuv420p -c:a aac -movflags +faststart "$2.mp4"
- printf "\n\nRunning ffmpeg on %s to optimize mp4\n" "$FILENAME"
- ffmpeg -v warning -i "$FILENAME" -b:v 0 -crf 25 "$FILENAME_NO_EXT-comp.mp4"
- printf "\n\nRunning ffmpeg on %s to optimize webm\n" "$FILENAME"
- ffmpeg -v warning -i "$FILENAME" -b:v 0 -crf 41 "$FILENAME_NO_EXT-comp.webm"
- printf "\n\nRunning ffmpeg_gif\n"
- ffmpeg_gif "$FILENAME" "$FILENAME_NO_EXT-comp.gif"
- printf "\n######## EXAMPLE VIDEO CODE: #########"
- printf "\n"
- printf "\n<video autoplay loop muted preload playsinline poster=\"SOME_FALLBACK_IMAGE.png\">"
- printf "\n\t<source src=\"%s-comp.webm\" type=\"video/webm\" />" "$FILENAME_NO_EXT"
- printf "\n\t<source src=\"%s-comp.mp4\" type=\"video/mp4\" />" "$FILENAME_NO_EXT"
- printf "\n\t<!--[if lt IE 9]><img src=\"%s-comp.gif\" /><![endif]-->" "$FILENAME_NO_EXT"
- printf "\n</video>"
- printf "\n"
- printf "\n######################################"
- printf "\n"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement