FFmpeg 支持¶
FFmpeg 是一个完整的跨平台解决方案,用于录制、转换和流式传输音频和视频。
安装 FFmpeg¶
从这里下载 FFmpeg
./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-zlibmakesudo make install
将 FFmpeg 添加到您的项目¶
添加库:
FFmpeg(对于 GCC:-lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread)
使用方法¶
在 lv_conf.h 中启用 LV_USE_FFMPEG。
请参阅以下示例。
注意,FFmpeg 扩展不使用 LVGL 的文件系统。 您可以直接传递图像或视频的路径,就像在您的操作系统或平台上通常使用的一样。
示例¶
解码图像¶
C code
GitHub#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_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
#endif
Error encountered while trying to open D:\lv_port_pc_eclipse-release-v8.3\lvgl\examples\libs\ffmpeg\lv_example_ffmpeg_1.py
解码视频¶
C code
GitHub#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_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
#endif
Error encountered while trying to open D:\lv_port_pc_eclipse-release-v8.3\lvgl\examples\libs\ffmpeg\lv_example_ffmpeg_2.py
API¶
Enums
Functions
-
void
lv_ffmpeg_init(void)¶ Register FFMPEG image decoder
-
int
lv_ffmpeg_get_frame_num(const char *path)¶ Get the number of frames contained in the file
- Parameters
path -- image or video file name
- Returns
Number of frames, less than 0 means failed
-
lv_obj_t *
lv_ffmpeg_player_create(lv_obj_t *parent)¶ Create ffmpeg_player object
- Parameters
parent -- pointer to an object, it will be the parent of the new player
- Returns
pointer to the created ffmpeg_player
-
lv_res_t
lv_ffmpeg_player_set_src(lv_obj_t *obj, const char *path)¶ Set the path of the file to be played
- Parameters
obj -- pointer to a ffmpeg_player object
path -- video file path
- Returns
LV_RES_OK: no error; LV_RES_INV: can't get the info.
-
void
lv_ffmpeg_player_set_cmd(lv_obj_t *obj, lv_ffmpeg_player_cmd_t cmd)¶ Set command control video player
- Parameters
obj -- pointer to a ffmpeg_player object
cmd -- control commands
Variables
-
const lv_obj_class_t
lv_ffmpeg_player_class¶
-
struct
lv_ffmpeg_player_t¶ Public Members
-
lv_timer_t *
timer¶
-
lv_img_dsc_t
imgdsc¶
-
bool
auto_restart¶
-
struct ffmpeg_context_s *
ffmpeg_ctx¶
-
lv_timer_t *