Movie Barcode Generator
python process_video.py inputfile width height
python process_video.py bigbuckbunny.mp4 320 180
- If it doesn't work on Windows, you might have to change FFMPEG_BIN from "ffmpeg" to "ffmpeg.exe"
- Use low resolution videos! They provide identical results but are processed exponentially faster than high definition videos (I've seen above 1300fps). You're smearing all the details anyway.
- By default, the resulting image will be as wide as the number of frames in the movie - probably several tens of thousands of pixels. However due to the nature of PNG files, it will only be a few hundred kilobytes! But you will need to use Photoshop or similar to format the images to your liking... or patch my code so the user can specify output size!
You may have seen sites like moviebarcode, The Colors of Motion or the Movie Barcode Generator. In short, they compress a movie into a single image, with vertical lines representing the average colours of sequential frames. Ideally this gives a glanceable idea of the movie's colour palette.
While moviebarcode squashes each frame to a single pixel width (preserving some vertical gradients), this script uses a similar process to The Colors of Motion (a single colour per frame). First find the average RGB values of all pixels in a single frame:
And then to repeat the process for all frames:
This should work with any movie file ffmpeg can handle (though in practice I've only tested it with mp4 files).
- I'd love to autodetect the video resolution but this seems to require grepping some ffmpeg output.
- There may be is almost certainly a faster approach than the one I'm using. Perhaps I should only take every nth frame?
- Users should be able to specify an output size instead of having to manually edit the file.
(Images: Big Buck Bunny)