I’ll confess; I have never figured out how to make animated gifs work well. Other people don’t seem to have much trouble, but mine always wind up tiny, grainy, low-frame-rate, and with huge file sizes. So it’s great that one can upload videos to Twitter directly, instead of having to convert videos into animated gifs. But Twitter is very, very fussy about what video formats it will accept, and every time I need to do this, I lose half a day trying to remember the procedure for making Twitter accept my video files.
I don’t know why it never occurred to me to do this before, but now that I’ve figured it out (again), I’m just going to post the answer here as a blog post, so that I can find it again the next time I want to tweet a video. And maybe it’ll help somebody else, too.
I’ve been hopeless at getting my video editor to spit out video in a format which Twitter will accept, so (as is so often the case), a command-line tool has come to my rescue. I use the free and open source ffmpeg software to handle the conversion from whatever arbitrary format my video editor wants to use, into the very specific format that Twitter wants me to have used.
Here’s the command that does the magic:
ffmpeg -i INPUT_FILENAME -c:v libx264 -strict -2 OUTPUT_FILENAME.mp4
That’s it! If you want, you can be fancy and specify image filters and other adjustments during the conversion. But if your video is already edited and scaled like you want it to be, and if all you need to do is to just make Twitter stop complaining that “one selected file is not an image” and simply accept the video, then the above seems to reliably do that! And it’s what I used to make the videos embedded in my tweets, such as this one: