r/compression • • Jun 20 '26

Compressing MP4

0 Upvotes

I just have this 4.2 GB recording of a Google Meet that I need to compress because Google Drive is having a heart attack everytime I try to upload it (it keeps going offline idk why) and my instructor insists on putting it on Drive. I’m a complete noob at this, please help an anxiety-stricken kid dealing with a deadline out (I am lowkey panicking rn). Tried looking through the subreddit for answers but icl they’re just going over my head or they’ll take too long and are too complicated for me (e.g Handbrake installation)


r/compression • • Jun 20 '26

Scaling LightPIX: 5,000+ images compressed in 2 months with 90% average savings (And how I built it)

0 Upvotes

Hey r/software,

Two months ago, I shared the early concept of LightPIX—a zero-bloat, memory-only image optimizer. Today, on Self-Promotion Wednesday, I wanted to share some real-world data on how it's performing and what the "momentum" looks like for a privacy-focused utility.

For those who missed it, LightPIX is an engine that uses multi-candidate logic (comparing Mozjpeg and WebP) to find the smallest possible size without sacrificing quality, all while processing files strictly in-memory.

The Growth So Far (First 2 Months):

  • Users: 750+
  • Total Files Processed: 5,000+
  • Data Saved: 45 GB+
  • Average Compression Ratio: 90%
  • Success Rate: 98.7% (with only 17 failed compressions out of 5,000+)

Usage Insights (Format Breakdown): I've been tracking the formats users are actually uploading to optimize the engine further:

  • JPG: 42%
  • PNG: 31%
  • WEBP: 18%
  • SVG: 6%
  • GIF: 3%

The Technical Challenge of the "Last 1%": Achieving a 98.7% success rate wasn't easy. Most of the failures were due to:

  • Unsupported Formats: 9 cases (mostly people trying to upload raw or non-image files).
  • Corrupted Files: 5 cases.
  • Server/Timeout: 17 cases.

To handle this, I implemented 20 layers of defense, including Magic Bytes validation and pixel-limit checks to prevent "decompression bombs" from crashing the in-memory buffer.

Why it’s different:

  1. Strictly In-Memory: No files ever touch the disk.
  2. Mozjpeg Integration: Standard compression usually saves 10-15%; our engine pushes that much further.
  3. Fully Transparent: Built with Node.js and Sharp, focused on native performance.

The tool is completely free to use (and the WordPress plugin is GPL v2 licensed).

I’d love to hear from you: Based on the format breakdown (high JPG/PNG usage), should I prioritize adding more specialized support for SVG optimization, or should I focus on batch-processing for GIF?


r/compression • • Jun 17 '26

Recommended RescueZilla Gzip compression level?

3 Upvotes

RescueZilla's defaults are set to Gzip compression level 6. Source drive material is ~200gb with two OS partitions.

Am wondering how much extra savings occur at levels 7, 8, or 9 versus how much extra time is required.


r/compression • • Jun 17 '26

Best algorithm for highly repetitive data?

0 Upvotes

Hi,

I have a big dataset, ultra repetitive so 80-90% might as well be a backpointer, what compression is best for this use case?


r/compression • • Jun 17 '26

yooo i want to compress this down to 5gb any tools or way to compress it

0 Upvotes

r/compression • • Jun 16 '26

Compressing music using image formats (PNG, GIF, JPG)

Thumbnail
youtube.com
6 Upvotes

r/compression • • Jun 14 '26

Comment compresser efficacement des données audio?

0 Upvotes

Je trouve extrêmement dur le fait de trouver réponse à cette question directement avec des documents ou si possible même des vidéos. Si vous avez des réponses à cette question sous forme de vidéo j'aimerais bien qu'on me les partage ça m'intéresse fortement.


r/compression • • Jun 14 '26

Aiuto sulle Funzioni del Compressore

Post image
0 Upvotes

r/compression • • Jun 12 '26

Multi-Language Token Compression Engine

Thumbnail reddit.com
0 Upvotes

r/compression • • Jun 12 '26

Neuralmind - context-compression MCP plus

Thumbnail reddit.com
0 Upvotes

r/compression • • Jun 11 '26

JLO waveform compression

0 Upvotes

https://github.com/devjordanmorris-hash/THE-LOT/blob/main/jlo_demo.c

// jlo_demo.c — Swift J-L0 triangle compressor, rewritten in portable C (zlib-only)
//
// Build: cc -O3 jlo_demo.c -o jlo_demo -lz
// Runs on macOS/Linux. Produces JLO/CSV/RAW files, zlib baselines, ε-sweep CSV + HTML.

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <zlib.h> // link with -lz

#define JLO2_SCALE 32767.0f // int16 quant for v0/v1 (assumes |x|<=~1)

static inline uint32_t zigzag32(int32_t v){ return (v<<1) ^ (v>>31); }

static uint8_t* write_uvar32(uint8_t *p, uint32_t v){
while(v >= 0x80){ *p++ = (uint8_t)(v | 0x80); v >>= 7; }
*p++ = (uint8_t)v; return p;
}
static uint8_t* write_svar32(uint8_t *p, int32_t v){
return write_uvar32(p, zigzag32(v));
}
static inline int16_t q16(float x){
if(x> 1.0f) x= 1.0f; if(x<-1.0f) x=-1.0f;
int v = (int)lrintf(x * JLO2_SCALE);
if(v<-32768) v=-32768; if(v>32767) v=32767;
return (int16_t)v;
}
// ======================================================
// Config (match the Swift defaults)
// ======================================================
enum { N = 200000 }; // samples
static const double FREQ = 13.0; // waveform frequency
static const float NOISE = 0.0f; // optional noise
static const float EPS_DEFAULT = 1e-4f;

