FastLED 3.9.15
Loading...
Searching...
No Matches
Codec Directory Reference
+ Directory dependency graph for Codec:

Files

 Codec.ino
 
 codec_processor.cpp
 
 codec_processor.h
 
 inlined_data.cpp
 
 inlined_data.h
 

Detailed Description

This directory contains examples demonstrating the FastLED codec module functionality for JPEG and MPEG1 decoding.

Overview

The FastLED codec module provides video and image decoding capabilities optimized for LED display applications through individual codec headers (fl/codec/jpeg.h and fl/codec/mpeg1.h). It supports:

Platform Support

Platform JPEG Support MPEG1 Support Hardware Acceleration
ESP32 ✓ (ROM decoder) ✓ (Software) ROM TJpgDec
ESP32-S3 ✓ (ROM + PIE) ✓ (Software) ROM TJpgDec + PIE
ESP32-C3/C6 ✓ (ROM decoder) ✓ (Software) ROM TJpgDec
ESP32-P4 ✓ (Hardware) ✓ (Software) Hardware JPEG codec
Teensy 4.x ✓ (Software) ✓ (Software) DSP instructions
STM32H7 ✓ (Hardware) ✓ (Software) Hardware JPEG + DMA2D
STM32F7 ✓ (Hardware) ✓ (Software) Hardware JPEG
Other None

Examples

1. CodecJpeg.ino

JPEG image decoding and display

Hardware Requirements:

Key Features:

2. CodecMpeg1.ino

MPEG1 video playback on LED matrix

Hardware Requirements:

Key Features:

Basic Usage Pattern

JPEG Decoding

#include "fl/codec/jpeg.h"
#include "fl/bytestreammemory.h"
// Configure decoder
fl::JpegDecoderConfig config;
config.format = fl::PixelFormat::RGB888;
config.quality = fl::JpegDecoderConfig::Medium;
// Create decoder
auto decoder = fl::Jpeg::createDecoder(config);
// Create stream from data
auto stream = fl::make_shared<fl::ByteStreamMemory>(jpegData, dataSize);
// Decode
if (decoder->begin(stream)) {
if (decoder->decode() == fl::DecodeResult::Success) {
fl::DecodedVideoFrame frame = decoder->getCurrentFrame();
// Use frame data...
}
decoder->end();
}
static JpegDecoderPtr createDecoder(const JpegConfig &config)
Definition jpeg.cpp.hpp:372
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414

MPEG1 Video Playback

#include "fl/codec/mpeg1.h"
// Configure for real-time streaming (immediate mode)
config.targetFps = 25;
config.immediateMode = true; // Default: bypasses frame buffering for minimal latency
// For buffered mode (when you need frame buffering):
// config.immediateMode = false;
// config.bufferFrames = 2;
// Create decoder
auto decoder = fl::mpeg1::createDecoder(config);
// Playback loop
while (decoder->hasMoreFrames()) {
if (decoder->decode() == fl::DecodeResult::Success) {
fl::DecodedVideoFrame frame = decoder->getCurrentFrame();
displayFrame(frame);
}
}
third_party::Mpeg1Config Mpeg1Config
Definition mpeg1.h:29

Performance Modes

Immediate Mode (Default - Recommended for Real-Time)

Buffered Mode (Legacy)

Memory Considerations

Frame Buffer Sizes

Example Memory Usage

Optimization Tips

  1. Use RGB565 format for memory-constrained devices
  2. Reduce matrix resolution for video playback
  3. Limit buffer frames in streaming mode
  4. Enable hardware acceleration when available

Error Handling

All decoders provide comprehensive error reporting:

fl::string error_msg;
auto decoder = fl::Jpeg::createDecoder(config, &error_msg);
if (!decoder) {
Serial.println("Failed to create decoder: " + error_msg);
return;
}
if (decoder->hasError(&error_msg)) {
Serial.println("Decoder error: " + error_msg);
}
#define Serial
Definition serial.h:304

Performance Tips

  1. Choose appropriate resolution: Lower resolutions decode faster
  2. Use hardware acceleration: Enable useHardwareAcceleration = true
  3. Optimize pixel format: RGB565 is faster than RGB888
  4. Buffer management: Use minimal buffer frames for streaming
  5. Platform-specific: ESP32-S3 PIE optimizations are automatic

Troubleshooting

Common Issues

"Codec not supported on this platform"

Memory allocation failures

Poor video performance

JPEG decode failures

Debug Output

Enable serial output for debugging:

Serial.begin(115200);
Serial.println("Decoder status: " + (decoder->isReady() ? "Ready" : "Not Ready"));

Building and Installation

  1. Install FastLED library with codec support
  2. Copy example to Arduino IDE
  3. Replace sample data with actual JPEG/MPEG1 files
  4. Adjust LED configuration for your hardware
  5. Upload and test

Further Reading