top | item 6633490

Stupid Programmer Tricks and Star Wars GIFs

311 points| chewxy | 12 years ago |rarlindseysmash.com | reply

45 comments

order
[+] btbuildem|12 years ago|reply
I would suggest ffmpeg as an alternative -- it peels, it slices and it dices. It will definitely convert a range of a video file to gif while adding subtitles, and you won't have to frankenstein things together..
[+] sigil|12 years ago|reply
Totally agree, although the author's use of vlc definitely qualifies as a clever hack.

I want more hackers to realize how insanely easy it is to programmatically generate video with ffmpeg. Just write a program that dumps raw RGB frames to stdout! You can turn that into any video format conceivable, including gif.

Here's a little demo I wrote. Generates a video of the Mandelbrot set coming into focus:

https://github.com/acg/generating-video-demo

Example gif:

http://imgur.com/RiqEHJJ

[+] mtrimpe|12 years ago|reply
There's even this (awesome) guide on optimizing video to gif conversion with ffmpeg and ImageMagick: http://blog.room208.org/post/48793543478

The file size reduction was quite impressive for our use case (roughly 10x smaller.)

In the end we did decide that while putting 5 second video intros in emails is cool, a 200k image is still a bit much for mobile users.

[+] lelandbatey|12 years ago|reply
Indeed, I have to vouch for ffmpeg as a the best solution. When I built GifMachine[0], it's pretty much just a web interface and automation layer to ffmpeg/imagemagick. Imagemagic and ffmpeg I found to be easy to use, fast, and delightfully scriptable. Using them together also produces the prettiest results.

For example, here's a gif produced with just ffmpeg: http://i.imgur.com/DWc4OdD.gif

And here is the version produced by ImageMagick: http://i.imgur.com/OdojPSo.gif

While the one made using ImageMagick looks better, it's also less compressed and takes up more space. So it's a tradeoff between the two.

[0] http://gifmachine.xwl.me/

[+] chewxy|12 years ago|reply
gstreamer too can be used. I prefer gstreamer as it really does embody the unix philosophy (in its own weird way though)
[+] oakwhiz|12 years ago|reply
avconv seems to be more up-to-date than ffmpeg.
[+] ryanthejuggler|12 years ago|reply
THIS.

Remember when you first discovered programming? When you did all those little projects that were, honestly, fairly useless, but brought you the spine-tingling sensation of having power over your domain?

Remember how when you started programming professionally, and you quit those projects? Why did that need to happen?

Bravo Lindsey, never stop making cool things.