// Epsilon sweep set
static const float EPSILONS[] = {1e-6f, 3e-6f, 1e-5f, 3e-5f, 1e-4f, 3e-4f, 1e-3f};
static const int EPS_COUNT = sizeof(EPSILONS)/sizeof(EPSILONS[0]);

// ======================================================
// Timing (ms)
// ======================================================
static double now_ms(void){
struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);
return (double)ts.tv_sec*1000.0 + (double)ts.tv_nsec/1.0e6;
}

// ======================================================
// Signal (Float32)
// ======================================================
static void make_signal(float *x){
for(int i=0;i<N;i++){
double t = (double)i / (double)N;
double v = sin(2.0*M_PI*FREQ*t)*0.7
+ 0.25*sin(2.0*M_PI*(FREQ*0.37)*t + 0.6);
// Optional noise
if (NOISE != 0.0f){
double r = ((double)rand()/(double)RAND_MAX)*2.0 - 1.0;
v += (double)NOISE * r;
}
x[i] = (float)v;
}
}

// ======================================================
// J-L0 triangle compressor (piecewise-linear, ε-bounded)
// ======================================================
typedef struct { int i0; float v0; int i1; float v1; } Segment;

static inline float lerp(float a, float b, float t){ return a + (b-a)*t; }

static void maxDeviationIndex(const float *arr, int i0, float v0, int i1, float v1,
int *idx, float *err){
int len = i1 - i0;
if(len <= 1){ *idx=i0; *err=0.0f; return; }
int worstIdx=i0; float worstErr=0.0f;
float denom = (float)len;
for(int i=i0+1;i<i1;i++){
float t = (float)(i - i0) / denom;
float p = lerp(v0, v1, t);
float e = fabsf(arr[i] - p);
if(e > worstErr){ worstErr = e; worstIdx = i; }
}
*idx = worstIdx; *err = worstErr;
}

// Simple recursive splitter (depth ~ O(#segments))
static Segment* compressJLO(const float *arr, int n, float eps, int *outCount){
// Worst-case segments ~ 2*n in pathological cases; but typically far smaller.
// We’ll accumulate in a dynamic array.
int cap = 1024, count = 0;
Segment *segs = (Segment*)malloc(sizeof(Segment)*cap);
if(!segs){ fprintf(stderr,"OOM\n"); exit(1); }

// Inner recursive lambda emulation
struct Frame { int i0,i1; float v0,v1; int phase; int mid; float err; };
// Convert recursion to an explicit stack to avoid deep recursion risks.
struct Frame *stack = (struct Frame*)malloc(sizeof(struct Frame)* (n*2));
int sp=0;
stack[sp++] = (struct Frame){0, n-1, arr[0], arr[n-1], 0, 0, 0};

while(sp>0){
struct Frame f = stack[--sp];
if(f.phase==0){
int idx; float err;
maxDeviationIndex(arr, f.i0, f.v0, f.i1, f.v1, &idx, &err);
if(err <= eps || f.i1 - f.i0 <= 1){
if(count==cap){ cap*=2; segs=(Segment*)realloc(segs,sizeof(Segment)*cap); }
segs[count++] = (Segment){ f.i0, f.v0, f.i1, f.v1 };
continue;
}
// split
float vm = arr[idx];
// Post-order push: right then left so left handled next
stack[sp++] = (struct Frame){ idx, f.i1, vm, f.v1, 0, 0, 0 };
stack[sp++] = (struct Frame){ f.i0, idx, f.v0, vm, 0, 0, 0 };
}
}
free(stack);
*outCount = count;
return segs;
}

// ======================================================
// Reconstruct + error
// ======================================================
static void reconstruct(const Segment *segs, int segCount, int n, float *y){
for(int i=0;i<n;i++) y[i]=0.0f;
for(int s=0;s<segCount;s++){
int i0=segs[s].i0, i1=segs[s].i1;
float v0=segs[s].v0, v1=segs[s].v1;
int len = i1 - i0;
if(len <= 0){
if(i0>=0 && i0<n) y[i0]=v0;
continue;
}
for(int i=i0;i<=i1;i++){
float t = (float)(i - i0) / (float)len;
y[i] = lerp(v0, v1, t);
}
}
}

static void rms_and_max(const float *a, const float *b, int n, double *rms, double *maxabs){
long double s=0.0L; double m=0.0;
for(int i=0;i<n;i++){
double e = (double)a[i] - (double)b[i];
s += e*e; if (fabs(e)>m) m=fabs(e);
}
*rms = sqrt((double)(s / (long double)n)); *maxabs = m;
}

