linux笔记(10):ubuntu环境下,基于SDL2运行lvgl+ffmpeg播放mp4

10 篇文章 6 订阅


参考文章:
1.百问网: 3rd party libraries(第 3 方库) » FFmpeg support
效果:

linux-sdl-lvlg-ffmpegmp4

1.ubuntu安装ffmpeg

1.1 源码安装

1.1 克隆ffmpeg源码

git clone https://github.com/FFmpeg/FFmpeg.git

1.2 配置编译条件,编译,安装

#1.配置
./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
#2.编译
make
#3.安装
sudo make install 

1.2 直接安装依赖包

我由于先安装了源码,再安装依赖包,现在都不知道是不是直接安装依赖包就可以了。
2023年3月12日,在家里的电脑测试了一下不用编译安装源码,只安装依赖包,就可以正常使用SDL2和FFmpeg。

sudo apt install libsdl2-dev libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libswresample-dev

2.下载lvgl源码

2.1 测试原始代码

使用这个版本https://github.com/lvgl/lv_port_pc_eclipse的源码。

#1.下载源码
git clone https://github.com/lvgl/lv_port_pc_eclipse.git
#2.进入目录
cd lv_port_pc_eclipse
#3.下载子模块
git submodule update  --init --recursive

此时,默认显示配置使用SDL,可以直接编译运行,默认运行《lv_demo_widgets()》:
在这里插入图片描述
lv_port_pc_eclipse 目录下,直接编译,运行:

#1.编译
make
#2.运行,SDL需要管理员权限
sudo ./demo

2.2 运行lv_example_ffmpeg_2()例程

2.2.1 配置 LV_USE_FFMPEG 为 1

在顶层目录下的 《lv_conf.h》 配置 LV_USE_FFMPEG 为 1:
在这里插入图片描述

2.2.2 lv_example_ffmpeg_2()替换lv_demo_widgets()

//    lv_demo_widgets();
  lv_example_ffmpeg_2();

2.2.3 链接库增加ffmpeg的库目录和库名

lv_port_pc_eclipse 目录下,修改Makefile,增加红框的内容:

LDLIBS	 			:= -lSDL2 -lm -L/uar/local/ffmpeg/lib -lavutil -lavformat -lavcodec -lswscale -lswresample 

在这里插入图片描述

2.2.4 《lv_ffmpeg.c》增加一行代码 av_register_all()

《lvgl\src\extra\libs\ffmpeg\lv_ffmpeg.c》 需要增加一行代码,才能正常工作:
在这里插入图片描述
在上面的函数中,没有av_register_all()就会导致avformat_open_input()出错;或许av_register_all()应该放置在更合理的地方(比如ffmpeg初始化时),放置这里只是临时解决方案。
从上面图片中689行的代码:

  if(avformat_open_input(&(ffmpeg_ctx->fmt_ctx), path, NULL, NULL) < 0) {

可以推断,视频文件的路径path是linux系统路径,不用理会lvgl自身的路径。

2.2.5 视频文件传入路径

本例程中,使用的文件系统驱动是STDIO ,lvgl自身的文件目录的命名都没有起作用,直接使用ubuntu的文件目录。
在这里插入图片描述
比如我播放的视频是 bird.mp4 ,在ubuntu中的路径是 /mnt/hgfs/linux-D1/app/birds.mp4,直接传入例程:

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, "/mnt/hgfs/linux-D1/app/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);
}

在这里插入图片描述

3.源码链接及编译方法

https://gitee.com/huangweide001/lvgl-ffmpeg
编译本源码时,只需安装1.2节的依赖包,修改mp4文件的目录:

在这里插入图片描述
lv_example_ffmpeg_2() 位于 lvgl-ffmpeg/lvgl/examples/libs/ffmpeg/lv_example_ffmpeg_2.c 文件中。
lvgl-ffmpeg 目录下,直接编译,运行即可。

  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
对于您的问题,"E: Unable to locate package sdl2"表示在Ubuntu 22.04上找不到sdl2软件包。这可能是因为sdl2软件包不在默认的Ubuntu软件源中。要解决该问题,您可以尝试以下方法: 方法1: 1. 确保您的软件源已更新。可以使用以下命令更新软件源: ``` sudo apt update ``` 2. 然后尝试重新安装sdl2软件包: ``` sudo apt install sdl2 ``` 方法2: 1. 检查您是否已将适当的软件源添加到您的系统。您可以编辑`/etc/apt/sources.list`文件,并确保已添加包含sdl2软件包的软件源。例如,您可以添加以下行: ``` deb http://archive.ubuntu.com/ubuntu xenial main universe ``` 2. 更新软件源并尝试重新安装sdl2软件包: ``` sudo apt update sudo apt install sdl2 ``` 如果以上方法都无法解决问题,您还可以尝试从其他来源手动安装sdl2软件包。您可以从sdl2的官方网站或其他可信的软件源下载并安装sdl2软件包。请确保您从可信的来源下载软件包,并按照提供的安装说明进行操作。 : http://stackoverflow.com/questions/11401079/makeinfo-package-missing-in-ubuntu-12-04 : root@Ubuntu32:/home/zhangbin/ffmpeg/ffmpegx86/ffmpeg-1.2# apt-get install texi2html Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: latex2html The following NEW packages will be installed: texi2html 0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded. Need to get 401 kB of archives. After this operation, 1,851 kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main texi2html all 1.82-1ubuntu1 [401 kB] Fetched 401 kB in 2s (171 kB/s) Selecting previously unselected package texi2html. (Reading database ... 211335 files and directories currently installed.) Unpacking texi2html (from .../texi2html_1.82-1ubuntu1_all.deb) ... Processing triggers for install-info ... Processing triggers for man-db ... Processing triggers for doc-base ... Processing 1 added doc-base file... Setting up texi2html (1.82-1ubuntu1) ... : dtc下载地址:git.qemu-project.org/?p=dtc.git;a=snapshot;h=1760e7ca03894689118646e229ca9487158cd0e8;sf=tgz
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值