涉及技术:
1、ffmpeg下linux编译+x264
进入x264解压
./configure --prefix=/usr/local/x264 --enable-shared --enable-static --host=arm-linux --cross-prefix=aarch64-linux-gnu- --disable-opencl --enable-fPIC --disable-asm
make -j8
make install
ffmpeglinux下编译
--prefix=/home/Desktop/ffmpeg/ffmpeg-outX11 --enable-x11grab --enable-filters --enable-asm --enable-ffmpeg --enable-ffplay --enable-ffprobe --enable-doc --enable-cross-compile --cross-prefix=aarch64-linux-gnu- --arch=aarch64 --target-os=linux --host-os=linux --enable-gpl --enable-version3 --enable-small --enable-shared --enable-static --enable-encoder=rawvideo --enable-encoder=mpeg2video --enable-encoder=mp2 --enable-encoder=libx264 --enable-libx264 --enable-muxer=adts --enable-muxer=mpegts --enable-muxer=mgeg2video --enable-muxer=rtsp --enable-muxer=hls --enable-muxer=h264 --enable-muxer=rtp --enable-muxer=avi --enable-muxer=flv --enable-muxer=mp4 --enable-demuxer=mpegts --enable-demuxer=rtsp --enable-demuxer=hls --enable-demuxer=h264 --enable-demuxer=rtp --enable-demuxer=flv --enable-demuxer=mp4 --enable-demuxer=avi --enable-demuxer=mpegps --enable-demuxer=mpegtsraw --enable-parser=aac --enable-parser=h264 --enable-parser=mpeg4video --enable-parser=mpegvideo --enable-parser=mpegaudio --enable-bsf=h264_mp4toannexb --enable-protocol=http --enable-protocol=rtp --enable-protocol=rtmpts --enable-protocol=https --enable-protocol=hls --enable-protocol=file --enable-protocol=data --enable-gray --enable-safe-bitstream-reader --enable-swscale --enable-swscale-alpha --enable-filter=scale --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
make -j8
make install
借鉴博客
https://www.cnblogs.com/yaoz/p/6944942.html ffmpeg编译
2、Linux下动态库路径搜索设置&动态库的依赖库
sudo vi /etc/ld.so.conf 将想要包含的动态库路径放里面
sudo ldconfig 将设置同步到系统上,注意设置之后ldd查看调用动态库寻找的时候最好关闭命令矿重新打开
动态库的依赖库(需要使用动态库需要链接的动态库) LD_Library_PATH 使用相对路径 -rpath .属性 libswresample.so.3 => ./libswresample.so.3
sudo ldconfig 可以创建出实体动态库相应的软链接
借鉴博客
https://blog.csdn.net/weixin_37139197/article/details/78736291
3、cmake&make&g++编译
使用自己编出的动态库编测试程序,依赖库放置lib下
g++ main.cpp -I/home/ffmpeg/include -L/home/ffmpeg/lib -lDesktopRecordSO_shared
将cmanager和DoubleRecord以及依赖库编译生成动态库
g++ cmanager.cpp DoubleRecord.cpp -g -std=c++11 -fPIC -Wl,-rpath ./ffmpeg/lib -shared -o libDesktopRecordSO_shared.so -I/home
/DesktopRecord/ffmpeg/include -lz -llzma -lm -lbz2 -lasound -lxcb -lssl -lavformat -lavcodec -lavutil -lx264 -lswresample -lswscale
cmake博客 编写生成动态库 失败
cmake_minimum_required (VERSION 3.5)
project (DesktopRecordSO)
add_compile_options(-fPIC)
include_directories (/home/Desktop/DesktopRecord_so/ffmpeg/include)
find_library(TESTFUNC_LIB libavcodec.a libxcb.a libavfilter.a libavformat.a libavutil.a libpostproc.a libswresample.a libswscale.a libx264 HINTS /home/Desktop/DesktopRecord_so/ffmpeg/lib)
set (SRC_LIST /home/Desktop/DesktopRecord_so/cmanager.cpp)
add_library (DesktopRecordSO_shared SHARED ${SRC_LIST})
set_target_properties (DesktopRecordSO_shared PROPERTIES OUTPUT_NAME "DesktopRecordSO_shared")
target_link_libraries (DesktopRecordSO_shared ${TESTFUNC_LIB})
set (LIBRARY_OUTPUT_PATH /home/Desktop/DesktopRecord_so/lib)
借鉴博客
https://blog.csdn.net/whahu1989/article/details/82078563#t5
make 编写生成动态库 失败
4、linux zlog日志库
借鉴博客
https://blog.csdn.net/wangqingchuan92/article/details/107338690/
https://www.cnblogs.com/superPerfect/p/3617716.html
https://blog.csdn.net/sinat_36436112/article/details/105921759?utm_term=zlog%E6%97%A5%E5%BF%97%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allsobaiduweb~default-0-105921759&spm=3001.4430
http://hardysimpson.github.io/zlog/ 下载最新的zlog源码包以及代码直接输出配置文件
https://blog.csdn.net/fireblue1990/article/details/55808086
获取本地时间 创建文件夹mkdir函数 注意操作mode |来组合
void GetTimeEx2(char *pBuf)
{
time_t nt;
time(&nt);
struct tm *local;
local = localtime(&nt);
sprintf(pBuf, "%04d%02d%02d", local->tm_year + 1900,
local->tm_mon + 1,
local->tm_mday);
}
bool InitLogFile(void)
{
int rc;
char *szAppPath;
szAppPath = getcwd(NULL, 0);
char szTime[32] = { 0 };
GetTimeEx2(szTime);
char szConfigPath[10000] = { 0 };
sprintf(szConfigPath, "%s/zlog.conf", szAppPath);
char szLogFilePath[10000] = { 0 };
sprintf(szLogFilePath, "%s/log", szAppPath);
if (access(szLogFilePath, 0) < 0)
mkdir(szLogFilePath, S_IRWXU | S_IRWXG);
char szLogFilePathEx[1000] = { 0 };
sprintf(szLogFilePathEx, "%s/log/DesktopRecord-%s.log", szAppPath, szTime);
FILE *pFile = fopen(szConfigPath, "wb");
if (pFile)
{
char *pWriteData = "[formats]\n";
fwrite(pWriteData, 1, strlen(pWriteData), pFile);
char *pWriteData2 = "my = \"%d|%V| %m%n\"\n";
fwrite(pWriteData2, 1, strlen(pWriteData2), pFile);
char *pWriteData3 = "[rules]\n";
fwrite(pWriteData3, 1, strlen(pWriteData3), pFile);
//char *pWriteData4 = "my_cat.DEBUG >stdout;my\n";
//fwrite(pWriteData4, 1, strlen(pWriteData4), pFile);
char szData[1000] = { 0 };
sprintf(szData, "my_cat.DEBUG \"%s\";my\n", szLogFilePathEx);
fwrite(szData, 1, strlen(szData), pFile);
fclose(pFile);
pFile = NULL;
}
rc = dzlog_init(szConfigPath, "my_cat");
if (rc) {
return false;
}
return true;
}
CManager::CManager()
{
InitLogFile();
// dzlog_init("test.conf", "my_cat");
m_zc = zlog_get_category("my_cat");
av_register_all();
avcodec_register_all();
InitVideoInput();
}
CManager::~CManager()
{
zlog_fini();
}
5、gbd调试
gdb a.out 调试允许程序
r 运行
b 可以接函数名或者cpp文件:行数 下断点
n 断点下一步
p 接变量名 可以查看变量的名称
wh 查看源码
bt 奔溃后查看堆栈调用
借鉴博客
https://blog.csdn.net/niyaozuozuihao/article/details/91802994
未解决问题:ffmpeg编译为静态库,制作动态库形式的双录程序,提示报错 recompile with -fPIC