91°F

Aaron Parecki

  • Articles
  • Notes
  • Photos
  • make-video-previews.sh

    December 26, 2018
    1. #!/bin/bash
    2.  
    3. # Make previews for a folder of .mov or .mp4 files that MacOS can open.
    4. # Normalizes to 480x270 at 30fps and 96kbps audio.
    5. # Converts a 277mb file from a DSLR into a 789kb file.
    6.  
    7. current_file=none
    8.  
    9. # Catch ctrl-c and stop the whole batch, otherwise ctrl-c just stops ffmpeg and the loop continues
    10. trap ctrl_c INT
    11. function ctrl_c() {
    12. echo "** aborting $current_file"
    13. if [ -e "$current_file.preview.mp4" ]
    14. then
    15. # Delete the current file since ffmpeg will have left it there after being interrupted
    16. rm "$current_file.preview.mp4"
    17. fi
    18. exit
    19. }
    20.  
    21. for filename in `ls *.{MOV,MP4,mov,mp4}`
    22. do
    23. # Check if the preview file already exists
    24. if [ -e "$filename.preview.mp4" ]
    25. then
    26. echo "$filename.preview.mp4 already exists"
    27. else
    28. # Don't convert .preview.mp4 files
    29. if [[ $filename != *.preview.mp4 ]]
    30. then
    31. current_file=$filename
    32.  
    33. # ffmpeg flags
    34. # -c:v libx264 -- encode using h264
    35. # -b:a 96k -- set audio to 96kbps
    36. # -s 480x270 -- scale video to 480x270 (1/4 of 1920x1080)
    37. # -r 30 -- set frame rate to 30fps
    38. # -movflags faststart -- move the index to the beginning of the file
    39. # -pix_fmt yuv420p -- this is needed for the resulting video to be understood by some apps like Quicktime and Quick Look
    40.  
    41. ffmpeg -i $filename -c:v libx264 -b:a 96k -s 480x270 -r 30 -movflags faststart -pix_fmt yuv420p $filename.preview.mp4
    42. fi
    43. fi
    44. done
    Portland, Oregon • 44°F
    Wed, Dec 26, 2018 4:37pm -08:00 #video
Posted in /code using quill.p3k.io

Hi, I'm Aaron Parecki, Director of Identity Standards at Okta, and co-founder of IndieWebCamp. I maintain oauth.net, write and consult about OAuth, and participate in the OAuth Working Group at the IETF. I also help people learn about video production and livestreaming. (detailed bio)

I've been tracking my location since 2008 and I wrote 100 songs in 100 days. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel. Read more.

  • Director of Identity Standards at Okta
  • IndieWebCamp Founder
  • OAuth WG Editor
  • OpenID Board Member

  • 🎥 YouTube Tutorials and Reviews
  • 🏠 We're building a triplex!
  • ⭐️ Life Stack
  • ⚙️ Home Automation
  • All
  • Articles
  • Bookmarks
  • Notes
  • Photos
  • Replies
  • Reviews
  • Trips
  • Videos
  • Contact
© 1999-2025 by Aaron Parecki. Powered by p3k. This site supports Webmention.
Except where otherwise noted, text content on this site is licensed under a Creative Commons Attribution 3.0 License.
IndieWebCamp Microformats Webmention W3C HTML5 Creative Commons
WeChat ID
aaronpk_tv