You can use this script in an Automator “Run Shell Script” action. Make sure the shell is “/bin/zsh” and the input is “as arguments”
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/bin/zsh
# Creates mp4, webm, poster.png for the website.
# Webm can take a long time to convert.
# Install ffmpeg on macOS with: brew install ffmpeg
# In the video element, webm should come before mp4.
for f in "$@"
do
dc="$(GetFileInfo -d "$f")" # store creation date
dm="$(GetFileInfo -m "$f")" # store modification date
noExt=$f:t:r
# -y does always overwrite existing files, -n skips if it already exists
/usr/local/bin/ffmpeg -n -i "$f" -vcodec h264 -acodec mp2 "$noExt".mp4
SetFile -d "$dc" "$noExt".mp4 # restore creation date
SetFile -m "$dm" "$noExt".mp4 # restore modification date
/usr/local/bin/ffmpeg -n -i "$f" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis "$noExt".webm
SetFile -d "$dc" "$noExt".webm # restore creation date
SetFile -m "$dm" "$noExt".webm # restore modification date
/usr/local/bin/ffmpeg -n -i "$f" -vframes 1 -f image2 poster.png # use frist frame as poster frame
echo "<video controls poster=\"poster.png\">" # add muted if there is no audio
echo " <source type=\"video/webm\" src=\"$noExt.webm\">"
echo " <source type=\"video/mp4\" src=\"$noExt.mp4\">"
echo "</video>"
done
|
Webm notes
Adjust the CRF value till the quality/size tradeoff is ok. Lower values produce bigger but better files. Try -threads 4
when it is slow, but no promises, measure it.