一、安装ffmpeg
1)直接在buildroot 上打开ffmpeg的支持 按图片所示打开重新编译即可
前面俩个可以不用开,其他全打开
保存 重新编译根文件系统
板子roofs更新一下 测试一下ffmpeg 是否可用
ffmpeg
可用结果
libdrm 的版本跟 ffmpeg的版本不兼容 ffmpeg没法正常使用 具体看buildroot的版本了
我这里用的是buildroot2023.02.06 可以尝试更新libdrm 这里我直接自己编译ffmpeg来运行了
2)ubuntu22.04 编译 ffmpeg3.4.8 这里参考luckfox的
参考【Luckfox幸狐 RV1106 Linux 开发板】基于ffmpeg的视频播放测试_rv1106 ffmpeg-CSDN博客
下载ffmpeg源码解压后进入
这里有个我编译好的 下载链接下载即可
wget http://www.ffmpeg.org/releases/ffmpeg-3.4.8.tar.gz
tar -zxvf ffmpeg-3.4.8.tar.gz
cd ffmpeg-3.4.8/
sudo ./configure --enable-cross-compile --arch=arm --target-os=linux --cross-prefix=/home/qsy/rv1106/Echo-Mate-main/SDK/rv1106-sdk/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- --enable-shared --prefix=/usr/lib/ffmpeg
make
make install
指定自己的编译链
--cross-prefix=/home/qsy/rv1106/Echo-Mate-main/SDK/rv1106-sdk/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-
指定编译的输出路径
--prefix=/usr/lib/ffmpeg
这是编译输出的文件 (直接把ffmpeg整个文件copy到板子上)
bin 可执行文件
include 头文件 用于二次开发
lib 动态链接库
share
copy到板子上添加环境变量 bin 添加可执行权限
export LD_LIBRARY_PATH=/root/ffmpeg/lib:$LD_LIBRARY_PATH
export PATH="/root/ffmpeg/bin:$PATH"
chmod +x /root/ffmpeg/bin/*
播放视频尝试 正常这里就可以播放视频了
ffmpeg -i test.mp4 -an -vf "format=rgb565,scale=150:200" -c:v rawvideo -pix_fmt rgb565 -f fbdev /dev/fb0
二、启用LVGL的组件Ffmpeg
LVGL版本9.2.3
参考LVGL官方文档FFmpeg support — LVGL documentation
打开lv_config 的FFMPEG支持
LV_USE_FFMPEG 1
这里直接编译是会报错的 缺少头文件 需要添加我们上面编译的ffmpeg
1)如果你的buildroot 可用 那么cmakelist直接链接到你的buildroot里面就好了
2)如果跟我一样是自己编译的Ffmpeg 链接到你的Ffmpeg路径
Ffmpeg 复制到板子 lib添加到环境变量
cmkaelist示例
# 设置ffmpeg路径(根据你的实际路径)
set(FFMPEG_DIR /home/qsy/rv1106/Echo-Mate-main/ffmpeg)
# 包含头文件
include_directories(${FFMPEG_DIR}/include)
# 链接库文件
link_directories(${FFMPEG_DIR}/lib)
target_link_libraries(main
lvgl
# lvgl::examples
# lvgl::demos
lvgl::thorvg
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${Libdrm_LIBRARIES} m pthread
z
# ffmpeg 的依赖
avformat avcodec swresample swscale avutil
)
到这里重新编译 编译就没问题了 我们看官方给的示例代码
这里不能用LVGL的文件系统 直接用的自己的os系统路径
/*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*/
/*It will use the LVGL filesystem abstraction (not the OS filesystem)
*if `LV_FFMPEG_PLAYER_USE_LV_FS` is set.*/
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);
示例代码
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "gui_app/common/lv_lib.h"
#include "gui_app/ui.h"
static const char *getenv_default(const char *name, const char *dflt)
{
return getenv(name) ? : dflt;
}
#if LV_USE_EVDEV
static void lv_linux_indev_init(void)
{
lv_indev_t * touch;
touch = lv_evdev_create(LV_INDEV_TYPE_POINTER, "/dev/input/event0");
}
#endif
#if LV_USE_LINUX_FBDEV
static void lv_linux_disp_init(void)
{
const char *device = getenv_default("LV_LINUX_FBDEV_DEVICE", "/dev/fb0");
lv_display_t * disp = lv_linux_fbdev_create();
lv_linux_fbdev_set_file(disp, device);
}
#elif LV_USE_LINUX_DRM
static void lv_linux_disp_init(void)
{
const char *device = getenv_default("LV_LINUX_DRM_CARD", "/dev/dri/card0");
lv_display_t * disp = lv_linux_drm_create();
lv_linux_drm_set_file(disp, device, -1);
}
#elif LV_USE_SDL
static void lv_linux_disp_init(void)
{
const int width = atoi(getenv("LV_SDL_VIDEO_WIDTH") ? : "320");
const int height = atoi(getenv("LV_SDL_VIDEO_HEIGHT") ? : "240");
lv_sdl_window_create(width, height);
}
static void lv_linux_indev_init(void)
{
lv_sdl_mouse_create();
}
#else
#error Unsupported configuration
#endif
int main(void)
{
lv_init();
/*Linux display device init*/
lv_linux_disp_init();
lv_linux_indev_init();
/*Create a Demo*/
// lv_demo_widgets();
// lv_demo_widgets_start_slideshow();
// ui_init();
// create label
// lv_obj_t * label = lv_label_create(lv_scr_act());
// lv_label_set_text(label, "Hello, world!");
// // lv_obj_align(label, NULL, LV_ALIGN_CENTER,0,0);
// create button
lv_obj_t * button = lv_btn_create(lv_scr_act());
lv_obj_t * label2 = lv_label_create(button);
lv_label_set_text(label2, "FFMEPG");
lv_obj_align(button, LV_ALIGN_CENTER, 0, 60);
lv_obj_t * player = lv_ffmpeg_player_create(lv_screen_active());
lv_ffmpeg_player_set_src(player, "/root/test.mp4");
lv_ffmpeg_player_set_auto_restart(player, true);
lv_ffmpeg_player_set_cmd(player, LV_FFMPEG_PLAYER_CMD_START);
lv_obj_center(player);
/*Handle LVGL tasks*/
while(1) {
lv_timer_handler();
usleep(1000);
}
return 0;
}
二、LVGL Ffmpeg的 读取文件失败
这里直接运行会显示无法打开文件 报错信息在 lv_ffmpeg.c文件682行
找到 lv_ffmpeg.c 的682行
if(avformat_open_input(&(ffmpeg_ctx->fmt_ctx), path, NULL, NULL) < 0) {
LV_LOG_ERROR("Could not open source file %s", path);
goto failed;
}
这里 需要加一行 否则无法打开文件
av_register_all();
修改后的代码
/* open input file, and allocate format context */
av_register_all();
if(avformat_open_input(&(ffmpeg_ctx->fmt_ctx), path, NULL, NULL) < 0) {
LV_LOG_ERROR("Could not open source file %s", path);
goto failed;
}
至此 重新编译 烧入 程序即可正常运行