Author Topic: Four Level Grayscale Video  (Read 32262 times)

0 Members and 1 Guest are viewing this topic.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Four Level Grayscale Video
« Reply #90 on: February 19, 2011, 08:41:06 pm »
@Thepenguin77: That smash bros. video looks great!, and I'm glad compression is working now. =)

@apcalc: Do you mean that super can now export a video as a series of BMPs?

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Four Level Grayscale Video
« Reply #91 on: February 19, 2011, 08:41:44 pm »
@apcalc: Do you mean that super can now export a video as a series of BMPs?

Yep! :)


Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Four Level Grayscale Video
« Reply #92 on: February 19, 2011, 08:44:06 pm »
Ah, that's pretty cool actually. It should have (and appears to have been) an easy add for them anyways. :)

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: Four Level Grayscale Video
« Reply #93 on: March 01, 2011, 02:46:16 pm »
Awesome job! This topic reminded me of a video player I was writing back in 2009 but never finished. My video codec only supports monochrome videos (only dithering, no grayscale), though, so it's not really the same as yours. With the way it works, it would probably be difficult to adapt to grayscale too.

I wrote an encoder and decoder that run on my computer, but I designed the compression format to make it fast and easy to decode on a 6MHz Z80 (I was targeting my trusty ol' TI-86). The GIF animation I attached shows the output of the decoder (after scaling and stretching it to the same aspect ratio as the TI-86 screen and converting to GIF). The video is 4:36 long and runs at about 8 fps. The compressed video is 577 KB long, so it's about 260 bytes per frame, or 2KB/s. The source is Red Hot Chili Pepper's "Can't Stop" music video. :)

I think I used FFMPEG to dump the video to individual images (I can't remember what format it dumps to, probably JPEG), eventually converted them to Portable Pixmap (PPM) format, scaled and cropped them, dithered them, and then concatenated them into one file, for my encoder to read. These steps are all fairly easy to do in batch with the NetPBM utilities.

Here's how the decoder works: the input file contains a list of 8x8 pixel tiles. The decoder saves these for later. Each frame consists of 16x8 tiles (128x64 screen / 8x8) running from top to bottom, left to right (column-major order). For each tile, the decoder reads a byte. If the byte is less than 128, then it is an index into the list of tiles. If the byte is 255, then the decoder reads in 8 more bytes and uses those as a "literal" tile. Whichever tile it uses (either from the list or a "literal" tile), the decoder XOR's the tile onto the previous frame at the current tile location. I chose to use XOR so the video can be played backwards (eg, rewinding) easily. To play a video backwards, the decoder XOR's the tiles exactly the same way.

Besides 0-127 and 255, there are several other byte values that are special too. The values between 128 and 143 mean "rotate the tile in the frame". By rotate I mean rotate each byte left or right, and rotate the bytes up or down. This is kind of like shifting the tile horizontally and vertically, but since I'm rotating the tiles, it's reversible (again, so the video can be played backwards). Bits 0 and 1 indicate how many pixels to rotate horizontally (-2, -1, 1, or 2), and bits 2 and 3 are for the vertical shift amount (same as the horizontal). Like the tile XOR operations, tile rotations operate on the tile in the previous frame. To play a video backward, the decoder has to rotate each tile in the opposite direction.

This leaves byte values 144 through 254 for other reversible operations. These are currently unused in my decoder but might be used in the future.

Here's the overall byte format:

video header:
1 byte=n (number of tiles)
8*n bytes=tile data

frame:
1 byte=frame type (most are 2 for "cumulative", but other values are possible, eg, 0 for end of stream)
128 tiles

tile:
1 byte=transformation type
8 bytes=literal tile (if type=255)

I haven't done this yet, but at the end of each frame I should probably write a 2-byte value that says how large that frame was, so the decoder can skip to the beginning of each frame when playing a video backwards.

One other idea I was playing with is to losslessly compress each lossy-compressed frame, but initial results show larger file sizes when this is done. It could be that the RLE compression method that I used on the frame data just isn't suitable for that type of data (I think it was basically the RLE used by the PCX format). This is an area I'll investigate further.

Based on this description of the decoder, it should be obvious how the encoder works, right? :) It basically just has to come up with a good set of tiles to pass to the decoder, and then for each tile within each frame, decide which tile adjustment (using a tile index, literal tile, or other transformation) results in the "best-looking" tile in the output. "Best looking" is subjective, so the encoder really determines the quality/size tradeoff (up to the hard limits of the format, which is currently 129 bytes/frame minimum).

Edit: tiles are actually stored in column-major order, not row-major order. That should make decoding slightly faster than row-major order.
« Last Edit: March 01, 2011, 04:08:41 pm by christop »
Christopher Williams

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Four Level Grayscale Video
« Reply #94 on: March 03, 2011, 04:10:40 am »
That's quite nice actually. Actually at such compression you can fit a lot more too. It doesn't look as great but on higher-res calcs it could probably look better due to smaller pixels reducing the dithering effect.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Four Level Grayscale Video
« Reply #95 on: March 03, 2011, 11:05:53 am »
I think that if you added a new dithering algorithm, you could even get that to look even nicer!  Try this one on for size! http://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering :D

Offline Freyaday

  • The One And Only Serial Time Killing Catboy-Capoeirista-Ballerino
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1970
  • Rating: +128/-15
  • I put on my robe and pixel hat...
    • View Profile
Re: Four Level Grayscale Video
« Reply #96 on: March 03, 2011, 03:40:26 pm »
I bow the presence of these programs. I have so much to learn. *Weeps*
In other news, Frey continues kicking unprecedented levels of ass.
Proud member of LF#N--Lolis For #9678B6 Names


I'm a performer at heart; I stole it last week.
My Artwork!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Four Level Grayscale Video
« Reply #97 on: March 03, 2011, 03:45:09 pm »
Btw I wonder if Christop algorithm is the same as the one used in the RealSound video player that got featured on ticalc.org a few years ago?

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: Four Level Grayscale Video
« Reply #98 on: March 03, 2011, 04:07:46 pm »
Btw I wonder if Christop algorithm is the same as the one used in the RealSound video player that got featured on ticalc.org a few years ago?
Are you referring to this one? http://www.ticalc.org/archives/files/fileinfo/385/38513.html

As far as I know, that only plays sound. That is the only RealSound player I could find on ticalc.

Regarding Floyd-Steinberg dithering, yes, it looks better (I tried it already), but it decreases the amount of compression possible because it changes more pixels between frames than ordered (Bayer) dithering. A better encoder might do a better job at handling it, though. (A better encoder might pass through the video twice: once to generate the best tile set for that video, and then again to do the actual encoding)
Christopher Williams

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Four Level Grayscale Video
« Reply #99 on: March 04, 2011, 02:16:00 am »
Actually nevermind, it was not RealSound 2 but another video thing by Dan Englender:

http://www.ticalc.org/archives/news/articles/13/130/130297.html

RealSound 2 was an update to the app you linked to, which added video support. However it never actually got released. There's also TIMM, but it only created 8xp files, since it was made back when the 83+ SDK was not free and nobody wanted to develop Flash apps.

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: Four Level Grayscale Video
« Reply #100 on: March 10, 2011, 11:20:09 pm »
?? That link is to a ticalc news for usb8x.  ??
NVM, I had no idea.  :P
« Last Edit: March 11, 2011, 12:04:20 am by ralphdspam »
ld a, 0
ld a, a

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Four Level Grayscale Video
« Reply #101 on: March 11, 2011, 12:02:33 am »
USB8X has a vid player. They demonstrated it with a cutscene from the matrix :P but it's monochrome
« Last Edit: March 11, 2011, 12:02:47 am by willrandship »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Four Level Grayscale Video
« Reply #102 on: March 11, 2011, 03:03:29 am »
I always wondered if USB8x works via the TI-Nspire in 84+ mode, but then we're getting a bit off topic. :P

Offline ikemike

  • LV3 Member (Next: 100)
  • ***
  • Posts: 67
  • Rating: +4/-0
  • Hmm.
    • View Profile
Re: Four Level Grayscale Video
« Reply #103 on: March 28, 2011, 11:55:01 am »
What file type of movie can USB8X play? It'd be indescribably epic to sit and watch anime in class.
Anonymous Legend

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Four Level Grayscale Video
« Reply #104 on: March 28, 2011, 12:29:42 pm »
What file type of movie can USB8X play? It'd be indescribably epic to sit and watch anime in class.
USB8X itself doesn't have a movie player - the player is separate. I don't know where the player can be found, or what it supports...