Ubuntu 20.04 搭建 CLion FFmpeg 开发环境
2021/5/6 7:29:14
本文主要是介绍Ubuntu 20.04 搭建 CLion FFmpeg 开发环境,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
CLion 是一款优秀的编程开发软件,没有 IDE 辅助开发工作很难,因此使用 CLion 开发 Ubuntu 20.04 下的项目是个不错的选择。
一、CLion 安装
首先到 jetbrains 官网 https://www.jetbrains.com/clion/ 下载 CLion 安装包 CLion-2021.1.tar.gz。
下载好安装包后,解压缩包即可,直接使用图形界面工具,鼠标右键,解压到此处即可。
或者使用解压命令也是可以的。
tar -zxvf CLion-2021.1.tar.gz
其中 zxvf 含义分别如下:
z: gzip 压缩格式
x: extract 解压
v: verbose 详细信息
f: file(file=archieve) 文件
解压后的文件夹内找到 Install-Linux-tar.txt,里面描述了详细的安装步骤,下面我只按照文件内的前两步指导去做,其他的都是可选的。
-
Unpack the CLion distribution archive that you downloaded
where you wish to install the program. We will refer to this
location as your {installation home}. -
To start the application, open a console, cd into “{installation home}/bin” and type:
./clion.sh
This will initialize various configuration files in the configuration directory:
~/.config/JetBrains/CLion2021.1. -
[OPTIONAL] Add “{installation home}/bin” to your PATH environment
variable so that you can start CLion from any directory. -
[OPTIONAL] To adjust the value of the JVM heap size, create a file clion.vmoptions
(or clion64.vmoptions if using a 64-bit JDK) in the configuration directory
and set the -Xms and -Xmx parameters. To see how to do this,
you can reference the vmoptions file under “{installation home}/bin” as a model
but do not modify it, add your options to the new file.
第一步就是解压 CLion 安装包,这已经完成了。
第二步进入解压后的 CLion 文件夹,即 ~/clion-2021.1/bin,接着直接运行 clion.sh 脚本,这个脚本会初始化配置目录中的各种配置文件 ~/.config/JetBrains/CLion2021.1
第三步配置环境变量,这一步是可选的,配置好环境变量以后在其他目录下也能直接启动 CLion。第四步调整 JVM 堆大小的值。
二、运行使用 FFmpeg lib 的 Demo
在《FFmpeg Ubuntu 20.04 编译》一节中编译好的 FFmpeg 库位于 ffmpeg_build 目录下。
新建 CLion 工程。重点在 CMakeLists.txt 编写,如果只是简单的加入 FFmpeg lib 和头文件编译,工程会提示报错的,缺少诸如 pthread 库中的函数等等。这就需要参考 /ffmpeg_build/lib/pkgconfig/ 下每个库的 pc 文件了。
工程最终 cmake 配置如下。
cmake_minimum_required(VERSION 3.19) set(PROJECT_NAME ffmpeg_version) project(${PROJECT_NAME}) set(CMAKE_CXX_STANDARD 11) include_directories(/home/snake/ffmpeg_build/include/) link_directories(/home/snake/ffmpeg_build/lib/) add_executable(${PROJECT_NAME} main.cpp) #libavcodec target_link_libraries(${PROJECT_NAME} vpx m pthread vpx m dav1d dl z fdk-aac mp3lame opus vorbis ogg vorbisenc vorbis x264 x265 stdc++ gcc_s gcc rt numa va) #libavdevice target_link_libraries(${PROJECT_NAME} m xcb Xau Xdmcp xcb-shm xcb-shape xcb-xfixes xcb-render asound dl pthread rt SDL2 pulse-simple pulse X11 Xext Xcursor Xinerama Xi Xrandr Xss Xxf86vm wayland-egl wayland-client wayland-cursor xkbcommon sndio Xv) #libavfilter target_link_libraries(${PROJECT_NAME} pthread m ass harfbuzz glib-2.0 pcre graphite2 fontconfig uuid expat fribidi freetype png16 z va) #libavformat target_link_libraries(${PROJECT_NAME} m z gnutls pthread gmp unistring idn2 atomic hogweed nettle tasn1 p11-kit) #libavutil target_link_libraries(${PROJECT_NAME} pthread va-drm va va-x11 vdpau X11 m Xv X11 Xext) #libdav1d target_link_libraries(${PROJECT_NAME} pthread dl) #libpostproc target_link_libraries(${PROJECT_NAME} m) #libSvtAv1Enc target_link_libraries(${PROJECT_NAME} pthread m) #libswresample target_link_libraries(${PROJECT_NAME} m) #libswscale target_link_libraries(${PROJECT_NAME} m) target_link_libraries( ${PROJECT_NAME} avcodec avdevice avfilter avformat avutil dav1d postproc SvtAv1Enc swresample swscale )
以上配置文件中的引入库顺序也至关重要,如果库引入顺序颠倒,可能导致编译无法通过。要注意编译依赖先后顺序。
最后来看一下 main.cpp 源码。
#include <iostream> extern "C" { #include<libavutil/avutil.h> #include<libavcodec/avcodec.h> #include<libavformat/avformat.h> #include<libavdevice/avdevice.h> #include<libavfilter/avfilter.h> #include<libswscale/swscale.h> #include<libswresample/swresample.h> #include<libpostproc/postprocess.h> } void getVersion(unsigned version, char *lib_name) { unsigned major = AV_VERSION_MAJOR(version); unsigned minor = AV_VERSION_MINOR(version); unsigned micro = AV_VERSION_MICRO(version); printf("%s %d.%d.%d\n", lib_name, major, minor, micro); } int main() { std::cout << "config: " << avutil_configuration() << std::endl; char avutil[] = "avutil"; getVersion(avutil_version(), avutil); char avcodec[] = "avcodec"; getVersion(avcodec_version(), avcodec); char avformat[] = "avformat"; getVersion(avformat_version(), avformat); char avdevice[] = "avdevice"; getVersion(avdevice_version(), avdevice); char avfilter[] = "avfilter"; getVersion(avfilter_version(), avfilter); char swscale[] = "swscale"; getVersion(swscale_version(), swscale); char swresample[] = "swresample"; getVersion(swresample_version(), swresample); char postproc[] = "postproc"; getVersion(postproc_version(), postproc); return 0; }
编译输出如下:
最后是运行结果,先打印出配置信息,然后是各个库的版本信息。
这篇关于Ubuntu 20.04 搭建 CLion FFmpeg 开发环境的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-06Package Easy(基于 NSIS 的打包exe安装包工具)使用方法-icode9专业技术文章分享
- 2024-06-06基于 casdoor 的 ELK 开源登录认证解决方案: elk-auth-casdoor-icode9专业技术文章分享
- 2024-05-29Elasticsearch慢查询日志配置
- 2024-05-29揭秘华为如此多成功项目的产品关键——Charter模板
- 2024-05-29海外IDC业务拓展的7大挑战
- 2024-05-29InLine Chat功能优化对标Github Copilot,CodeGeeX带来更高效、更直观的编程体验!
- 2024-05-29CodeGeeX 智能编程助手 6 项功能升级,在Visual Studio插件市场霸榜2周!
- 2024-05-29AutoMQ 生态集成 Apache Doris
- 2024-05-292024年IDC行业的深度挖掘:机遇、挑战与未来展望
- 2024-05-29五款扩展组件齐发 —— Volcano、Keda、Crane-scheduler 等,邀你体验