CSC319 Multimedia Computing

Multimedia ComputingUnit 68 min read

Multimedia Data Compression & Coding: Techniques, Trade-offs, and Real-World Impact

Unit 6 of Multimedia Computing: Explores how to reduce file sizes without losing critical data (lossless) or accepting minor quality trade-offs (lossy), with deep dives into entropy coding, DCT, Huffman, JPEG, and MP3—plus how these power apps like Daraz, NTC, and WhatsApp.

Why Compress Multimedia?

Multimedia files (images, audio, video) are data-rich but inefficient. A single 1080p video can exceed 1GB per minute if uncompressed. Compression shrinks files to:

  • Save storage (e.g., NTC’s 5G network needs to transmit compressed video calls).
  • Reduce bandwidth (e.g., WhatsApp’s video calls use H.264 compression to avoid buffering).
  • Speed up transfers (e.g., Daraz’s product images are JPEG-compressed to load faster).

Compression works by exploiting redundancy (repeated patterns) and perceptual limits (what humans can’t notice).


1. Lossless vs. Lossy Compression: The Core Trade-off

graph TD
    A["Multimedia Data"] --> B["Lossless Compression"]
    A --> C["Lossy Compression"]
    B --> D["No quality loss\n(Archives, docs)"]
    C --> E["Minimal quality loss\n(Videos, music)"]
    D --> F["Examples: ZIP, PNG-8\n(No data loss)"]
    E --> G["Examples: JPEG, MP3\n(Small file, slight artifacts)"]
Feature Lossless Lossy
Data Recovery Original file can be perfectly reconstructed Approximation only; original lost
Use Case Text, code, medical scans, PNG-8 Photos, music, video (JPEG, MP3)
Compression Ratio Lower (30–70%) Higher (80–95%)
Speed Faster (no complex math) Slower (DCT, quantization)
Example Apps eSewa’s transaction logs (PNG-8) Ncell’s 4K video calls (H.265)

Worked Example: PNG vs. JPEG

  • A PNG of a logo (text + flat colors) compresses to 1.2MB (lossless).
  • The same logo as a JPEG compresses to 80KB (lossy), but you’d notice color banding in high-zoom views.

2. Entropy Coding: The Mathematical Foundation

Entropy coding exploits probability—frequent symbols (e.g., spaces in text) get shorter codes.

Huffman Coding (45%)Arithmetic Coding (35%)Run-Length Encoding (20%)
Distribution of entropy coding techniques used in modern multimedia compression.

Key Methods

  1. Huffman Coding
    • Assigns shorter bits to more frequent symbols.
    • Example: In English text, ‘e’ (12%) gets 0, ‘z’ (0.1%) gets 111111.
graph TD
    A["Symbol"] --> B["Frequency Count"]
    B --> C["Assign Variable-Length Codes"]
    C --> D["Huffman Tree Example"]
    D --> E["Example: 'e' → 0, 'z' → 111111"]
    E --> F["Prefix-Free Property"]
  1. Arithmetic Coding
    • Encodes entire sequences as a single number (e.g., 0.101101 for "hello").
    • Better for low-frequency symbols (e.g., rare words in a book).

Real-World Use:

  • WhatsApp’s text messages use Huffman coding to compress repeated words like “ok” or “yes.”
  • ZIP files combine Huffman + LZ77 (see below) for lossless archives.

3. Predictive Coding: Exploiting Spatial/Temporal Redundancy

Predictive coding estimates repeated patterns (e.g., smooth gradients in images) and stores only the difference (error).

A. Run-Length Encoding (RLE)

  • Stores sequences of identical values as (value, count).
  • Example: A black-and-white bar chart’s long white stripe might encode as (255, 1000).

B. Lempel-Ziv-Welch (LZW)

  • Used in GIF/PNG and TIFF.
  • Replaces repeated substrings with a single code (e.g., “the” → 12345).
  • Limit: Patent expired in 2003, but still used in Nepal’s eSewa transaction IDs (compressed for storage).

4. Transform Coding: The Secret to JPEG/MP3

Transform coding converts data into a domain where redundancy is easier to remove.

Discrete Cosine Transform (DCT)

  • Breaks an image into 8×8 blocks and transforms them into frequency components (low/high).
  • Key Insight: Humans can’t see high-frequency noise (e.g., jagged edges).
  • Process:
    1. Split image into 8×8 blocks.
    2. Apply DCT → frequency spectrum.
    3. Quantize (round) high frequencies → lossy compression.
    4. Encode remaining coefficients with Huffman.
graph TD
    A["Original Image"] --> B["8x8 Pixel Block"]
    B --> C["DCT Transform → Frequency Spectrum"]
    C --> D["Quantization (Discard High Frequencies)"]
    D --> E["Huffman Encoding → JPEG File"]
    E --> F["Result: Smaller File, Slight Artifacts"]

