PeterLemon / RaspberryPi

Raspberry Pi Bare Metal Assembly Programming
447 stars 67 forks source link

GRBLZVideo - creating lz format videos #11

Closed apkatsikas closed 7 years ago

apkatsikas commented 7 years ago

Hi,

Was wondering how I can get a video file into this format you use, lz.

PeterLemon commented 7 years ago

Hi Andrew,

The LZ77 format I use is exactly the same as the GBA Bios decompression routine with you can find information about here: http://problemkaputt.de/gbatek.htm#biosdecompressionfunctions

The video file (Video.lz), is just each frame of the animation, compressed using a GBA LZ77 compression tool. You can find the tool I use here: http://members.iinet.net.au/~freeaxs/gbacomp/files/gbacrusher.zip http://members.iinet.net.au/~freeaxs/gbacomp/#GBA Crusher

There is a command-line version of this tool inside that archive called "gbacrushercl". I use it like this to create each compresed frame: "gbacrushercl -L 00000001.grb -O 00000001.lz"

Once I have all the frames compressed into seperate .lz compressed files, I concat them all together: "copy /b *.lz Video.lz"

So now you will probably ask what a ".grb" file is, so I will explain that...

GRB frames are my own simple replacement for the more commonly used YUV files used in MPEG etc.

The human eye is sensitive to different colors: Green 70%, Red 20%, Blue 10%

The GRB frame uses these psychovisual properties of the human eye, to save the RGB layers like this:

Green channel is saved at the full resolution: 320x240 pixels (76800 bytes) Red channel is saved at 1/2 resolution: 160x120 pixels (19200 bytes) Blue channel is saved at 1/4 resolution: 80x60 pixels (4800 bytes)

I then just concat the data of Green,Red,Blue channels together in that order to create the ".grb" file: Green 320x240 + Red 160x120 + Blue 80x60 = 100800 bytes.

You can see this is much smaller than if I just kept the R,G,B channels at full size which would be 76800*3 (230400 bytes).

I also use a gimp script to scale using the "Cubic" filter, the Red & Blue color channel images to their smaller resolutions, which improves overall visual quality.

I hope this helps you out, I am gonna close this issue now =D

apkatsikas commented 7 years ago

@PeterLemon wow! thank you so much, very impressive stuff :)

apkatsikas commented 7 years ago

@PeterLemon could you share a sample grb file with me? I want to make my own and would like to see an example if possible. thanks!

Or asked another way, if i use ImageMagick to extract/separate the RGB channels, does it matter what format the image is in, and when i go to concatenate the image files (in Green, Red, Blue order), do i just change the file extension to .grb and the file is complete?

PeterLemon commented 7 years ago

Hi Andrew,

You can use one of the many GBA/NDS extraction utils available, to grab ".grb" files from my videos.

You can find one here called "LZ77 Restructor 2": http://www.romhacking.net/utilities/973/

  1. Run this program & open the "Video.lz" file. (You will need to select "Files of type/All files", to see the .lz file extension)

  2. On the left tab, you will see a selection of 5 files / 656, that is has found, select one of the files.

  3. Click on the "Hex+Text" switch, then the "Extract Selected" button.

  4. Name the file you want to save, and once it has saved you will have an extracted ".grb" file from that video (100800 bytes)

Hope this helps you out.

apkatsikas commented 7 years ago

@PeterLemon - thank you so much for the info, will be trying this out soon. if i have additional questions is it OK to follow up here?

PeterLemon commented 7 years ago

Hi Andrew, Yeah sure, you can ask me any questions to follow up here.

apkatsikas commented 1 year ago

Hi @PeterLemon! it took me many years to give this a try, but now that i am a more confident and experienced programmer, i got it running!

https://www.youtube.com/watch?v=S8icTC9zRAc

My only issue is it does not loop and then it freezes, whereas your example loops forever (desired behavior for me as well).

My process is here:

https://github.com/apkatsikas/pi-video

When i open my concat-ed lz file, it looks like this: image

notably, mine shows only 1 element of 159, vs. your files 5. also of note, i only used 155 frames for this animation, so im not sure where the other 4 are coming from. i also noticed your starts with a few test frames, it looks like, whereas mine does not.

Other things to consider:

I could process my array differently like this https://github.com/apkatsikas/pi-video/blob/fc316f29794ba68453592231e06337367fa3cc68/process.py#L10

I could specify a different length, byte order or signed options https://github.com/apkatsikas/pi-video/blob/fc316f29794ba68453592231e06337367fa3cc68/process.py#L45

I could write bytes more like this https://github.com/apkatsikas/pi-video/blob/fc316f29794ba68453592231e06337367fa3cc68/process.py#L50

apkatsikas commented 1 year ago

could it have to do with this line? https://github.com/PeterLemon/RaspberryPi/blob/5783e31ba16353413a9248431da464e37a5619d1/Video/GRBLZVideo/kernel.asm#L35

im also curious how your 656 frames is represented here as 615.