Last active
April 12, 2020 10:37
-
-
Save dmoney/bb6a64cbe1cad40ce4aebffc5e8d058c to your computer and use it in GitHub Desktop.
This file contains 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
How To Get A GIF From A Tweet | |
Twitter converts uploaded .gif files to a video for ease of use. However, | |
you may want to get this .gif file. As far as I know it's | |
not possible to download the raw .gif file, if any, that Twitter stores. | |
However, it is possible to download the video file using curl and | |
convert it to a gif using ffmpeg (though making a high quality .gif | |
may require some knowledge of ffmpeg's arcane parameters). | |
Instructions: | |
- download the HTML source code of the tweet containing the GIF | |
(note: view source doesn't work for this, because it won't contain the | |
thumb URL used in the next step) | |
curl https://twitter.com/<USER_HANDLE>/status/<TWEET_ID> > tweet.html | |
- in the source code, find a URL containing "tweet_video_thumb", e.g: | |
https://pbs.twimg.com/tweet_video_thumb/<VIDEO_ID>.jpg | |
(note: the video ID will be different from the tweet ID) | |
- this URL will end in <VIDEO_ID>.jpg (excluding brackets) | |
- using this ID, the video url is (also excluding brackets): | |
https://video.twimg.com/tweet_video/<VIDEO_ID>.mp4 | |
- get that file, e.g.: | |
curl https://video.twimg.com/tweet_video/<VIDEO_ID>.mp4 > video.mp4 | |
- convert to gif: | |
ffmpeg -i video.mp4 output.gif | |
- the gif will be of low quality. With ffmpeg wizardry it's possible to generate | |
a higher quality one. Some arcane parameters for doing that are described | |
here, but I haven't tried them out yet: | |
https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality | |
- And here: | |
https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment