feat(lib) add ffmpeg video and image decoder (#2805)

* add ffmpeg decoder to extra/libs

* fix(Kconfig) add ffmpeg configuration

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>

* feat(example) add ffmpeg decoder example

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>

* update lv_conf_template.h

* feat(example) add picture and video to ffmpeg example

* docs(libs) update FFMpeg introduction

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>

* fix(ffmpeg) replace with new videos and examples

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>

* fix(ffmpeg) remove the include of lv_img_cache.h

* fix(ffmpeg) add LV_ASSERT_OBJ

* Update examples/libs/ffmpeg/lv_example_ffmpeg_2.c

Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
_VIFEXTech
2021-11-19 15:49:39 +08:00
committed by GitHub
parent bdc6331ba6
commit a97ac7ec8e
15 changed files with 1146 additions and 0 deletions
+7
View File
@@ -834,6 +834,13 @@ menu "LVGL configuration"
config LV_USE_RLOTTIE
bool "Lottie library"
config LV_USE_FFMPEG
bool "FFmpeg library"
config LV_FFMPEG_AV_DUMP_FORMAT
bool "Dump av format"
depends on LV_USE_FFMPEG
default n
endmenu
menu "Others"
+34
View File
@@ -0,0 +1,34 @@
```eval_rst
.. include:: /header.rst
:github_url: |github_link_base|/libs/ffmpeg.md
```
# FFmpeg support
[FFmpeg](https://www.ffmpeg.org/) A complete, cross-platform solution to record, convert and stream audio and video.
## Install FFmpeg
- Download FFmpeg from [here](https://www.ffmpeg.org/download.html)
- `./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`
## Add FFmpeg to your project
- Add library: `FFmpeg` (for GCC: `-lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread`)
## Usage
Enable `LV_USE_FFMPEG` in `lv_conf.h`.
See the examples below.
Note that, the FFmpeg extension doesn't use LVGL's file system.
You can simply pass the path to the font as usual on your operating system or platform.
## API
```eval_rst
.. doxygenfile:: lv_ffmpeg.h
:project: lvgl
```
+1
View File
@@ -18,5 +18,6 @@
freetype
qrcode
rlottie
ffmpeg
```
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

+39
View File
@@ -0,0 +1,39 @@
/**
* @file lv_example_ffmpeg.h
*
*/
#ifndef LV_EXAMPLE_FFMPEG_H
#define LV_EXAMPLE_FFMPEG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_example_ffmpeg_1(void);
void lv_example_ffmpeg_2(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_EXAMPLE_FFMPEG_H*/
@@ -0,0 +1,26 @@
#include "../../lv_examples.h"
#if LV_USE_FFMPEG && LV_BUILD_EXAMPLES
/**
* Open a image from a file
*/
void lv_example_ffmpeg_1(void)
{
lv_obj_t * img = lv_img_create(lv_scr_act());
lv_img_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_scr_act());
lv_label_set_text(label, "FFmpeg is not installed");
lv_obj_center(label);
}
#endif
@@ -0,0 +1,30 @@
#include "../../lv_examples.h"
#if LV_USE_FFMPEG && LV_BUILD_EXAMPLES
/**
* 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_scr_act());
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_scr_act());
lv_label_set_text(label, "FFmpeg is not installed");
lv_obj_center(label);
}
#endif
+1
View File
@@ -20,6 +20,7 @@ extern "C" {
#include "qrcode/lv_example_qrcode.h"
#include "freetype/lv_example_freetype.h"
#include "rlottie/lv_example_rlottie.h"
#include "ffmpeg/lv_example_ffmpeg.h"
/*********************
* DEFINES
+8
View File
@@ -581,6 +581,14 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
/*Rlottie library*/
#define LV_USE_RLOTTIE 0
/*FFmpeg library for image decoding and playing videos
*Supports all major image formats so do not enable other image decoder with it*/
#define LV_USE_FFMPEG 0
#if LV_USE_FFMPEG
/*Dump input information to stderr*/
#define LV_FFMPEG_AV_DUMP_FORMAT 0
#endif
/*-----------
* Others
*----------*/
File diff suppressed because it is too large Load Diff
+104
View File
@@ -0,0 +1,104 @@
/**
* @file lv_ffmpeg.h
*
*/
#ifndef LV_FFMPEG_H
#define LV_FFMPEG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lvgl.h"
#if LV_USE_FFMPEG != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct ffmpeg_context_s;
extern const lv_obj_class_t lv_ffmpeg_player_class;
typedef struct {
lv_img_t img;
lv_timer_t * timer;
lv_img_dsc_t imgdsc;
bool auto_restart;
struct ffmpeg_context_s * ffmpeg_ctx;
} lv_ffmpeg_player_t;
typedef enum {
LV_FFMPEG_PLAYER_CMD_START,
LV_FFMPEG_PLAYER_CMD_STOP,
LV_FFMPEG_PLAYER_CMD_PAUSE,
LV_FFMPEG_PLAYER_CMD_RESUME,
_LV_FFMPEG_PLAYER_CMD_LAST
} lv_ffmpeg_player_cmd_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Register FFMPEG image decoder
*/
void lv_ffmpeg_init(void);
/**
* Get the number of frames contained in the file
* @param path image or video file name
* @return Number of frames, less than 0 means failed
*/
int lv_ffmpeg_get_frame_num(const char * path);
/**
* Create ffmpeg_player object
* @param parent pointer to an object, it will be the parent of the new player
* @return pointer to the created ffmpeg_player
*/
lv_obj_t * lv_ffmpeg_player_create(lv_obj_t * parent);
/**
* Set the path of the file to be played
* @param obj pointer to a ffmpeg_player object
* @param path video file path
* @return LV_RES_OK: no error; LV_RES_INV: can't get the info.
*/
lv_res_t lv_ffmpeg_player_set_src(lv_obj_t * obj, const char * path);
/**
* Set command control video player
* @param obj pointer to a ffmpeg_player object
* @param cmd control commands
*/
void lv_ffmpeg_player_set_cmd(lv_obj_t * obj, lv_ffmpeg_player_cmd_t cmd);
/**
* Set the video to automatically replay
* @param obj pointer to a ffmpeg_player object
* @param en true: enable the auto restart
*/
void lv_ffmpeg_player_set_auto_restart(lv_obj_t * obj, bool en);
/*=====================
* Other functions
*====================*/
/**********************
* MACROS
**********************/
#endif /*LV_USE_FFMPEG*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_FFMPEG_H*/
+1
View File
@@ -21,6 +21,7 @@ extern "C" {
#include "sjpg/lv_sjpg.h"
#include "freetype/lv_freetype.h"
#include "rlottie/lv_rlottie.h"
#include "ffmpeg/lv_ffmpeg.h"
/*********************
* DEFINES
+4
View File
@@ -75,6 +75,10 @@ void lv_extra_init(void)
*Cache max 64 faces and 1 size*/
lv_freetype_init(0, 0, LV_FREETYPE_CACHE_SIZE);
#endif
#if LV_USE_FFMPEG
lv_ffmpeg_init();
#endif
}
/**********************
+20
View File
@@ -1878,6 +1878,26 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
# endif
#endif
/*FFmpeg library for image decoding and playing videos
*Supports all major image formats so do not enable other image decoder with it*/
#ifndef LV_USE_FFMPEG
# ifdef CONFIG_LV_USE_FFMPEG
# define LV_USE_FFMPEG CONFIG_LV_USE_FFMPEG
# else
# define LV_USE_FFMPEG 0
# endif
#endif
#if LV_USE_FFMPEG
/*Dump input information to stderr*/
#ifndef LV_FFMPEG_AV_DUMP_FORMAT
# ifdef CONFIG_LV_FFMPEG_AV_DUMP_FORMAT
# define LV_FFMPEG_AV_DUMP_FORMAT CONFIG_LV_FFMPEG_AV_DUMP_FORMAT
# else
# define LV_FFMPEG_AV_DUMP_FORMAT 0
# endif
#endif
#endif
/*-----------
* Others
*----------*/