FFmpeg Support

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video.

The FFmpeg is an LVGL extension that interfaces with the official FFmpeg library to help you add platform-independent recording, converting and streaming audio and video into your LVGL UI.

The set-up steps below are for Linux, but they can be adapted for other platforms.

For a detailed introduction, see: https://www.ffmpeg.org

Installing FFmpeg

Download the FFmpeg library from its official download page, then install it:

./configure --disable-all --disable-autodetect --disable-podpages --disable-asm --enable-avcodec --enable-avformat --enable-decoders --enable-encoders --enable-demuxers --enable-parsers --enable-protocol='file' --enable-swscale --enable-zlib
make
sudo make install

Adding FFmpeg to Your Project

To use the FFmpeg library in your project, you will need to link against these libraries:

libavformat:

part of FFmpeg library

libavcodec:

part of FFmpeg library

libavutil:

part of FFmpeg library

libswscale:

part of FFmpeg library

libm:

libz:

libpthread:

If you are using GCC-based toolchain, this can be taken care of by adding the following command-line options:

-lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread

Usage

Set the LV_USE_FFMPEG in lv_conf.h to 1.

Also set LV_FFMPEG_PLAYER_USE_LV_FS in lv_conf.h to 1 if you want to integrate the LVGL File System (lv_fs_drv) extension into FFmpeg.

See the examples below for how to correctly use this library.

Events

  • LV_EVENT_READY Sent when playback is complete and auto-restart is not enabled.

Learn more about Events.

Examples

Decode image

#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_FFMPEG

/**
 * Open an image from a file
 */
void lv_example_ffmpeg_1(void)
{
    lv_obj_t * img = lv_image_create(lv_screen_active());
    lv_image_set_src(img, "./lvgl/examples/libs/ffmpeg/ffmpeg.png");
    lv_obj_center(img);
}

#else

void lv_example_ffmpeg_1(void)
{
    /*TODO
     *fallback for online examples*/

    lv_obj_t * label = lv_label_create(lv_screen_active());
    lv_label_set_text(label, "FFmpeg is not installed");
    lv_obj_center(label);
}

#endif
#endif

Decode video

#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_FFMPEG

/**
 * Open a video from a file
 */
void lv_example_ffmpeg_2(void)
{
    /*birds.mp4 is downloaded from http://www.videezy.com (Free Stock Footage by Videezy!)
     *https://www.videezy.com/abstract/44864-silhouettes-of-birds-over-the-sunset*/
    lv_obj_t * player = lv_ffmpeg_player_create(lv_screen_active());
    lv_ffmpeg_player_set_src(player, "./lvgl/examples/libs/ffmpeg/birds.mp4");
    lv_ffmpeg_player_set_auto_restart(player, true);
    lv_ffmpeg_player_set_cmd(player, LV_FFMPEG_PLAYER_CMD_START);
    lv_obj_center(player);
}

#else

void lv_example_ffmpeg_2(void)
{
    /*TODO
     *fallback for online examples*/

    lv_obj_t * label = lv_label_create(lv_screen_active());
    lv_label_set_text(label, "FFmpeg is not installed");
    lv_obj_center(label);
}

#endif
#endif

API

lv_ffmpeg.h

lv_types.h