单独编译ffmpeg.c和ffplay.c的CMakeLists.txt, 方便调试

原创
2022/09/16 10:51
阅读数 566

1.ffmpeg依赖:

apt-get -y install wget git curl autoconf automake build-essential libass-dev libfreetype6-dev \
  libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
  libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev yasm libmp3lame-dev libopus-dev libsdl2-2.0 libsdl2-dev \
  nasm cmake libx264-dev mercurial

2.ffmpeg常用依赖源码:

# 下载,DL 是对wget的封装
			DL https://github.com/yasm/yasm/archive/refs/tags/v1.3.0.tar.gz \
	&& DL https://github.com/videolan/x265/archive/refs/tags/3.4.tar.gz \
	&& DL https://github.com/mstorsjo/fdk-aac/archive/refs/tags/v2.0.2.tar.gz \
	&& DL https://github.com/webmproject/libvpx/archive/v1.8.2.tar.gz \
	&& DL http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 \
	&& DL https://github.com/cisco/openh264/archive/refs/tags/v2.3.0.tar.gz \
	&& DL https://github.com/libsdl-org/SDL/archive/refs/tags/release-2.24.0.tar.gz 
# 解压
	find -name "*.tar.gz" -exec tar -xzvf {} \;
	find -name "*.tar.bz2" -exec tar -xjvf {} \;

3.编译带调试信息的依赖源码, 安装到 ../ffmpeg_build

ROOT=$PWD
	pushd yasm-1.3.0 \
	&& ./autogen.sh \
	&& CFLAGS="-g -fPIC" ./configure --prefix="$ROOT/../ffmpeg_build" --bindir="$ROOT/../bin" \
	&& make -j$(cat /proc/cpuinfo | grep processor | wc -l) \
	&& make install \
	&& popd \
	&& hg --version \
	&& pushd x265-3.4/build/linux \
	&& PATH="$ROOT/../bin:$PATH" cmake -DCMAKE_C_FLAGS="-g -fPIC" -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$ROOT/../ffmpeg_build" -DENABLE_SHARED:bool=off ../../source \
	&& make -j$(cat /proc/cpuinfo | grep processor | wc -l) \
	&& make install \
	&& popd \
	&& pushd fdk-aac-2.0.2 \
	&& autoreconf -fiv \
	&& CFLAGS="-g -fPIC" ./configure --prefix="$ROOT/../ffmpeg_build" --disable-shared \
	&& make -j$(cat /proc/cpuinfo | grep processor | wc -l) \
	&& make install \
	&& make distclean \
	&& popd \
	&& pushd libvpx-1.8.2 \
	&& PATH="$ROOT/../bin:$PATH" CFLAGS="-g -fPIC" ./configure --prefix="$ROOT/../ffmpeg_build" --disable-examples --disable-unit-tests \
	&& PATH="$ROOT/../bin:$PATH" make -j$(cat /proc/cpuinfo | grep processor | wc -l) \
	&& make install \
	&& popd \
	&& pushd openh264-2.3.0 \
	&& CFLAGS="-g -fPIC" make OS=linux ARCH=$(uname -m) \
	&& make install \
	&& popd \
	&& pushd SDL-release-2.24.0 \
	&& CFLAGS="-g -fPIC" ./configure --prefix="$ROOT/../ffmpeg_build" \
	&& make \
	&& make install \
	&& popd

4.编译ffmpeg和相关lib库, ffmpeg安装到./bin, lib安装到../ffmpeg_build

#install ffmpeg
ROOT=$(dirname $0) && \
cd $ROOT
pushd ffmpeg \
&& PATH="$ROOT/bin:$PATH" CONFIG_FFPLAY=yes PKG_CONFIG_PATH="$ROOT/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$ROOT/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-libs=-static \
  --extra-cflags="--static -I$ROOT/ffmpeg_build/include -fPIC" \
  --extra-ldflags="-L$ROOT/ffmpeg_build/lib" \
  --extra-libs="-lpthread -lm -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor " \
  --bindir="$ROOT/bin" \
  --enable-gpl \
  --enable-debug \
  --enable-sdl2 \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-libopenh264 \
  --enable-nonfree \
  --disable-doc \
  --disable-htmlpages \
  --disable-manpages \
  --disable-podpages \
  --disable-txtpages \
&& PATH="$ROOT/bin:$PATH" make VERBOSE=1 -j$(cat /proc/cpuinfo | grep processor | wc -l) \
&& make install \
&& hash -r \
&& popd

5.在ffmpeg目录下创建cmake/CMakeLists.txt

project(ffmpeg)

cmake_minimum_required(VERSION 3.0)

add_compile_options("-g" "-no-pie")

include_directories(.. ../../ffmpeg_build/include ../../ffmpeg_build/include)
link_directories(../../ffmpeg_build/lib)

# find_library(FINDLIB libfdk-aac.a ../../ffmpeg_build/lib ENV)
# message("FINDLIB " ${FINDLIB})

# ffplay
add_executable(ffplay ../fftools/ffplay ../fftools/cmdutils ../fftools/opt_common ../libavcodec/avdct ../libavfilter/graphdump)
target_link_libraries(ffplay "-no-pie" avformat avcodec avfilter postproc avutil avdevice swresample swscale openh264
	SDL2 vorbis vorbisenc xcb xcb-shape xcb-xfixes xcb-shm freetype x264 x265 vpx opus fdk-aac theora theoraenc theoradec mp3lame
	stdc++ dl m z pthread)

# ffmpeg
file(GLOB FFMPEG_FILES RELATIVE ${PROJECT_SOURCE_DIR} ../fftools/*.c)
list(REMOVE_ITEM FFMPEG_FILES ../fftools/ffplay.c ../fftools/ffprobe.c)
message("FFMPEG_FILES=" ${FFMPEG_FILES})
add_executable(ffmpeg ${FFMPEG_FILES} ../libavfilter/graphdump ../libavdevice/lavfi ../libavcodec/avfft 
	../libavcodec/avdct)
target_link_libraries(ffmpeg "-no-pie" avformat avcodec avfilter postproc avutil avdevice swresample swscale openh264
	SDL2 vorbis vorbisenc xcb xcb-shape xcb-xfixes xcb-shm freetype x264 x265 vpx opus fdk-aac theora theoraenc theoradec mp3lame
	stdc++ dl m z pthread)
	

6.调试: 修改源码后需要重新编译对应的源码, 然后通过CMakeLists.txt文件选择目标调试

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部