#!/bin/bash # Make previews for a folder of .mov or .mp4 files that MacOS can open. # Normalizes to 480x270 at 30fps and 96kbps audio. # Converts a 277mb file from a DSLR into a 789kb file. current_file=none # Catch ctrl-c and stop the whole batch, otherwise ctrl-c just stops ffmpeg and the loop continues trap ctrl_c INT function ctrl_c() { echo "** aborting $current_file" if [ -e "$current_file.preview.mp4" ] then # Delete the current file since ffmpeg will have left it there after being interrupted rm "$current_file.preview.mp4" fi exit } for filename in `ls *.{MOV,MP4,mov,mp4}` do # Check if the preview file already exists if [ -e "$filename.preview.mp4" ] then echo "$filename.preview.mp4 already exists" else # Don't convert .preview.mp4 files if [[ $filename != *.preview.mp4 ]] then current_file=$filename # ffmpeg flags # -c:v libx264 -- encode using h264 # -b:a 96k -- set audio to 96kbps # -s 480x270 -- scale video to 480x270 (1/4 of 1920x1080) # -r 30 -- set frame rate to 30fps # -movflags faststart -- move the index to the beginning of the file # -pix_fmt yuv420p -- this is needed for the resulting video to be understood by some apps like Quicktime and Quick Look ffmpeg -i $filename -c:v libx264 -b:a 96k -s 480x270 -r 30 -movflags faststart -pix_fmt yuv420p $filename.preview.mp4 fi fi done
WeChat ID
aaronpk_tv