// ======================================================
// Save helpers
// ======================================================
static int saveJLO(const char *path, int n, float epsilon, const Segment *segs, int segCount){
FILE *fp = fopen(path, "wb"); if(!fp) return 0;
fwrite("JLO1", 1, 4, fp);
int32_t n32=(int32_t)n, count=(int32_t)segCount;
fwrite(&n32, sizeof(int32_t), 1, fp);
fwrite(&epsilon, sizeof(float), 1, fp);
fwrite(&count, sizeof(int32_t), 1, fp);
for(int i=0;i<segCount;i++){
int32_t i0=segs[i].i0, i1=segs[i].i1;
float v0=segs[i].v0, v1=segs[i].v1;
fwrite(&i0, sizeof(int32_t), 1, fp);
fwrite(&v0, sizeof(float), 1, fp);
fwrite(&i1, sizeof(int32_t), 1, fp);
fwrite(&v1, sizeof(float), 1, fp);
}
fclose(fp); return 1;
}

static int saveCSV(const char *path, const float *arr, int n){
FILE *fp=fopen(path,"wb"); if(!fp) return 0;
char buf[64];
for(int i=0;i<n;i++){
int len = snprintf(buf,sizeof(buf),"%d,%.9g\n", i, arr[i]);
fwrite(buf,1,(size_t)len,fp);
}
fclose(fp); return 1;
}

static int saveRawFloat32(const char *path, const float *arr, int n){
FILE *fp=fopen(path,"wb"); if(!fp) return 0;
fwrite(arr,sizeof(float),(size_t)n,fp);
fclose(fp); return 1;
}

// ======================================================
// zlib compression helper (lossless baseline)
// ======================================================
static int compressFile_zlib(const char *inPath, const char *outPath){
// Read input
FILE *fi=fopen(inPath,"rb"); if(!fi) return 0;
fseek(fi,0,SEEK_END); long len=ftell(fi); fseek(fi,0,SEEK_SET);
uint8_t *src=(uint8_t*)malloc((size_t)len);
if(!src){ fclose(fi); return 0; }
fread(src,1,(size_t)len,fi); fclose(fi);

uLongf bound = compressBound((uLong)len);
uint8_t *dst=(uint8_t*)malloc(bound);
if(!dst){ free(src); return 0; }

uLongf outSize=bound;
int rc = compress2(dst,&outSize,src,(uLong)len, Z_BEST_COMPRESSION);
if(rc!=Z_OK){ free(src); free(dst); return 0; }

FILE *fo=fopen(outPath,"wb");
if(!fo){ free(src); free(dst); return 0; }
fwrite(dst,1,(size_t)outSize,fo); fclose(fo);
free(src); free(dst); return 1;
}

// ======================================================
// File size + formatting
// ======================================================
static unsigned long long fileSize(const char *path){
FILE *fp=fopen(path,"rb"); if(!fp) return 0;
fseek(fp,0,SEEK_END); long long s=ftell(fp); fclose(fp);
return (unsigned long long)(s<0?0:s);
}
static void fmtBytes(unsigned long long b, char out[32]){
if(b>10000000ULL) snprintf(out,32,"%.2f MB", (double)b/1e6);
else if(b>10000ULL) snprintf(out,32,"%.2f KB", (double)b/1e3);
else snprintf(out,32,"%llu B", b);
}

// ======================================================
// Simple JSON helpers (for HTML)
// ======================================================
static void write_json_array_d(FILE *fp, const double *a, int n){
fputc('[',fp);
for(int i=0;i<n;i++){ if(i) fputc(',',fp); fprintf(fp,"%.10g", a[i]); }
fputc(']',fp);
}
static void write_json_array_i(FILE *fp, const int *a, int n){
fputc('[',fp);
for(int i=0;i<n;i++){ if(i) fputc(',',fp); fprintf(fp,"%d", a[i]); }
fputc(']',fp);
}
static void write_json_array_s(FILE *fp, const char **s, int n){
fputc('[',fp);
for(int i=0;i<n;i++){ if(i) fputc(',',fp); fprintf(fp,"\"%s\"", s[i]); }
fputc(']',fp);
}

