hackffm / ESP32_BadApple
Bad Apple video by Touhou on ESP32 with SSD1306 OLED, uses the Heatshrink compression library to decompress the RLE encoded video data.
rem OLED 128x64のサイズに動画をリサイズ
ffmpeg.exe -i "[Touhou] Bad Apple!! PV [Shadow]" -vf "scale=128:64" ba_oled.mp4
rem 動画の全フレームを PNGファイルに書き出し
mkdir scene
ffmpeg.exe -i ba_oled.mp4 ./scene/%05d.png
● WSL上で heatshrinkをビルドして動画データを圧縮する
# heatshrinkをビルドする
git clone https://github.com/atomicobject/heatshrink
cd heatshrink
make
# sceneディレクトリに全フレームの PNGファイル(6573個)をコピーしておく
ls -l ./scene
# Compress.pyで PNGファイルを RLE圧縮する
rm video.*
python Compress.py
# 1150898
# Done
# heatshrinkで更に圧縮する
# RLE to heatshrink
./heatshrink -e video.bin video.hs
ls -l video.*
# -rw-r--r-- 1 user user 1150898 Feb 26 00:31 video.bin
# -rw-r--r-- 1 user user 585822 Feb 26 00:32 video.hs
# -rw-r--r-- 1 user user 6730752 Feb 26 00:31 video.uc
90度回転版は元データの 10%以下!
byte
圧縮率(元の何%か)
元データ 6573フレーム
6730752
100.0%
RLE圧縮
1150898
17.1%
heatshrink圧縮
585822
8.7% (50.9%)
$ ./heatshrink -h
heatshrink version 0.4.1 by Scott Vokes <vokes.s@gmail.com>
Home page: https://github.com/atomicobject/heatshrink
Usage:
heatshrink [-h] [-e|-d] [-v] [-w SIZE] [-l BITS] [IN_FILE] [OUT_FILE]
heatshrink compresses or decompresses byte streams using LZSS, and is
designed especially for embedded, low-memory, and/or hard real-time
systems.
-h print help
-e encode (compress, default)
-d decode (decompress)
-v verbose (print input & output sizes, compression ratio, etc.)
-w SIZE Base-2 log of LZSS sliding window size
A larger value allows searches a larger history of the data for repeated
patterns, potentially compressing more effectively, but will use
more memory and processing time.
Recommended default: -w 8 (embedded systems), -w 10 (elsewhere)
-l BITS Number of bits used for back-reference lengths
A larger value allows longer substitutions, but since all
back-references must use -w + -l bits, larger -w or -l can be
counterproductive if most patterns are small and/or local.
Recommended default: -l 4
If IN_FILE or OUT_FILE are unspecified, they will default to
"-" for standard input and standard output, respectively.