QT编译FFmpeg源程序方法

背景

由于FFmpeg提供了几个命令行工具(最常用的三剑客:ffmpeg,ffplay,ffprobe)来提供给其他程序调用来实现快速开发,但这些进程只能满足一般的项目需求,有时侯,为了实现一些特色功能,又不想另写模块来实现,这时,一个好的实践是修改这些工具的源文件,比如ffmpeg.c。然后重新编译生成自已的工具进程来给其他模块来使用。下面就以最常用的ffmpeg来说明如何在Ubuntu18.04环境下使用Qt5.12.3的Qt Creator来对ffmpeg-4.1中的fftools/ffmpeg.c进行编译、调试、和生成app。

编译和安装ffmpeg-4.1

这个我之前的博客有写,网上也能找到很多。

创建CMakeLists.txt

为了方便,我直接在ffmpeg-4.1目录下创建”CMakeLists.txt”,内容如下: 这个是实际编译通过并正常进入调试模式的设置。网上很难找到。

cmake_minimum_required(VERSION 3.0.0)
project(qzmffmpeg VERSION 0.1) #compile .c pass.

set(CMAKE_C_STANDARD)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# src ========================================
set(SRCS
    ${PROJECT_SOURCE_DIR}/fftools/ffmpeg.c
    ${PROJECT_SOURCE_DIR}/fftools/ffmpeg_opt.c
    ${PROJECT_SOURCE_DIR}/fftools/ffmpeg_filter.c
    ${PROJECT_SOURCE_DIR}/fftools/ffmpeg_hw.c
    ${PROJECT_SOURCE_DIR}/fftools/cmdutils.c
)

add_executable(${PROJECT_NAME}
    #${DIR_SRCS_CURRENT}
    ${SRCS}
)

target_link_libraries(${PROJECT_NAME} -lavcodec)
target_link_libraries(${PROJECT_NAME} -lavdevice)
target_link_libraries(${PROJECT_NAME} -lavfilter)
target_link_libraries(${PROJECT_NAME} -lavformat)
target_link_libraries(${PROJECT_NAME} -lavutil)
target_link_libraries(${PROJECT_NAME} -lpostproc)
target_link_libraries(${PROJECT_NAME} -lswresample)
target_link_libraries(${PROJECT_NAME} -lswscale)
target_link_libraries(${PROJECT_NAME} -lm) 
target_link_libraries(${PROJECT_NAME} -lpthread)

使用Qt Creator建立一个PRJ来编译ffmpeg.c

把用Qt Creator加载CMakeLists.txt作为一个项目,先运行”Run CMake”,再运行“Build Project “qzmffmpeg”。如下图所示:

Build的Compile Output信息如下:

16:29:47: Running steps for project qzmffmpeg...
16:29:47: Starting: "/usr/local/bin/cmake" --build . --target clean
16:29:47: The process "/usr/local/bin/cmake" exited normally.
16:29:47: Starting: "/usr/local/bin/cmake" --build . --target all
[ 50%] Building C object CMakeFiles/qzmffmpeg.dir/fftools/ffmpeg.c.o
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c: In function ‘do_streamcopy’:
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:2080:5: warning: ‘av_copy_packet_side_data’ is deprecated [-Wdeprecated-declarations]
     av_copy_packet_side_data(&opkt, pkt);
     ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/xhj/qzm/ffmpeg-4.1/libavformat/avformat.h:319:0,
                 from /home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:43:
/home/xhj/qzm/ffmpeg-4.1/libavcodec/avcodec.h:4406:5: note: declared here
 int av_copy_packet_side_data(AVPacket *dst, const AVPacket *src);
     ^~~~~~~~~~~~~~~~~~~~~~~~
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c: In function ‘init_output_stream’:
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:3549:9: warning: ‘avcodec_copy_context’ is deprecated [-Wdeprecated-declarations]
         ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx);
         ^~~
In file included from /home/xhj/qzm/ffmpeg-4.1/libavformat/avformat.h:319:0,
                 from /home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:43:
/home/xhj/qzm/ffmpeg-4.1/libavcodec/avcodec.h:4178:5: note: declared here
 int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
     ^~~~~~~~~~~~~~~~~~~~
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:3549:9: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
         ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx);
         ^~~
In file included from /home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:43:0:
/home/xhj/qzm/ffmpeg-4.1/libavformat/avformat.h:878:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:3595:9: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
         ost->st->codec->codec= ost->enc_ctx->codec;
         ^~~
In file included from /home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:43:0:
/home/xhj/qzm/ffmpeg-4.1/libavformat/avformat.h:878:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c: In function ‘check_keyboard_interaction’:
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:3976:13: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
             debug = input_streams[0]->st->codec->debug<<1;
             ^~~~~
In file included from /home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:43:0:
/home/xhj/qzm/ffmpeg-4.1/libavformat/avformat.h:878:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:3999:13: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
             input_streams[i]->st->codec->debug = debug;
             ^~~~~~~~~~~~~
In file included from /home/xhj/qzm/ffmpeg-4.1/fftools/ffmpeg.c:43:0:
/home/xhj/qzm/ffmpeg-4.1/libavformat/avformat.h:878:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
[100%] Linking C executable qzmffmpeg
[100%] Built target qzmffmpeg
16:29:48: The process "/usr/local/bin/cmake" exited normally.
16:29:48: Elapsed time: 00:01.

使用Qt Creator来调试和生成ffmpeg进程

经过上面的CMake和Build后,即可开始调试ffmpeg.c,如下图所示:

然后,我们就可以改写ffmpeg.c,加入我们的功能进去,并调试通过后,生成release的ffmpeg模块来使用。

转载
原文链接:https://blog.csdn.net/u012915636/article/details/90208644


文章作者: YUV420.COM
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 YUV420.COM !
评论
 上一篇
网站备案相关问题汇总 网站备案相关问题汇总
网站必须备案吗 国内空间必须备案。 国外空间不需要备案。 国内空间商如阿里云提供的香港,美国机房不需要备案。 备案对网站运营收录有哪些影响 百度对备案网站优先收录 百度联盟等广告联盟必须要备案信息 不备案不能从事经营性工作。 北京地区备
2020-01-09
下一篇 
基于油猴的Chrome插件网盘助手提供直接下载链接和VIP不限速破解 基于油猴的Chrome插件网盘助手提供直接下载链接和VIP不限速破解
背景百度网盘保存文件后,用浏览器下载里面的文件,总是提示安装客户端,烦人至极,同时客户端非会员限速 解决方案Chrome商店搜索【网盘助手】关键字,或者到该地址安装网盘助手脚本插件. http://pan.newday.me/ 功能自动生成
2020-01-08
  目录