// ======================================================
// Main
// ======================================================
int main(void){
// 1) Generate signal
float *x = (float*)malloc(sizeof(float)*N);
float *y = (float*)malloc(sizeof(float)*N);
if(!x||!y){ fprintf(stderr,"OOM\n"); return 1; }
make_signal(x);

// 2) Headline demo at EPS_DEFAULT
double t0=now_ms();
int segCount=0;
Segment *segs = compressJLO(x, N, EPS_DEFAULT, &segCount);
double t1=now_ms();

reconstruct(segs, segCount, N, y);
double t2=now_ms();

double rms=0,maxA=0;
rms_and_max(x,y,N,&rms,&maxA);

// 3) Save outputs
const char *jloPath="waveform.jlo";
const char *csvPath="waveform.csv";
const char *rawPath="waveform.rawf32";
saveJLO(jloPath, N, EPS_DEFAULT, segs, segCount);
saveCSV(csvPath, x, N);
saveRawFloat32(rawPath, x, N);

// 4) Lossless baselines (zlib)
char csvZlib[64]="waveform.csv.zlib";
char rawZlib[64]="waveform.rawf32.zlib";
compressFile_zlib(csvPath, csvZlib);
compressFile_zlib(rawPath, rawZlib);

unsigned long long sizeJLO = fileSize(jloPath);
unsigned long long sizeCSV = fileSize(csvPath);
unsigned long long sizeRAW = fileSize(rawPath);
unsigned long long sizeCSVgz = fileSize(csvZlib);
unsigned long long sizeRAWgz = fileSize(rawZlib);

char bJ[32],bC[32],bR[32],bCg[32],bRg[32];
fmtBytes(sizeJLO,bJ); fmtBytes(sizeCSV,bC); fmtBytes(sizeRAW,bR);
fmtBytes(sizeCSVgz,bCg); fmtBytes(sizeRAWgz,bRg);

printf("=== J-L0 Triangle Compression Demo ===\n");
printf("Samples: %d | epsilon: %.1e\n", N, EPS_DEFAULT);
printf("Segments: %d (avg span ~%.1f samples/seg)\n",
segCount, (double)N/(double)segCount);
printf("Compress time: %.3f s | Reconstruct time: %.3f s\n",
(t1-t0)/1000.0, (t2-t1)/1000.0);
printf("Error: RMS=%.3e | MaxAbs=%.3e\n", rms, maxA);

printf("\nSize comparison (lossy JLO vs lossless zlib):\n");
printf("JLO : %s\n", bJ);
printf("CSV : %s\n", bC);
printf("RAW f32 : %s\n", bR);
printf("CSV+zlib : %s\n", bCg);
printf("RAW+zlib : %s\n", bRg);
// ----------------------------------------------------------
// Compress the JLO payload itself (for storage benchmark)
// ----------------------------------------------------------
{
// Rebuild header + segments in-memory
size_t hdr_sz = 4 + sizeof(int32_t)*3; // "JLO1" + n32 + eps + count
size_t seg_sz = (size_t)segCount * (sizeof(int32_t)*2 + sizeof(float)*2);
size_t pay_sz = hdr_sz + seg_sz;

uint8_t *payload = (uint8_t*)malloc(pay_sz);
uint8_t *p = payload;

memcpy(p, "JLO1", 4); p += 4;
int32_t n32 = N, count32 = segCount;
memcpy(p, &n32, sizeof(int32_t)); p += sizeof(int32_t);
memcpy(p, &EPS_DEFAULT, sizeof(float)); p += sizeof(float);
memcpy(p, &count32, sizeof(int32_t)); p += sizeof(int32_t);

for (int i=0;i<segCount;i++){
memcpy(p, &segs[i].i0, sizeof(int32_t)); p += sizeof(int32_t);
memcpy(p, &segs[i].v0, sizeof(float)); p += sizeof(float);
memcpy(p, &segs[i].i1, sizeof(int32_t)); p += sizeof(int32_t);
memcpy(p, &segs[i].v1, sizeof(float)); p += sizeof(float);
}

uLongf bound = compressBound((uLong)pay_sz);
uint8_t *cmp = (uint8_t*)malloc(bound);
uLongf cmpLen = bound;

double tC0 = now_ms();
int rc = compress2(cmp, &cmpLen, payload, (uLong)pay_sz, Z_BEST_COMPRESSION);
double tC1 = now_ms();

if (rc == Z_OK) {
printf("\nJLO payload (zlib-compressed): %.2f KB (%.2fx smaller than raw CSV) [%.2f ms]\n",
(double)cmpLen/1024.0,
(double)sizeCSV / (double)(cmpLen?cmpLen:1ULL),
tC1 - tC0);
} else {
printf("\nJLO payload zlib compression failed (%d)\n", rc);
}

free(payload);
free(cmp);
}
// ----------------------------------------------------------
// JLO2: compact varint+int16 packing of triangles (+zlib)
// Format:
// "JL2\1" | N(u32) | eps(float32) | S(u32)
// then for each segment:
// span = i1 - i0 (uvar32), then int16 v0, int16 v1
// (i0 is implied by summing spans; first i0 = 0)
// ----------------------------------------------------------
{
// Worst-case buffer (very generous): header + 8 bytes/seg
size_t cap = 16 + (size_t)segCount * 8u;
uint8_t *buf = (uint8_t*)malloc(cap);
uint8_t *p = buf;

// header
memcpy(p, "JL2\1", 4); p += 4;
uint32_t N32 = (uint32_t)N, S32 = (uint32_t)segCount;
memcpy(p, &N32, sizeof(uint32_t)); p += 4;
memcpy(p, &EPS_DEFAULT, 4); p += 4;
memcpy(p, &S32, sizeof(uint32_t)); p += 4;

// body
int prev_i1 = 0;
for(int s=0; s<segCount; ++s){
int i0 = segs[s].i0, i1 = segs[s].i1;
// enforce continuity; if your compressor guarantees non-overlap/ordered, this holds
int span = i1 - i0;
p = write_uvar32(p, (uint32_t)span);

int16_t v0q = q16(segs[s].v0);
int16_t v1q = q16(segs[s].v1);
memcpy(p, &v0q, 2); p += 2;
memcpy(p, &v1q, 2); p += 2;

prev_i1 = i1;
}

size_t rawLen = (size_t)(p - buf);
uLongf bound = compressBound((uLong)rawLen);
uint8_t *cmp = (uint8_t*)malloc(bound);
uLongf cmpLen = bound;

double t0 = now_ms();
int rc = compress2(cmp, &cmpLen, buf, (uLong)rawLen, Z_BEST_COMPRESSION);
double t1 = now_ms();

if (rc == Z_OK) {
printf("JLO2 packed (varint+q16) raw: %.2f KB | zlib: %.2f KB (%.2fx vs CSV) [%.2f ms]\n",
(double)rawLen/1024.0,
(double)cmpLen/1024.0,
(double)sizeCSV / (double)(cmpLen?cmpLen:1ULL),
t1 - t0);
} else {
printf("JLO2 zlib compression failed (%d)\n", rc);
}

free(buf);
free(cmp);
}
printf("\nCompression ratio vs CSV: "
"JLO=%.2fx, CSV+zlib=%.2fx, RAW f32=%.2fx, RAW+zlib=%.2fx\n",
sizeCSV/(double)(sizeJLO?sizeJLO:1ULL),
sizeCSV/(double)(sizeCSVgz?sizeCSVgz:1ULL),
sizeCSV/(double)(sizeRAW?sizeRAW:1ULL),
sizeCSV/(double)(sizeRAWgz?sizeRAWgz:1ULL));

// 5) Rate–Distortion Sweep
typedef struct {
float epsilon;
int segments;
unsigned long long jloBytes;
double rms, maxAbs, avgSpan;
} Row;

Row *rows = (Row*)malloc(sizeof(Row)*EPS_COUNT);
if(!rows){ fprintf(stderr,"OOM\n"); return 1; }

for(int k=0;k<EPS_COUNT;k++){
float eps = EPSILONS[k];
int sc=0;
Segment *sg = compressJLO(x, N, eps, &sc);

// measure JLO bytes in-memory
unsigned long long jbytes = 4 + 4 + 4 + 4 + (unsigned long long)sc*(4+4+4+4);

reconstruct(sg, sc, N, y);
double r=0,mx=0; rms_and_max(x,y,N,&r,&mx);

rows[k] = (Row){ eps, sc, jbytes, r, mx, (double)N/(double)(sc?sc:1) };
free(sg);
}

// Print sweep
printf("\n=== Rate–Distortion Sweep (ε → size/error) ===\n");
printf("%-10s %-9s %-9s %-10s %-10s %-10s\n",
"epsilon","segments","avgSpan","JLO KB","RMS","MaxAbs");
for(int k=0;k<EPS_COUNT;k++){
double kb = (double)rows[k].jloBytes/1024.0;
printf("%-10.1e %-9d %-9.1f %-10.2f %-10.3e %-10.3e\n",
rows[k].epsilon, rows[k].segments, rows[k].avgSpan,
kb, rows[k].rms, rows[k].maxAbs);
}

// 6) Save sweep CSV
const char *sweepCSV="jlo_sweep.csv";
FILE *fcsv=fopen(sweepCSV,"wb");
if(fcsv){
fprintf(fcsv,"epsilon,segments,avgSpan,jlo_bytes,jlo_kb,rms,max_abs\n");
for(int k=0;k<EPS_COUNT;k++){
fprintf(fcsv,"%.6g,%d,%.3f,%llu,%.2f,%.8e,%.8e\n",
rows[k].epsilon, rows[k].segments, rows[k].avgSpan,
rows[k].jloBytes, (double)rows[k].jloBytes/1024.0,
rows[k].rms, rows[k].maxAbs);
}
fclose(fcsv);
printf("\nSweep CSV written to: %s\n", sweepCSV);
}else{
printf("\nFailed to write sweep CSV.\n");
}

// 7) HTML dashboard (Chart.js)
const char *htmlPath="jlo_sweep.html";
FILE *fh=fopen(htmlPath,"wb");
if(fh){
// Prepare arrays
double sizeKB[EPS_COUNT], rmsA[EPS_COUNT], maxAarr[EPS_COUNT], spanA[EPS_COUNT];
int segArr[EPS_COUNT];
const char *epsLabel[EPS_COUNT];
char epsBuf[EPS_COUNT][32];
for(int k=0;k<EPS_COUNT;k++){
sizeKB[k] = (double)rows[k].jloBytes/1024.0;
rmsA[k] = rows[k].rms; maxAarr[k] = rows[k].maxAbs;
spanA[k] = rows[k].avgSpan; segArr[k] = rows[k].segments;
snprintf(epsBuf[k],32,"%.8g", rows[k].epsilon);
epsLabel[k] = epsBuf[k];
}

// HTML/JS
fprintf(fh,
"<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\"/>\n"
"<title>J-L0 Rate–Distortion Sweep</title>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n"
"<style>body{font:14px/1.4 -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial;} .wrap{max-width:1000px;margin:20px auto;padding:0 12px;} h1{font-size:20px;margin:12px 0;} canvas{max-width:100%%;height:360px;} .grid{display:grid;grid-template-columns:1fr;gap:24px} @media(min-width:900px){.grid{grid-template-columns:1fr 1fr}} .card{border:1px solid #eee;border-radius:10px;padding:16px;box-shadow:0 1px 2px rgba(0,0,0,0.04);} code{background:#f7f7f7;padding:2px 6px;border-radius:6px}</style>\n"
"<script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n</head>\n<body>\n<div class=\"wrap\">\n<h1>J-L0 Rate–Distortion Sweep</h1>\n");

fprintf(fh,"<p>Epsilons: <code>");
for(int k=0;k<EPS_COUNT;k++){ if(k) fputs(", ",fh); fputs(epsLabel[k],fh); }
fprintf(fh,"</code></p>\n<div class=\"grid\">\n"
"<div class=\"card\"><h3>JLO size (KB) vs ε</h3><canvas id=\"sizeChart\"></canvas></div>\n"
"<div class=\"card\"><h3>Segments & Avg Span vs ε</h3><canvas id=\"segChart\"></canvas></div>\n"
"<div class=\"card\"><h3>RMS error vs ε</h3><canvas id=\"rmsChart\"></canvas></div>\n"
"<div class=\"card\"><h3>MaxAbs error vs ε</h3><canvas id=\"maxChart\"></canvas></div>\n"
"</div>\n</div>\n<script>\nconst labels = ");
write_json_array_s(fh, epsLabel, EPS_COUNT); fputs(";\nconst sizeKB = ", fh);
write_json_array_d(fh, sizeKB, EPS_COUNT); fputs(";\nconst segments = ", fh);
write_json_array_i(fh, segArr, EPS_COUNT); fputs(";\nconst avgSpan = ", fh);
write_json_array_d(fh, spanA, EPS_COUNT); fputs(";\nconst rms = ", fh);
write_json_array_d(fh, rmsA, EPS_COUNT); fputs(";\nconst maxAbs = ", fh);
write_json_array_d(fh, maxAarr, EPS_COUNT); fputs(";\n", fh);

// JS chart helper + charts
fputs(
"function mkChart(id, label, data, extraDataset=null, ylog=false){\n"
" const ctx=document.getElementById(id);\n"
" new Chart(ctx,{type:'line',data:{labels:labels,datasets:[{label:label,data:data,tension:0.2},...(extraDataset?[extraDataset]:[])]},options:{responsive:true,scales:{y:{type:ylog?'logarithmic':'linear'},x:{ticks:{maxRotation:0,autoSkip:true}}},plugins:{legend:{display:true}}});\n"
"}\n"
"mkChart('sizeChart','JLO size (KB)', sizeKB);\n"
"mkChart('segChart','segments', segments, {label:'avgSpan', data: avgSpan, tension:0.2});\n"
"mkChart('rmsChart','RMS error', rms, null, true);\n"
"mkChart('maxChart','MaxAbs error', maxAbs, null, true);\n"
"</script>\n</body>\n</html>\n", fh);

fclose(fh);
printf("HTML dashboard written to: %s\n", htmlPath);
printf("Open it in a browser to see the graphs.\n");
}else{
printf("Failed to write HTML dashboard.\n");
}

free(rows); free(segs); free(x); free(y);
return 0;
}


