Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. # I use Windows, so I need a little helper (we dont have /bin). Non-windows users don't need this
  2. function ffmpeg() {
  3. command '/c/Program Files/ffmpeg/bin/ffmpeg.exe' "$@"
  4. }
  5.  
  6. # --------------------------------------------------------- #
  7. # ffmpeg_gif () #
  8. # Converts a video with ffmpeg to a 15fps optimized gif #
  9. # Parameters: $source_file $target_file #
  10. # Returns: target_file #
  11. # --------------------------------------------------------- #
  12. function ffmpeg_gif() {
  13. palette="/tmp/palette.png"
  14. # example filters: "fps=15,scale=320:-1:flags=lanczos"
  15. filters="fps=15"
  16. ffmpeg -v warning -i "$1" -vf "$filters,palettegen" -y $palette
  17. ffmpeg -v warning -i "$1" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
  18. }
  19.  
  20. # ---------------------------------------------------------#
  21. # ffmpeg_the_works () #
  22. # Converts a video to mp4, webm & gif with ffmpeg #
  23. # Parameters: $source_file #
  24. # Returns: $file-comp.mp4, $file-comp.webm, $file-comp.gif #
  25. # ---------------------------------------------------------#
  26. function ffmpeg_the_works() {
  27.  
  28. FILENAME="${1}"
  29. FILENAME_NO_EXT="${FILENAME%.*}"
  30.  
  31. # old: ffmpeg -v warning -i "$FILENAME" -c:v libx264 -profile:v main -vf format=yuv420p -c:a aac -movflags +faststart "$2.mp4"
  32. printf "\n\nRunning ffmpeg on %s to optimize mp4\n" "$FILENAME"
  33. ffmpeg -v warning -i "$FILENAME" -b:v 0 -crf 25 "$FILENAME_NO_EXT-comp.mp4"
  34.  
  35. printf "\n\nRunning ffmpeg on %s to optimize webm\n" "$FILENAME"
  36. ffmpeg -v warning -i "$FILENAME" -b:v 0 -crf 41 "$FILENAME_NO_EXT-comp.webm"
  37.  
  38. printf "\n\nRunning ffmpeg_gif\n"
  39. ffmpeg_gif "$FILENAME" "$FILENAME_NO_EXT-comp.gif"
  40.  
  41. printf "\n######## EXAMPLE VIDEO CODE: #########"
  42. printf "\n"
  43. printf "\n<video autoplay loop muted preload playsinline poster=\"SOME_FALLBACK_IMAGE.png\">"
  44. printf "\n\t<source src=\"%s-comp.webm\" type=\"video/webm\" />" "$FILENAME_NO_EXT"
  45. printf "\n\t<source src=\"%s-comp.mp4\" type=\"video/mp4\" />" "$FILENAME_NO_EXT"
  46. printf "\n\t<!--[if lt IE 9]><img src=\"%s-comp.gif\" /><![endif]-->" "$FILENAME_NO_EXT"
  47. printf "\n</video>"
  48. printf "\n"
  49. printf "\n######################################"
  50. printf "\n"
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement