Schillsaver icon indicating copy to clipboard operation
Schillsaver copied to clipboard

Usage of color to store more bytes in a frame

Open Ceiridge opened this issue 4 years ago • 5 comments

Couldn't colored pixels make it possible to store more bytes in a pixel? At the moment, it's just 0 or 1, but a color RGB value consists of 4 bytes. Wouldn't that make more sense?

Ceiridge avatar Apr 11 '20 14:04 Ceiridge

Yup, it's been a long-time goal to move away from FFMPEG and implement custom en/decoders that handle multi-colored pixels. However, I wasn't able to find any good Java libraries to help handle reading/writing frames to/from an MP4 file when I last checked.

If you have any suggestions, I'm definitely open to trying things out again

Valkryst avatar Apr 11 '20 15:04 Valkryst

What's so bad about FFMPEG? Does it not support colored pixels?

Ceiridge avatar Apr 11 '20 15:04 Ceiridge

It's not that there's anything wrong with FFMPEG, but Schillsaver's currently written as a GUI wrapper around the FFMPEG executable. There's an encoding, and a decoding, command that handles all of the heavy work at the moment.

ffmpeg.exe -f rawvideo -pix_fmt monob -s 10x10 -r 60 -i inputfile.zip -vf scale=iw*10:-1 -sws_flags neighbor -c:v libx264 -threads 8 -loglevel verbse -preset veryfast -y outputfile.mp4

Note: This encoding command may be a little off, I rewrote it after quickly glancing at the code.

What I'd like to do is read-in the input file bit-by-bit, generate an in-memory frame (e.g. BufferedImage or VolatileImage), pass the in-memory frame to FFMPEG, and have FFMPEG append it to the output file. Those last three read-create-append steps would be run continuously, until all bits have been read.

From what I recall, and this was a year or two ago, the libraries that I tried mostly failed at appending the generated frames to an MP4 file or couldn't read the file frame-by-frame.

I could generate thousands of frames, save them to disk, and use the FFMPEG executable to concatenate them together into an MP4 file (and a similar process in-reverse when decoding), but that would be a considerable amount of HDD/SSD IO and I don't think it's practical for large files

Valkryst avatar Apr 11 '20 15:04 Valkryst

I think it could be worth trying to either change the source code of FFMPEG and recompile it, so that it is accessible with a JNI class and so that you can give it an array of integers or something by adding a function that is similar to the one that reads an input file.

Or you can maybe make another native tool that uses FFMPEG as a library and which calls FFMPEG's functions directly (for example: http://www.ffmpeg.org/doxygen/trunk/api-example_8c-source.html ) and embed it with JNI.

But then I would always recommend to do the calculations in that native tool too, because that could be much faster than Java and its BufferedImage

Ceiridge avatar Apr 11 '20 15:04 Ceiridge

Wow. I was just about to open an issue about using color for more data and here it is!! LOL

dillfrescott avatar Oct 21 '21 04:10 dillfrescott