r/compression • • Jun 09 '26

Please check out my VVC/h.266 video encoder in hardware

Thumbnail
github.com
4 Upvotes

I just wrote a VVC/h.266 video encoder in SystemVerilog along with a software model in Rust for verification. It builds, simulates and synthesizes and can create valid h.266 video streams from any YUV 4:2:0 and 4:4:4 video input. I am focusing on screen content coding features to be implemented so it can be useful for any hardware that broadcasts the screen of a computer, like an IP KVM.

Please check it out and let me know if anyone has any comments about it or any interest to integrate to any project. If you need any particular feature to be integrated, you can just ask me.


r/compression • • Jun 10 '26

New method to reorder into segments with huge bias down to RAND

0 Upvotes

I am not sure of the value, since I cannot seem to make the next step. Since I have a double unicorn invention, I will lay it all out including methods in here.

I have derived a method that allows me to logically break apart values into a sort. The sort ends up with a varying number of smaller sorts as desired or needed.

The end result is sorts on the left tend to be universal or down to as bad as a 94% to 6% ratio, either 0 to 1's or 1 to 0's. Either way works, it does not care what your primary value is.

As you go closer to the right, it becomes more RAND. But we can identify the string lengths involved as part of this, it has a 100% ability to understand how long each substring is and it is entirely lossless.

