Movie Barcodes

I loved the Moviebarcode site that I found via MetaFilter and wanted to create some barcodes of my own. After a bit of fiddling I managed to produce some reasonable facsimiles using a combination of VLC and ImageMagick.

This example barcode is from Sleep Dealer.

I used VLC under Windows 7 and ImageMagick under Ubuntu Linux because that’s where they were already installed, but I imagine the commands are pretty similar irrespective of which OS you are using.

Step 1 – Extract images

vlc movie.avi --video-filter=scene --scene-prefix=movie --scene-ratio=90 --scene-path=c:\movie

The important option is scene-ratio which tells VLC how many frames to capture. A value of 90 captures every ninetieth frame and will create about two thousand images for a two hour film; VLC creates .png files by default but you can force it to create JPEGs by adding --scene-format=jpg. The scene-path command tells VLC where to store the images; if you omit this option it uses the default folder (My Pictures in Windows).

This step does require VLC to play the whole movie at normal speed, but muting the sound and leaving it running in the background isn’t a problem.

Step 2 – Resize images

To create the barcode each frame needs to be reduced to one pixel wide using ImageMagick. You can do this in two ways: resizing or cropping. Resizing gives a better “average” of the frame but cropping gives a sharper image. These commands also convert the .png files to .jpg files which helps to save disk space.

convert *.png -resize 1x{screenshot height}\! movie.jpg

convert *.png -crop 1x{screenshot height}+X+Y movie.jpg

The \! option prevents ImageMagick from preserving the aspect ratio of the original image when resizing and the +X and +Y options tell ImageMagick where in the image to crop; you probably want to select X to be halfway across your image and Y to be zero. In both cases you’ll need to replace {screenshot height} with whatever the size of your original screenshots is.

Step 3 – Assemble barcode

Using ImageMagick:

montage -geometry +0+0 -tile x1 *.jpg barcode.png

The -geometry +0+0 command ensures that there is no border between images and the -tile x1 option tells ImageMagick to create a montage that is only one image high, i.e. one long stream. You need to be careful with how your files are numbered before this stage because ImageMagick works alphabetically and will add image100.jpg before image20.jpg.

Step 4 (optional) – Smooth barcode

If you want a smoother result you can shrink the barcode down to one pixel high and then expand it back out to your desired size. Shrinking finds the average colour and when expanding back out the you get a smooth result containing only the averaged colour.

Smoothed version of the example Sleep Dealer barcode.

If you have any problems, questions or hints, or if you want me to produce a movie barcode for you, post in the comments below.


