|
| 1 | +| Supported Targets | ESP32-P4 | |
| 2 | +| ----------------- | -------- | |
| 3 | + |
| 4 | +# HDMI Video Renderer |
| 5 | + |
| 6 | +This example demonstrates how to display a video in MP4/AVI format on an HDMI monitor. |
| 7 | + |
| 8 | +## How to use the example |
| 9 | + |
| 10 | +## ESP-IDF Required |
| 11 | + |
| 12 | +### Hardware Required |
| 13 | + |
| 14 | +* An ESP32-P4-Function-EV-Board. |
| 15 | +* An [ESP-HDMI-Bridge](https://oshwhub.com/esp-college/esp-hdmi-bridge). |
| 16 | +* An SD card that stores MP4 videos. |
| 17 | +* A USB-C cable for power supply and programming. |
| 18 | +* Please refer to the following steps for the connection: |
| 19 | + * **Step 1**. According to the table below, connect the pins on the back of the screen adapter board to the corresponding pins on the development board. |
| 20 | + |
| 21 | + | ESP-HDMI-Bridge | ESP32-P4-Function-EV-Board | |
| 22 | + | -------------------- | -------------------------- | |
| 23 | + | 5V (any one) | 5V (any one) | |
| 24 | + | GND (any one) | GND (any one) | |
| 25 | + |
| 26 | + * **Step 2**. Connect the FPC of LCD through the `MIPI_DSI` interface. |
| 27 | + * **Step 3**. Use a USB-C cable to connect the `USB-UART` port to a PC (Used for power supply and viewing serial output). |
| 28 | + * **Step 4**. Turn on the power switch of the board. |
| 29 | + |
| 30 | +### Configure the Project |
| 31 | + |
| 32 | +Run `idf.py menuconfig` and navigate to `HDMI MP4 Player Configuration` menu. |
| 33 | + |
| 34 | +- Navigate to `Video File Configuration` submenu |
| 35 | +- Set the `Video File Name` to match your video file name stored in the SD card |
| 36 | +- Default value is `test_video.mp4` |
| 37 | +- Make sure the file name matches exactly, including the `.mp4` or `.avi` extension |
| 38 | + |
| 39 | +### Test Video Downloads |
| 40 | + |
| 41 | +This repository provides a test MP4 file encoded with MJPEG video and AAC audio for testing and compatibility purposes. |
| 42 | + |
| 43 | +- **Video Codec**: MJPEG |
| 44 | +- **Audio Codec**: AAC |
| 45 | +- **Frame Rate**: 20fps(RGB888) |
| 46 | +- **File Format**: `.mp4` |
| 47 | +- **Download Link**: [test_video.mp4](https://dl.espressif.com/AE/esp-dev-kits/test_video.mp4) |
| 48 | + |
| 49 | +This test file is useful for validating MJPEG decoding, AAC audio support, and embedded system playback compatibility. |
| 50 | + |
| 51 | +### Build and Flash |
| 52 | + |
| 53 | +Run `idf.py set-target esp32p4` to select the target chip. |
| 54 | + |
| 55 | +Run `idf.py -p PORT build flash monitor` to build, flash and monitor the project. A fancy animation will show up on the LCD as expected. |
| 56 | + |
| 57 | +The first time you run `idf.py` for the example will cost extra time as the build system needs to address the component dependencies and downloads the missing components from registry into `managed_components` folder. |
| 58 | + |
| 59 | +(To exit the serial monitor, type ``Ctrl-]``.) |
| 60 | + |
| 61 | +See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects. |
| 62 | + |
| 63 | +## Troubleshooting |
| 64 | + |
| 65 | +For any technical queries, please open an [issue](https://github.com/espressif/esp-iot-solution/issues) on GitHub. We will get back to you soon. |
| 66 | + |
| 67 | +## Important Notes |
| 68 | + |
| 69 | +### Video Format Requirements |
| 70 | + |
| 71 | +1. **MP4 Container Format** |
| 72 | + - Currently only supports MP4 files with MJPEG video encoding |
| 73 | + - Other video codecs (H.264, H.265, etc.) are not supported at this time |
| 74 | + - Audio tracks in MP4 files are supported |
| 75 | + |
| 76 | +2. **Video Resolution and Format** |
| 77 | + - For YUV420 format videos: |
| 78 | + * Width must be divisible by 16 |
| 79 | + * Height must be divisible by 16 |
| 80 | + * This alignment requirement ensures optimal performance and compatibility |
| 81 | + - For YUV422 format videos: |
| 82 | + * Width must be divisible by 16 |
| 83 | + * Height must be divisible by 8 |
| 84 | + * Provides better color quality than YUV420 but requires more bandwidth |
| 85 | + - For YUV444 format videos: |
| 86 | + * Width must be divisible by 8 |
| 87 | + * Height must be divisible by 8 |
| 88 | + * Offers the highest color quality but requires the most bandwidth |
| 89 | + |
| 90 | +3. **Display Buffer Configuration** |
| 91 | + - When using LCD internal buffer mode: |
| 92 | + * Video resolution must exactly match the HDMI output resolution |
| 93 | + * This ensures optimal performance and prevents display artifacts |
| 94 | + * Example: If HDMI is set to 1280x720, the MP4 must also be 1280x720 |
| 95 | + - When using external buffer mode: |
| 96 | + * More flexible resolution support |
| 97 | + * Automatic scaling is available |
| 98 | + * May have slightly lower performance compared to internal buffer mode |
| 99 | + |
| 100 | +### FAQ |
| 101 | + |
| 102 | +#### Blue Screen Flickering Issues |
| 103 | + |
| 104 | +If you encounter blue screen flickering during video playback, this is typically caused by **insufficient PSRAM bandwidth**. Here are the recommended solutions: |
| 105 | + |
| 106 | +1. **Use RGB565 Format** |
| 107 | + - If your display supports RGB565, consider switching from RGB888 to RGB565 format |
| 108 | + |
| 109 | +2. **Optimize Video Parameters** |
| 110 | + - **Lower Resolution**: Reduce video resolution (e.g., from 1280x720 to 1024x768) |
| 111 | + - **Reduce Frame Rate**: Lower the video frame rate (e.g., from 30fps to 20fps or 15fps) |
| 112 | + - **Increase Compression**: Use higher JPEG compression quality to reduce frame sizes |
| 113 | + |
| 114 | +3. **AVI Format Audio Limitations** |
| 115 | + - **AVI videos with audio are not recommended** due to higher bandwidth requirements |
| 116 | + - If playing AVI files causes blue screen flickering, **disable audio playback** |
| 117 | + - For audio playback, use MP4 format with AAC encoding instead |
| 118 | + |
| 119 | +These optimizations help balance video quality with available system bandwidth to ensure stable playback. |
| 120 | + |
| 121 | +## Video Conversion with FFmpeg |
| 122 | + |
| 123 | +### Installation |
| 124 | +```bash |
| 125 | +# Windows: Download from https://ffmpeg.org/download.html |
| 126 | +# macOS: brew install ffmpeg |
| 127 | +# Linux: sudo apt install ffmpeg |
| 128 | +``` |
| 129 | + |
| 130 | +### Basic MJPEG Conversion |
| 131 | +```bash |
| 132 | +# Convert any video to MJPEG MP4 |
| 133 | +ffmpeg -i input.mp4 -c:v mjpeg -c:a aac output.mp4 |
| 134 | +``` |
| 135 | + |
| 136 | +### Recommended Settings |
| 137 | + |
| 138 | +**High Quality (1280x720, RGB888 displays):** |
| 139 | +```bash |
| 140 | +ffmpeg -i input.mp4 -c:v mjpeg -q:v 3 -vf scale=1280:720 -r 20 -c:a aac output.mp4 |
| 141 | +``` |
| 142 | + |
| 143 | +**Balanced (1024x768, recommended):** |
| 144 | +```bash |
| 145 | +ffmpeg -i input.mp4 -c:v mjpeg -q:v 5 -vf scale=1024:768 -r 20 -c:a aac output.mp4 |
| 146 | +``` |
| 147 | + |
| 148 | +**Low Bandwidth (800x600, RGB565 or troubleshooting):** |
| 149 | +```bash |
| 150 | +ffmpeg -i input.mp4 -c:v mjpeg -q:v 8 -vf scale=800:600 -r 15 -c:a aac output.mp4 |
| 151 | +``` |
| 152 | + |
| 153 | +### Key Parameters |
| 154 | +- `-q:v`: Quality (1-31, lower = better quality, larger file) |
| 155 | +- `-vf scale=W:H`: Resolution adjustment |
| 156 | +- `-r`: Frame rate (15-25 fps recommended) |
| 157 | +- `-an`: Remove audio if causing issues |
0 commit comments