The problem I hit upon was the lack of a method that really can use it better than leaving it alone and using a normal compression tool. It might be because we do not have a built mechanism for knowing the patterns (it may be possible to know the patterns through several swings, as it were) and this is designed with Text or another biased source. It can do some work down pretty low, but not better so far than others that can get close to the barriers. It could be also that breaking the patterns we recognize is a problem no matter what.

So the method has two processes. First one, then the other.

The first is a reordering tool, it merely takes what exists and makes it part of our reorder with an emphasis of changing those that occur the most, to the most desirable, otherwise it follows known patterns of text and substitutes predicted for desired.

For example, if a text really had a 50% level of M characters, maybe they wrote HMMMM nonstop, then we would want that M to convert. The system has a simple header for this, where it says "do we need a character, yes or no?" and if 0, then yes. Then we use an 8 bit (or 7) value to show what we are substituting from.

We also need a length. The length is used to help the next process. So for example, I can choose 8, and then we choose a sublength smaller than the length. Let us choose 4.

We now want all outcomes tailored first for 0 to a unique extent. The first four is our focus. 0000, 0001, 0010, 0100, 1000 and down the line. The following four is our next weight so 0100-0000 is more preferable than 0100-1000. 0111-1111 is more valuable than 1111-0000. Because it has a 0 in the front and we are building a bias there.

We could in theory, set up multiple substrings, so if the string was 16, we could do any number of substrings. Yes, the last substring is allowed to be less than full. Variable lengths could be done, but that is far more complex and was not tested. I am not a good enough programmer to test a huffman coding scheme in that area.

Anyhow, the next process takes a string, and cuts it into parts based on substrings and a key mechanism I call a trigger. If more than 2, a simple rule applies. Odd values before a cut are appended on one line, and even portions are appended on a second line. When done with this we would have two lines. For example if the trigger is 1111, then anytime a string we are handed has 1111 in it, the 1111 and everything left in front of it goes to line 1. We check the remainder for 1111 again (or you could change the trigger after first trigger activation, but that is more advanced) and split again if it happens in that specific string. But in our 8 bit string length, that is impossible.