(YMMV. I'm assuming of course that you learned programming as a hobby--if you learned by taking a college course then gasp you might have skipped the pointless-project phase entirely. I suggest you get on top of that.)

[+] Cthulhu_|12 years ago|reply
> Remember how when you started programming professionally, and you quit those projects? Why did that need to happen?

It didn't, I now get to spend 8+ hours a day working on things that matter, things that get me paid, thinks that make my customers (and their customers) happy, things that I see people use daily on their phone on my way to my next assignment.

Just because I work for a boss - and no, not some cool startup in the Valley - doesn't mean I don't do cool projects anymore.

(My pointless project phase was amongst others a scraper for InvisionFree forums, they would charge hundreds of dollars to get a copy of the database of a <50.000 post forum - and ours was over half a million posts big)

[+] ZoFreX|12 years ago|reply
Very, very cool. I love the approach, especially the interface that ties it all together! Nice trick to use subtitle files to grab the right bit of video automatically, too.

If anyone is thinking of doing something similar, or just wants to script some video in some way, I can highly recommend AviSynth. It fits into the extremely flexible DirectShow pipeline and has earned a permanent place in my video editing toolchain (I use it as the frameserver for encoding DVDs).

Here's an example script (if you have AviSynth installed and create a file with these contents named hello.avs, you can open it in any media player you choose to see the results):

    BlankClip()
    Subtitle("Hello, world!")
[+] noelwelsh|12 years ago|reply
Take this approach and apply it with CSS, a web framework, and a DB and you can go quite far in the .com game. You'll run into problems if you get popular, but that's a good problem to have.
[+] Cthulhu_|12 years ago|reply
And yet, you won't - it mostly depends, I think, where your video comes from. gifsoup (iirc) will scrape a youtube video and turn it into a .gif. There's probably quite a few youtube-to-gif services out there, come to think of it.

It'll be a problem if you use the original star wars video in one way or another though. I think. Depends on whether it can be considered fair use or not.

[+] chewxy|12 years ago|reply
This is what I call a great hack.
[+] jlgreco|12 years ago|reply
Assuming a random distribution of quotes from the twitter stream, and assuming there isn't any control on repeats, how long can we expect to be able to recreate the movies (well, the portions with dialog) in gif form?
[+] akx|12 years ago|reply
Neat. For the hell of it, I wanted to see how the same could be done with ffmpeg, so here's what I got in ~20 minutes:

https://gist.github.com/akx/7217852

(You could add a `-vf ass=my_subtitle_file.ass` to the ffmpeg command line burn subtitles into the gif.)

[+] KnightHawk3|12 years ago|reply
Not being good at ffmpeg, if I were to run it on a file with subtitles in the file (The most recent episode of an Anime for example), would it burn the subtitles in?
[+] sonnyz|12 years ago|reply
The subtitles files you can find online are formatted with timestamps to allow the video player to sync the text with the video, so for this purpose it makes perfect sense. Maybe set top boxes could make use of subtitles to allow users to search for a certain point in a video.
[+] mark_olson|12 years ago|reply
I did something similar (http://markolson.github.io/storyboard/) earlier this year using ffmpeg and ImageMagick to generate either GIFs around lines of dialog (like this project), or PDFs where each page is a frame of text or a new scene. Optimizing GIFs is by far the least enjoyable part.
[+] hox|12 years ago|reply
Damn you I was going to come post your storyboard. :(
[+] _pmf_|12 years ago|reply
The prevalence of the animated GIF is an eloquent statement about the current video encoding mess. While the typical small video clip today, encoded in a fancy new standard, is orders of magnitudes smaller that the JS+CSS+HTML site containing it, we use GIFs because nobody has any idea who is able to see the content is using a modern endoder.
[+] sdoering|12 years ago|reply
Was really informative to read. I am a novice in every programming aspect, as I am formally a product (or content) manager.

But using python as my tool for answering my bosses questions with data, I really enjoy reading posts like these, giving me ideas to learn and try new things.

Thanks a lot for that!

[+] gutsy|12 years ago|reply
This is awesome! I had no idea that you could programmatically do this (I still consider myself a novice even though I've been professionally coding for two years). Very, very cool!

Now I kinda want to try this.

[+] rflrob|12 years ago|reply
I wonder how hard it would be to introduce a cut detector, so that the (to me) annoying cinematic cuts that are sometimes at the beginning or end of a quote can be trimmed off. I think a simple heuristic of something like "If the frame cuts in the last half-second of the gif, trim off the extra frames" would work well, although I don't know how well a simple detector would work, nor how many quotes have a reaction shot that would get cut off unnecessarily.
[+] moccajoghurt|12 years ago|reply
I also enjoy gifs. I have been creating gifs with VirtualDub so far.

I usually prefer writing scripts to do stuff but VirtualDub is one of the few tools I simply use because I enjoy the open source and hacker spirit behind it.

An interesting plugin I miss for VD is an color reduction algorithm which would help to create very small gifs.

On reddit and tumblr gifs are a growing trend and it might be worth to put some effort into gif creation.

[+] lmm|12 years ago|reply
If you're going to do serious video editing, it's well worth learning avisynth.
[+] ge0rg|12 years ago|reply
This is brilliant. Now, instead of using random quotes, please take the IMDB quotes and make anigifs of them :)
[+] parennoob|12 years ago|reply
Am the only one who puts animated GIFs in the same category as the blink and marquee tags? Absolutely hate when there is more than one of these attention-seeking horrors on the page.

I've had to stop reading github's blog since they started putting thousands of these abhorrences there and started making it looks like a Buzzfeed page.