Bad Apple! / Compressed video proof of concept


(Bruce) #1

I’ve had a go at squeezing the Bad Apple!! video down onto the arduboy. Unlike other consoles the video has been ported to, the issue is not speed, but storage. The arduboy has a fixed 32kb of program
memory, no way of expanding with cartridges. I’ve aimed for 11x8 resolution and 8 frames per second, which when uncompressed sits at ~27KB of memory, but the overhead of the libraries and arduino gunk pushes that up to about 40KB combined.

Video demo;
https://t.co/hbY4AjgUn6

My compression method pads the video to 16x8 resolution, 2 bytes per line. The left hand byte stores 5 data bits and 3 image bits, while the right hand byte stores 8 image bits. If the right byte can be matched to anything from the previous 31 bytes in the chain, it is discarded, and the distance to the matching byte is stored in the data bits. This compresses the source video down to 62%-ish, making room for other things like more frames or music, maybe. There is the odd bit of video corruption, but I think that’s down to my encoding tool, not the method used.

If anyone has a good idea on how to store the music alongside the video, I’m open to suggestions.


Arduboy custom bootloader
(Holmes) #2

Now that I see the original, this makes a lot more sense!


(Bruce) #3

Yeah, out of context it doesn’t mean much, just wanted to get the Arduboy on the list of consoles with a port. :stuck_out_tongue:
I have a few other ideas for compressing, but not any that would be effective enough to keep the video legible, sadly.


(Kevin) #4

Someone waiting on getting their Arduboy was able to compress the image down, but it doesn’t have any of the library or drawing functions.


(Scott) #5

Well, if you just want to see the video on the Arduboy’s screen, you could probably send the video data over USB from a PC.


(Molly C) #6

If you are doing this with the hope of using it as a basis for game cutscenes… you might take a tip from how they did things on the NES and animate sprites while moving them around. Could potentially allow for a much more pleasing approximation. I believe there is a function that will let one scale and rotate sprites on the fly.


(Scott R) #7

Bad Apple rocks, I used it for testing an oled using mplayer on a Pi a few years ago.

I happened to stumble on this arduino running Bad Apple on an ssd1306 there’s a link to the bitmaps in the description


(Erwin) #8

I had no idea that you can use he x3key remote in that way :nerd:


(Kevin) #9

Frick!

FMV looks so good!!!

I wish @bateske would hurry up and make an Arduboy with an SD card! Oh wait, thats me. :flushed:


(Pharap) #10

I held off on buying one specifically because I heard they were making a better Arduboy with an SD card slot. That was around christmas time I think :P, I’ve been ‘borrowing’ my friend’s kickstarter unit since before then.


(Molly C) #11

A modified version of gif might just compress a video small enough to fit some quality seconds. Dividing down the rez would allow for more time, and if you don’t do it quite as much the video might be discernible. gif format would have to be redesigned to take advantage of the framebuffer order. I think gif patent ran out and there is likely example source out there either way. I believe the gif animations are mostly diffs so only a fraction of the frame is being compressed along with vectors. One could likely compress the 1 bit frames in an ordinary gif and find out how much space it should take.


(Scott) #12

In the mean time, one could consider pulling in data from a PC via USB using the Serial functions.


(Pharap) #13

The gif format has too much guff.

The header block wastes 6 bytes, the logical screen descriptor is 7 bytes and uses 16-bit numbers (when realistically the Arduboy would only need 8 bits describing the image width and height), then it has an optimal global table which requires at least one byte to indicate that it’s been disabled, et cetera et cetera.

Long story short, it would be more efficient and probably easier to just use an entirely custom-made format that takes all the Arduboy’s limitations into account. All it would need to be is a series of (compressed) frames with a list of timings indicating which frame is to be displayed next and for how long.


(Molly C) #14

I think a modified version of the format might work. Since the payload should be modified so should the headers. One could even go so far as to assume we are dealing with arduboy and forgo the traditional header. Use an index into constant array to define header details. Decoding builds string tables which are likely going to be where one sees memory concerns.

I was thinking one could get better results replacing the string table compression with Huffman coding. I don’t see any reason why the table couldn’t be stored in PROGMEM so that would lower processing overhead Not that we are suffering from a lack of processor power. :laughing: It would avoid cluttering ram. Actually thinking about it making use of ram would be better for compression tables as well as generating them on the fly from data like gif does.

I think the most important part of any video format for the Arduboy is storing/compressing diffs avoiding whole frames as much as possible. There is going to be a threshold where storing diffs will approach the size of a full frame so those might as well be full frames.


(Molly C) #15

Searching for 1 bit animated gif didn’t yeild much results. Well except source. https://github.com/rexxars/ndarray-1bit-gif.
If I had the frames I could try it so see what size one could potentially get. Even the example http://i.imgur.com/66WoImN.gif is close to 32k and that is a 4bit gif. So I believe there is potential.


(Pharap) #16

It’s a bit of a Thesseus’s Ship paradox though.
Once you scrap the headers, the unnecessary 16-bit stuff, the colour table etc can you really say it’s based on gif anymore? At some point when you’ve removed enough features its effectively an entirely different format that doesn’t resemble gif anymore, at which point it might as well have been its own thing in the first place.

If you start from scratch and pluck the best bits of several different image formats you’ll end up with a better format overall. For example, PNG’s deflate algorithm (which is combination of huffman coding and LZ77) is typically much better than GIF’s LZW.

Without running tests though it’s impossible to say which method will work best. It might be the case that RLE works better than any of the fancier compression methods.

Be careful what you wish for.


(Molly C) #17

I may take a crack at a video demo when I’m done with the project I’m working on now. I don’t see video being practical for a game without external storage, but it is still a fun problem to mull over.


(Molly C) #18

I experimented with some frames we used to make the video for our game jam submission. I was able to get 207 frames down to about 24k with gif. And for lolz I 7ziped it. I think we might be able to come up with some worthwhile video compression if the 7zip source isn’t insanely huge. I know it is processor intensive, but we have way more processor than available space so…


(Pharap) #19

The 7z format supports LZMA, LZMA2, Bzip2, PPMd and DEFLATE as well as AES-256 encryption, unicode file names, various preprocessing features et cetera et cetera. There are 99 files alone for the different compression methods.


“I’ve got 99 files, but not a glitch in one.”

Seriously though, I think a custom file format would be much better.

I might work on a prototype myself later in the week, but I’ve got other projects on the go and there’s voting to be done.


(Molly C) #20

Inspecting the archive it claims to only be using LZMA:16 to compress the gif.