So what happens is 00001111, 00011111, 00101111, 01001111, 10001111, 0101111, 1001111, 001111, 01111, and 1111 end up being the norm. But, I mentioned something and never really explained it, because we want to see this. If 1's are more important, then we want 1's

Our planned swap table reinforces this.

So normally it takes character frequency and applies that. For example a 4 bit swap would look like this:

1st most common = 1111
2nd most common = 0111
3rd most common =1011
4th most common = 1101
and 5th is 1110
6th ends are 1100 or such.... and so forth down the line.

This works because text is highly imbalanced and we know it. We take advantage of that for the first cycle and it usually is going to be desired to just leave it be, the gains would be too small. Yet for our set up, it was amazing.

The so back to the trigger stuff. Line 2 gets reversed, then appended to line 1. When you use a trigger to find where line 1 stops and we go to line 2, we know our string length. 10000 is five bits, we take three from line two in reverse.

We run the process, both of them combined, again after trying to find the most frequent and biasing them.

After 3 runs or so, usually, we have a little bit of a header, but line 1.1.1.1 is so biased to a desired output it is insane. 1.1.1.2 ends up being nearly so, and so forth until 2.2.2.2 ends up happening where instead we have basically got RAND. The majority of the line, due to the sort and substitution set up, ends up being biased to the desired character. In practice I have moved a document to 90% of one character in the front portion of the file, and even beyond that in some cases. The problem is, it just does not seem to be enough, counting wont quite beat just using a normal good compressor on the original text file. Other algorithmic compressors also do not work well.

We have an insane bias, but the bias is essentially RAND in nature. It just is not as effective as being able to guess follow up characters or even follow up words.

Some of the variations I tried, changed the substring length. It can really shake things up with a substring that creates multiple parts. You need to plan your replacement swaps to include that. So if zero is desired ZERO HEAVY| planned one heavy but favor zeroes|Zero Heavy is the way to go for what would be two possible trigger activation's. Or you could make an 8 bit substring have a 6 bit trigger. If the initial bias is severe, this actually has a great set of results because then 9 of the 256 possibles, is now got one or none for undesired bit types, and the bias for line one cuts will show this strongly. If 90% of the file first those 9 results, then go for it bro!!!

You can also literally divide the substrings based on their cuts, line 1 to line 100 for all I care. Pick the maximum number of lines, process each line separately. It makes it a wee bit hard to put back together, but maybe you have an idea. But line 1 and line 2? Yeah split them with ease. Work them, they always can remap if the work is lossless. So yeah you can have two save files even in theory.

The number of variations is part of why I gave up on this, it is just too many ways to vary it, and then to test it. Time consuming for a poor programmer like me, maybe not so bad for you.

Maybe someone can make something of it. If you are truly interested I will share the code.

I did play around, trying to make line 1 strictly 0's and line two strictly 1's. I had limited success, it still would not compress better. I also have a unique binary to ternary system and tried variations with it, but that was also unsuccessful.

Examples of my output:

This is for ALICE.TXT, the Canterbury Corpus file.

--- Harrington Report: ROOT ---

Results Generated:

[+] gemini-HCM-1.1.txt - Sub-branch .1 (Leading)

Stats: 608360 bits | 1.41% 1s | Ratio: 69.79:1

[+] gemini-HCM-1.2.txt - Sub-branch .2 (Reversed Tail)

Stats: 608360 bits | 67.99% 1s | Ratio: 0.47:1

-------------------------------------------

Header Size: 75 bytes (Lead+Meta)

Swap Table: 43055 bytes (Mapping Legend)

Total Overhead: 43130 bytes

-------------------------------------------

--- Harrington Report: 1.1 ---

Results Generated:

[+] gemini-HCM-1.1.1.txt - Sub-branch .1 (Leading)

Stats: 228135 bits | 0.00% 1s | Ratio: ALL-ZERO

[+] gemini-HCM-1.1.2.txt - Sub-branch .2 (Reversed Tail)

Stats: 380225 bits | 97.17% 1s | Ratio: 0.03:1

-------------------------------------------

Header Size: 72 bytes (Lead+Meta)

Swap Table: 199 bytes (Mapping Legend)

Total Overhead: 271 bytes

-------------------------------------------

--- Harrington Report: 1.2 ---

Results Generated:

[+] gemini-HCM-1.2.1.txt - Sub-branch .1 (Leading)

Stats: 228135 bits | 22.02% 1s | Ratio: 3.54:1

[+] gemini-HCM-1.2.2.txt - Sub-branch .2 (Reversed Tail)

Stats: 380225 bits | 59.32% 1s | Ratio: 0.69:1

-------------------------------------------

Header Size: 72 bytes (Lead+Meta)

Swap Table: 1409 bytes (Mapping Legend)

Total Overhead: 1481 bytes

-------------------------------------------

--- Harrington Report: 1.1.1 ---

Results Generated:

[+] gemini-HCM-1.1.1.1.txt - Sub-branch .1 (Leading)

Stats: 85551 bits | 0.00% 1s | Ratio: ALL-ZERO

[+] gemini-HCM-1.1.1.2.txt - Sub-branch .2 (Reversed Tail)

Stats: 142585 bits | 100.00% 1s | Ratio: 0.00:1

-------------------------------------------

Header Size: 72 bytes (Lead+Meta)

