Created
October 6, 2021 18:12
-
-
Save jesseditson/fdef40dc7c130c53006713a0894745c6 to your computer and use it in GitHub Desktop.
Create an animated gif from a Dropbox Capture link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# 1. take a video with dropbox capture. | |
# 2. run this file. It will convert the video link from your pasteboard into a gif and replace it. | |
function chrome { | |
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $@ | |
} | |
TMPDIR=$(mktemp) | |
rm $TMPDIR | |
mkdir $TMPDIR | |
TMPFILE="$TMPDIR/video.ts" | |
videourl=$(pbpaste) | |
if [[ "${videourl:0:4}" != http ]]; then | |
echo "$videourl is not a url" | |
exit 1 | |
fi | |
dom=$(chrome --headless --run-all-compositor-stages-before-draw --virtual-time-budget=10000 --dump-dom $videourl) | |
echo $dom > "$TMPDIR/rendered.html" | |
plist1src=$(sed -rn "s/.*<video.*<source src=\"([^\"]+)\".*/\1/p" "$TMPDIR/rendered.html") | |
echo "fetching $plist1src" | |
curl $plist1src -o "$TMPDIR/plist1.m3u8" | |
plist2src=$(grep "type=video" "$TMPDIR/plist1.m3u8" | tail -n 1) | |
echo "fetching $plist2src" | |
curl "$plist2src" -o "$TMPDIR/plist2.m3u8" | |
video=$(grep "type=video" "$TMPDIR/plist2.m3u8" | tail -n 1) | |
echo "video URL: $video" | |
curl "$video" -o "$TMPFILE" | |
mkdir "$TMPDIR/frames" | |
open "$TMPDIR" | |
animation="$TMPDIR/animation.gif" | |
ffmpeg -i $TMPFILE -r 24 "$animation" | |
echo "animation: $animation" | |
# gifsicle --delay=18 --loop "$TMPDIR/frames/out*.png" > "$TMPDIR/animation.gif" | |
# convert -layers Optimize "$TMPDIR/animation.gif" "$TMPDIR/animation_optimized.gif" | |
osascript -e "set the clipboard to (read (POSIX file $animation) as GIF animation)" | |
echo "Press [k] to keep the files, any other key to delete them." | |
while : ; do | |
read -n 1 k <&1 | |
if [[ $k = k ]] ; then | |
break | |
else | |
rm -rf $TMPDIR | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment