标签:NAME PROJECT target link Ubuntu include 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;
}
编译输出如下:
最后是运行结果,先打印出配置信息,然后是各个库的版本信息。
标签:NAME,PROJECT,target,link,Ubuntu,include,CLion,FFmpeg 来源: https://blog.csdn.net/tyyj90/article/details/116423644
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。