Skip to content

Instantly share code, notes, and snippets.

@adipasquale
Last active May 11, 2023 13:36
Show Gist options
  • Save adipasquale/af5684a3d70f10a4b59b2d75a002fafa to your computer and use it in GitHub Desktop.
Save adipasquale/af5684a3d70f10a4b59b2d75a002fafa to your computer and use it in GitHub Desktop.
Compress and convert videos with ffmpeg and automator
# open Automator
# create a new quick action
# select Movie files in Finder
# add action "Run Shell Script"
# select ruby as the shell and pass inputs as arguments
# enter this
require 'time'
ARGV.each do |input_path|
basename = File.basename(input_path, File.extname(input_path))
output_path = "#{File.dirname(input_path)}/#{basename}.compressed.#{Time.now.utc.iso8601}.mp4"
command = "/opt/homebrew/bin/ffmpeg -i #{input_path} -vcodec libx264 -crf 20 #{output_path}"
system command, exception: true
system %{say "compression finished for movie #{basename}"}, exception: true
end
# save with the name you’d like
# same as above with
require 'time'
ARGV.each do |input_path|
basename = File.basename(input_path, File.extname(input_path))
output_path = "#{File.dirname(input_path)}/#{basename}.#{Time.now.utc.iso8601}.webm"
command = "/opt/homebrew/bin/ffmpeg -i #{input_path} -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus #{output_path}"
system command, exception: true
system %{say "compression finished for movie #{basename}"}, exception: true
end
ffmpeg -i video.mp4 -vcodec libx265 -crf 30 video.mp4
ffmpeg -i video.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus video.webm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment