Skip to main content
added 1331 characters in body
Source Link
vmrob
  • 261
  • 1
  • 5

If you wanted to create an automator workflow for this, you would want to use the "Run Shell Script" workflow item using the arguments as input. I had to modify it slightly as the resulting .app doesn't know where ffprobe, ffmpeg, or gifsicle are, so this solution is definitely not very portable and might require adjusting, but it's at least quick:

#!/bin/bash -e

# Converts a video to a gif

if [ "$#" -ne 1 ]; then
    echo "usage: ${0##*/} [input video]"
    exit 1
fi

TOOL_PATH=/usr/local/bin
VIDEO=$1
GIF=$VIDEO.gif

# finds width and height of $VIDEO expressed as 123x456
WIDTH_HEIGHT=$($TOOL_PATH/ffprobe -loglevel warning -show_streams $VIDEO | grep -e "width\|height" | sed -E 's/(width|height)=//g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/x/g')

# converts the video
$TOOL_PATH/ffmpeg -i $VIDEO -s $WIDTH_HEIGHT -r 10 -f gif - | $TOOL_PATH/gifsicle --optimize=3 --delay=3 > $GIF

You can then save the workflow as an app or service that works on files so that using it is as simple as dragging and dropping movies into it or right clicking on a video file:

image demonstrating conversion

I have no idea why it's apparently sped up though..


If you wanted to create an automator workflow for this, you would want to use the "Run Shell Script" workflow item using the arguments as input. I had to modify it slightly as the resulting .app doesn't know where ffprobe, ffmpeg, or gifsicle are, so this solution is definitely not very portable and might require adjusting, but it's at least quick:

#!/bin/bash -e

# Converts a video to a gif

if [ "$#" -ne 1 ]; then
    echo "usage: ${0##*/} [input video]"
    exit 1
fi

TOOL_PATH=/usr/local/bin
VIDEO=$1
GIF=$VIDEO.gif

# finds width and height of $VIDEO expressed as 123x456
WIDTH_HEIGHT=$($TOOL_PATH/ffprobe -loglevel warning -show_streams $VIDEO | grep -e "width\|height" | sed -E 's/(width|height)=//g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/x/g')

# converts the video
$TOOL_PATH/ffmpeg -i $VIDEO -s $WIDTH_HEIGHT -r 10 -f gif - | $TOOL_PATH/gifsicle --optimize=3 --delay=3 > $GIF

You can then save the workflow as an app or service that works on files so that using it is as simple as dragging and dropping movies into it or right clicking on a video file:

image demonstrating conversion

I have no idea why it's apparently sped up though..

added 681 characters in body
Source Link
vmrob
  • 261
  • 1
  • 5

I was actually trying to solve this problem for myself today and found this nice little Github gist:

https://gist.github.com/dergachev/4627207

Uses Quicktime to save a video, ffmpeg to convert the video, and gifsicle to compress/clean the final gif.

It uses the command line, so it might not be great for your use case, but I suspect this could easily be put into an Automator workflow.

Installation:

brew install ffmpeg 
brew cask install xquartz #dependency for gifsicle, only required for mountain-lion and above
brew install gifsicle

Converting:

ffmpeg -i in.mov -s 600x400 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif

The output resolution can (and probably should) be varied along with the file names.


For people wanting to produce a shell script to do the above, I came up with this:

https://gist.github.com/vmrob/27e4de2295c253edb7b3

#!/bin/bash -e

# Converts a video to a gif

if [ "$#" -ne 2 ]; then
    echo "usage: ${0##*/} [input video] [output gif]"
    exit 1
fi

VIDEO=$1
GIF=$2

# finds width and height of $VIDEO expressed as 123x456
WIDTH_HEIGHT=$(ffprobe -loglevel warning -show_streams $VIDEO | grep -e "width\|height" | sed -E 's/(width|height)=//g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/x/g')

# converts the video
ffmpeg -i $VIDEO -s $WIDTH_HEIGHT -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $GIF

I was actually trying to solve this problem for myself today and found this nice little Github gist:

https://gist.github.com/dergachev/4627207

Uses Quicktime to save a video, ffmpeg to convert the video, and gifsicle to compress/clean the final gif.

It uses the command line, so it might not be great for your use case, but I suspect this could easily be put into an Automator workflow.

Installation:

brew install ffmpeg 
brew cask install xquartz #dependency for gifsicle, only required for mountain-lion and above
brew install gifsicle

Converting:

ffmpeg -i in.mov -s 600x400 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif

The output resolution can (and probably should) be varied along with the file names.

I was actually trying to solve this problem for myself today and found this nice little Github gist:

https://gist.github.com/dergachev/4627207

Uses Quicktime to save a video, ffmpeg to convert the video, and gifsicle to compress/clean the final gif.

It uses the command line, so it might not be great for your use case, but I suspect this could easily be put into an Automator workflow.

Installation:

brew install ffmpeg 
brew cask install xquartz #dependency for gifsicle, only required for mountain-lion and above
brew install gifsicle

Converting:

ffmpeg -i in.mov -s 600x400 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif

The output resolution can (and probably should) be varied along with the file names.


For people wanting to produce a shell script to do the above, I came up with this:

https://gist.github.com/vmrob/27e4de2295c253edb7b3

#!/bin/bash -e

# Converts a video to a gif

if [ "$#" -ne 2 ]; then
    echo "usage: ${0##*/} [input video] [output gif]"
    exit 1
fi

VIDEO=$1
GIF=$2

# finds width and height of $VIDEO expressed as 123x456
WIDTH_HEIGHT=$(ffprobe -loglevel warning -show_streams $VIDEO | grep -e "width\|height" | sed -E 's/(width|height)=//g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/x/g')

# converts the video
ffmpeg -i $VIDEO -s $WIDTH_HEIGHT -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $GIF
Source Link
vmrob
  • 261
  • 1
  • 5

I was actually trying to solve this problem for myself today and found this nice little Github gist:

https://gist.github.com/dergachev/4627207

Uses Quicktime to save a video, ffmpeg to convert the video, and gifsicle to compress/clean the final gif.

It uses the command line, so it might not be great for your use case, but I suspect this could easily be put into an Automator workflow.

Installation:

brew install ffmpeg 
brew cask install xquartz #dependency for gifsicle, only required for mountain-lion and above
brew install gifsicle

Converting:

ffmpeg -i in.mov -s 600x400 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif

The output resolution can (and probably should) be varied along with the file names.