57 thoughts on “Movie Barcodes

  1. Thanks for figuring this out, it’s fun!

    Just wanted to let you know that there’s a much faster way of doing the first step if you have access to mplayer. You can do:

    mplayer -framedrop -speed 100 -vf framestep=90 -nosound -vo jpeg movie.avi

    Where, as above, -framestep=90 means extract every 90th frame. the -vo jpeg writes things out as jpegs (you can do -vo png if you want, but since we’re going to jpeg later anyway it’s mostly a waste of space).

    The -speed 100 tells mplayer to try and play back at 100 times the standard speed. my computer couldn’t quite go that fast, but it did manage to do an hour of 1280×720 video in about 15 minutes, so that’s certainly an improvement. the -framedrop and -nosound are just optimizations, which are not technically needed but will probably make things go a bit faster.

    Finally, here’s a barcode I made of episode 1 of Carnivale. It looks about as I expected.

  2. I ripped more than 11.000 frames from the movie Amelie. Now I want to combine those through Image-Magick. Problem is that IM save everything into memory before outputting. My whole computer holds at that moment. Using more than 16Gigs of RAM. Is there a way to let image magick do the resizing frame by frame?

  3. Could you rename a thousand at a time, and process each as a batch? 11000 frames is a lot of images though – do you really need that many?

  4. how do you do step 1? can anyone guide me through the process? I don’t know how to work around these command lines. I’m using VLC, windows 7

  5. To be brutally honest, if you’re not happy working with the command line, then this process is probably not for you. :(

    I used Windows 7 and Ubuntu because that’s where the software was installed; it is possible to do the entire process under Windows if you want.

  6. Yes this is new to me. :| But I think this movie barcode is a pretty neat project and I would love to try it. thanks for the reply!

  7. I’m trying to barcode pulp fiction, and maybe schindler’s list. Anyway, I finally managed to get Step 1 done. phew

  8. curious, how did you set it to name your files? even if i add a few digit padding, it seems to jumble the images in the final montage. Thoughts?
    thanks~

  9. Or, you could use this process, worked great for me:

    montage -geometry +0+0 -tile x1 'ls -1rtc NAME*.jpg |xargs' NAME.png

    which lists the files in the correct order.

  10. What utility did you use to make sure the file had the correct file names? And what logic did you use in naming them? Leading zeroes? Thanks.

  11. I used Métamorphose to rename files (sorting by modification date/time) and did use leading zeros to make sure that they’d be sorted into the right order.

  12. I tried to do the exact same thing, but using a program called File Renamer, and run into the problem that hundreds of files were last modified at the exact same time down to the second.

    Is it perhaps because I’m in Windows? Does Linux use a more precise timestamp? I’m going to have a look at Métamorphose and see if perhaps the problem lies with File Renamer.

    Thanks.

  13. Yup. It works great using Métamorphose.

    Thanks!

  14. Hey, is there any chance of you creating a barcode of “The Picture of Dorian Gray”? I’m not really proficient at computing but I would appreciate the barcode very, very much.

  15. Hey, thank you for the idea. I’ve write small perl program to simplify the whole process. Only mplayer and ImageMagick is needed, and the process is very simple: run perl script and give to movie file. You got in a few minutes barcode.png file from the whole movie! The script is free, I’ve put it on my page, but I would like to say THANK YOU. I’ve linked to this page as a source of information, and you can take my script ;)
    This is a link to script and this is a link to page with the information.
    The script is able to convert HUGE amount of frames and memory error is fixed – instead of converting all files at once, I’ve decided to convert them one by one. This takes longer time, but your convert process will never be killed. On my PC with 8GB ram it is likely to be killed even for 1500 frames. So, here it is! Thank you for the whole blog, it is VERY interesting. Keep up the good work! I like it!

  16. Hey, I’d love if you could make one for me if your still doing that just email me if you would, thanks. – Alex

  17. Hi,
    I’m only vaguely familiar with the command line code- I tend to fall down if it’s not matlab! I run a mac and was curious how (if you knew) to use the terminal to execute such commands, if indeed that is the process to do it. And is ImageMagick necessary?
    Thanks,

    Andy

    Also- love your site. I’ve referred a few people to the nuclear section!

  18. I’m glad you like this site.

    I’m afraid I’m not a Mac person; I have no idea how they work and therefore no idea if you can use the terminal; I’m sure there’s a way to do it without ImageMagick but I don’t know how that would work – perhaps some sort of scripting plugin for PhotoShop etc. I think you’ll need to find yourself a Mac expert.

  19. I’ve sorted it, well, the majority! I’ve managed to make a barcode after figuring out how to install ImageMagick, and I’ve now got the hang of Terminal. Just took some googling. Just going to try the smoothing method now.

  20. All I have to recommend is replacing ImageMa­gick ‘convert’ with ‘mogrify.’ Retains the same options — mogrify simply modifies the files in place, rather than creating new. The benefit is fewer files to delete after completing the montage operation.

    Experimenting with alternate commands to capture frames — none of which proved superior to Nick’s in the first comment above — I hit upon a command line that provides an audio compliment to a movie barcode:

    mplayer -sstep 5 -vc null -vo null -ao pcm:waveheader movie.avi

    This results in a default file named audiodump.wav consisting of split second bursts of the movie’s audio track at five second intervals (the latter modified by the value of the -sstep option). Equalization to cut off frequencies above 6000 Hz helps reduce clicks.

    It’s fascinating the extent to which the source remains recognizable. I’ll leave it to readers to discern for themselves the cinema classic put through the shredder to yield this example.

  21. Hey,

    Nice post, but I’m not sure I understand this at all. Is there a how to make these for Dummies link? Anything more simpler on where and how exactly to start? Not sure I’m familiar with all the commands or how they are being used. Any info would help!

  22. If you’re not familiar with using the command line then this process probably isn’t for you; the instructions I’ve provided are about as for Dummies as I can get. Maybe someone else can offer better instructions? What movie are you trying to barcode?

  23. Great write up!

    One question, optional step 4 says you can shrink to 1px high to get an average of the colors to smooth. Is this a command I change in step 3 or do I use GIMP to do this?

    If I need to change the command what would it be changed to?

    Thanks again.

  24. I have tried for days to get this to work and I just can’t seem to make it right. I have all the frames reduced to slivers but I can’t get them together. Could I e-mail the frames to you and would you put them together for me and send the result back? I would really appreciate it.

  25. An old Irish animated film called Charlie. I can host the images on a third party website instead of having to send a large, slow e-mail attachment for you.

  26. Hi there
    I’ve enjoyed going through your method. I guess I have mixed ability.
    The imagemagick command doesn’t work for me and i’m not sure how to troubleshoot.
    i am on win7, and i installed imagemagick. Here’s my command and error:

    convert *.png -resize 1x{288}\! movie.jpg
    convert.exe: invalid argument for option `-resize’: 1x{288}\! @ error/convert.c/
    ConvertImageCommand/2355.

    help!

  27. Hey Mr. Reid!

    Any chance you could barcode “Grease” for a late christmas gift for my aunt?

    Thanks!
    Ben

Leave a Reply