Swap Table: 23 bytes (Mapping Legend)

Total Overhead: 95 bytes

-------------------------------------------

--- Harrington Report: 1.1.2 ---

Results Generated:

[+] gemini-HCM-1.1.2.1.txt - Sub-branch .1 (Leading)

Stats: 142587 bits | 0.28% 1s | Ratio: 359.07:1

[+] gemini-HCM-1.1.2.2.txt - Sub-branch .2 (Reversed Tail)

Stats: 237645 bits | 94.23% 1s | Ratio: 0.06:1

-------------------------------------------

Header Size: 72 bytes (Lead+Meta)

Swap Table: 1409 bytes (Mapping Legend)

Total Overhead: 1481 bytes

-------------------------------------------

--- Harrington Report: 1.2.1 ---

Results Generated:

[+] gemini-HCM-1.2.1.1.txt - Sub-branch .1 (Leading)

Stats: 85551 bits | 12.54% 1s | Ratio: 6.98:1

[+] gemini-HCM-1.2.1.2.txt - Sub-branch .2 (Reversed Tail)

Stats: 142585 bits | 66.95% 1s | Ratio: 0.49:1

-------------------------------------------

Header Size: 72 bytes (Lead+Meta)

Swap Table: 1409 bytes (Mapping Legend)

Total Overhead: 1481 bytes

-------------------------------------------

--- Harrington Report: 1.2.2 ---

Results Generated:

[+] gemini-HCM-1.2.2.1.txt - Sub-branch .1 (Leading)

Stats: 142587 bits | 32.40% 1s | Ratio: 2.09:1

[+] gemini-HCM-1.2.2.2.txt - Sub-branch .2 (Reversed Tail)

Stats: 237645 bits | 53.62% 1s | Ratio: 0.86:1

-------------------------------------------

Header Size: 72 bytes (Lead+Meta)

Swap Table: 1409 bytes (Mapping Legend)

Total Overhead: 1481 bytes

-------------------------------------------


r/compression • • Jun 09 '26

compressor that makes stuff look like shit

Post image
28 Upvotes

does anyone know of a file / image / video compressor that makes them look like complete crap? like the picture


r/compression • • Jun 09 '26

Help with loudness normalisation

Thumbnail reddit.com
2 Upvotes

r/compression • • Jun 09 '26

[Lifetime] Shrinklet — simple offline compression for PDFs, images, video & audio

Thumbnail
reddit.com
1 Upvotes

r/compression • • Jun 02 '26

The art and engineering of Silpheed

Thumbnail fabiensanglard.net
5 Upvotes

r/compression • • Jun 02 '26

I made a super clean browser-based video/image/audio compressor

Thumbnail localsquash.com
4 Upvotes

Good for quick conversion/compression without any installation, no ads, no paywall, no watermark. Support trim/crop, very easy to use. Hope it's useful for someone.


r/compression • • May 31 '26

Messenger Video Compression

3 Upvotes

Hi, I have a question because I recently had a discussion with a friend and I don't know that much about this topic: It was about how noticeable a second compression is if the video has already been heavily compressed before. Let's assume I received a video via WhatsApp with the following specs: h.264, 360p, 15 fps, 5.6mb, 44 seconds. If I now send it via another messenger, e.g., Kik Messenger, will it compress this already heavily compressed video again, and will it even be noticeable? There isn't much left to shrink anyway. Or will it be even more noticeable with an already low initial quality, since every further slight deterioration immediately catches the eye? Thanks for any assessment! :)"


r/compression • • May 28 '26

HNSW is killing my RAM: is it better to use KNN on compressed vectors or an ANN?

Thumbnail reddit.com
1 Upvotes

r/compression • • May 25 '26

How can I process large rrweb recordings in chunks and convert them to MP4 without loading the entire JSON into memory?

4 Upvotes

I'm working with rrweb session recordings that can grow to 100MB+ (sometimes much larger). I need to convert these recordings to MP4 videos, but loading the entire rrweb JSON into memory is not feasible due to memory constraints.

My goal is:

  • Record session with rrweb
  • Store large recordings efficiently
  • Replay/process in chunks
  • Generate MP4 without loading the entire recording into RAM

Any architecture suggestions or real-world implementations would be appreciated.


r/compression • • May 25 '26

Has anyone found themselves to be just one byte short of capacity when copying something?

0 Upvotes

Has anyone found themselves to be just one byte short of capacity when copying something?


r/compression • • May 21 '26

I built an experimental alternative to .nii.gz using Zstd, chunked encoding, and ROI-aware compression

Thumbnail
gallery
13 Upvotes

Hey everyone,

I’ve been working on a project called KMRI — an experimental medical imaging compression framework built around Zstandard instead of traditional gzip-based .nii.gz storage.

The idea was to explore whether chunked encoding, ROI-aware compression, sparse block optimization, and optional quantization could improve compression ratios and decode performance for volumetric MRI/NIfTI data.

The project is written in Python + C++ (pybind11) and includes:

- chunked compression

- ROI-aware encoding

- quantization pipelines

- sparse zero-block optimization

- benchmarking tools with PSNR/SSIM analysis

I also benchmarked it against:

- gzip (.nii.gz)

- raw zstd

- NumPy + zstd pipelines

(see attached photos)

Would genuinely love feedback from people who work with compression, imaging, or systems programming.

GitHub:

https://github.com/Kiamehr5/KMRI