龙空技术网

音视频开发6. 搭建 ffmpeg Linux远程开发环境

编程圈子 292

前言:

如今小伙伴们对“centos编译安装ffmpeg”可能比较关注,朋友们都需要剖析一些“centos编译安装ffmpeg”的相关文章。那么小编同时在网摘上收集了一些有关“centos编译安装ffmpeg””的相关资讯,希望小伙伴们能喜欢,姐妹们快快来了解一下吧!

一、准备环境CentOS7 服务端安装gcc4.8.2本地windows,安装vscode

目标: 搭建FFmpeg 远程开发环境 ,本地使用VSCode。

二、操作步骤1. 在CentOS 编译安装 ffmpeg

安装可参考: CentOS编译安装ffmpeg

2. 编译安装ffmpeg后的环境

库文件位置 : /usr/lib

ffmpeg源文件位置: /home/用户名/ffmpeg_sources/ffmpeg-4.2.2

3. 本地在vscode安装 远程开发插件

另外安装 c/c++插件。

4. 点击vscode左下角,进行远程配置。

按提示配置远程服务器信息。

5. 点击左侧Remote Explorer,连接到服务端6. 在vscode点击文件菜单,打开文件夹,选择远程目录三、建测试项目

项目路径: /home/xundh/ffmpegrtsp/

1. 项目CmakeLists.txt设置

cmake_minimum_required(VERSION 3.17)project(ffmpeg_demo)# 设置ffmpeg依赖库及头文件所在目录,并存进指定变量set(ffmpeg_libs_DIR /home/xundh/ffmpeg_sources/ffmpeg-4.2.2)set(ffmpeg_headers_DIR /home/xundh/ffmpeg_sources/ffmpeg-4.2.2)#对于find_package找不到的外部依赖库,可以用add_library添加# SHARED表示添加的是动态库# IMPORTED表示是引入已经存在的动态库add_library( avcodec SHARED IMPORTED)add_library( avfilter SHARED IMPORTED )add_library( swresample SHARED IMPORTED )add_library( swscale SHARED IMPORTED )add_library( avformat SHARED IMPORTED )add_library( avutil SHARED IMPORTED )#指定所添加依赖库的导入路径set_target_properties( avcodec PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavcodec/libavcodec.so )set_target_properties( avfilter PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavfilter/libavfilter.so )set_target_properties( swresample PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libswresample/libswresample.so )set_target_properties( swscale PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libswscale/libswscale.so )set_target_properties( avformat PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavformat/libavformat.so )set_target_properties( avutil PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavutil/libavutil.so )# 添加头文件路径到编译器的头文件搜索路径下,多个路径以空格分隔include_directories( ${ffmpeg_headers_DIR} )link_directories(${ffmpeg_libs_DIR} )link_directories(/usr/lib)set(CMAKE_CXX_STANDARD 14)add_executable(ffmpeg_demo main.cpp)target_link_libraries(${PROJECT_NAME}  avcodec avformat avutil swresample swscale swscale avfilter )
2. main.cpp
#include <stdio.h>#ifdef __cplusplusextern "C"{#endif#include "libavcodec/avcodec.h"#include "libavformat/avformat.h"#include "libavutil/imgutils.h"#include "libavutil/pixfmt.h"#include "libavutil/avutil.h"#include "libavutil/log.h"#include "libswscale/swscale.h"#ifdef __cplusplus}#endifusing namespace std;int main(){	return 0;}
3. 编译运行
cd /home/xundh/ffmpegrtspmkdir buildcd buildcmake ..make./ffmpeg_demo

标签: #centos编译安装ffmpeg