Worked Example: JPEG Compression Trace

  1. Start with a 512×512 RGB image (15MB uncompressed).
  2. Split into 8464 blocks (512/8 × 512/8).
  3. DCT reveals 90% of data is low-frequency (smooth colors).
  4. Quantize high frequencies → file shrinks to 2MB (JPEG).
  5. Huffman encodes → final size: 1.5MB.

Real-World Impact:

  • Daraz’s product images use JPEG to load in <2s on slow 3G.
  • NEPSE stock charts use DCT-compressed PNGs to reduce server load.

5. Hybrid Coding: Combining Techniques

Most real-world compression (e.g., JPEG, MP3, H.264) uses multiple methods:

  1. DCT (for frequency analysis).
  2. Quantization (lossy reduction).
  3. Entropy coding (Huffman/arithmetic).

Example: MP3 (Audio Compression)

  • Steps:
    1. Sampling: Convert analog audio to 44.1kHz PCM (16-bit samples).
    2. DCT: Split into frequency bands.
    3. Masking: Remove inaudible frequencies (e.g., >16kHz for humans).
    4. Bitrate reduction: Store only critical bands (e.g., 128kbps MP3 vs. 1.4MB WAV).
graph TD
    A["Original Audio"] --> B["Sampling: 44.1kHz PCM"]
    B --> C["FFT/DCT → Frequency Bands"]
    C --> D["Psychoacoustic Masking"]
    D --> E["Quantize & Encode → MP3"]
    E --> F["128kbps vs. 1.4MB WAV"]

Why MP3?

  • A 3-minute song goes from 100MB (WAV) → 3MB (MP3).
  • Ncell’s music app uses MP3 to save storage for offline playlists.

6. Video Compression: MPEG/H.264

Video compression reuses frames to avoid storing duplicates.

Key Techniques

  1. Intraframe (I-frames): Full JPEG-like compression (e.g., keyframes).
  2. Predictive (P-frames): Store differences from previous frame.
  3. Bidirectional (B-frames): Interpolate between two I/P frames.
graph TD
    A["I-Frame"] --> B["Full JPEG Compression"]
    B --> C["P-Frame"]
    C --> D["Motion Vectors + Differences"]
    D --> E["B-Frame"]
    E --> F["Interpolation from I/P Frames"]
    F --> G["Efficient for Video"]

Real-World Use:

  • Pathao’s ride-sharing app uses H.264 to stream driver location updates smoothly.
  • NTC’s live TV compresses to 5Mbps (vs. 200Mbps uncompressed).

7. Challenges in Multimedia Compression

Challenge Impact Solution
Perceptual Quality Artifacts (blockiness, noise) Adaptive DCT, super-resolution
Real-Time Processing Delay in video calls Hardware acceleration (GPU)
Cross-Platform Support JPEG vs. PNG vs. WebP Standardize (e.g., AVIF for next-gen)
Security Tampered files (e.g., fake images) Watermarking, checksums

Example: JPEG Artifacts

  • Problem: High compression (e.g., 10%) creates blockiness.
  • Fix: JPEG 2000 uses wavelet transforms for smoother edges.

In the Real World

  1. Khalti’s Payment Gateway

    • Idea: Lossless compression for transaction logs (PNG-8 for icons, ZIP for metadata).
    • Why? Ensures audit trails are 100% accurate (no data loss).
  2. Google Photos

    • Idea: Hybrid DCT + neural networks (Google’s "Smart Compression").
    • How? Uses AI to discard unnoticeable details (e.g., tiny text in photos).
    • Result: 15:1 compression with near-lossless quality.
  3. Ncell’s 4K Video Calls

    • Idea: H.265 (HEVC) compression (50% smaller than H.264).
    • Why? 4K video would need 10Gbps without compression—now it’s 2–3Mbps.

Exam Tip

Focus on these 3 areas for full marks:

  1. Compare Lossless vs. Lossy (table + real examples like PNG vs. JPEG).
  2. Trace JPEG/H.264 (show DCT → quantization → Huffman steps).
  3. Hybrid Coding (explain how MP3/JPEG combine DCT + entropy coding).

Common Pitfalls:

  • ❌ Forgetting why high frequencies are discarded (perceptual limits).
  • ❌ Mixing up RLE (for runs) and LZW (for substrings).
  • ❌ Not linking to real apps (e.g., "Ncell uses H.265 for 4K calls").

Sample Answer Structure:

  1. Define (e.g., "Entropy coding reduces file size by assigning shorter codes to frequent symbols").
  2. Explain with a diagram (e.g., Huffman tree for "hello").
  3. Give a real example (e.g., "WhatsApp uses Huffman for text compression").
  4. Compare (e.g., "Lossless: ZIP; Lossy: JPEG").

Final Visual Recap

Based on the TU BSc CSIT syllabus for Multimedia Computing (CSC319), unit 6.

Discussion

Loading…