1. Ubuntu 16.04 (gcc/g++ 7.1)
2. FFmpeg-2.8.15 (http://ffmpeg.org/download.html#releases)
3. SDL-2.0.10 (http://www.libsdl.org/download-2.0.php)
4. simplest_ffmpeg_player (https://github.com/leixiaohua1020/simplest_ffmpeg_player)
1. 解压 FFmpeg 的压缩包(如 ffmpeg-2.8.15.tar.gz)到当前目录,然后通过终端进入该目录,并编译、安装:
cd ./ffmpeg-2.8.15
./configure --disable-yasm #此处选项为yasm报错
make
sudo make install
2. 解压 SDL 的压缩包(如 SDL2-2.0.10.tar.gz)到当前目录,然后通过终端进入该目录,并编译、安装:
cd ./SDL2-2.0.10
./configure
make
sudo make install
解压simplest_ffmpeg_player的压缩包(如 simplest_ffmpeg_player_2.5.zip),然后通过终端进入子目录simplest_ffmpeg_player,并编译:
cd ./simplest_ffmpeg_player_2.5
cd ./simplest_ffmpeg_player
g++ simplest_ffmpeg_player.cpp -g -o simplest_ffmpeg_player.out -I /usr/local/include/ -L /usr/local/lib -lSDL2main -lSDL2 - lavcodec -lavutil -lswscale -pthread -lz -lm -lbz2 -lswresample
因环境配置原因,原本的simplest_ffmpeg_player中的gcc编译命令(complile_gcc.sh)
#! /bin/sh
gcc simplest_ffmpeg_player.cpp -g -o simplest_ffmpeg_player.out \
-I /usr/local/include -L /usr/local/lib -lSDL2main -lSDL2 -lavformat -lavcodec -lavutil -lswscale
会报错。
具体报错如下形式:
1. 缺少 -pthread:
/usr/bin/ld: /usr/local/lib/libavformat.a(udp.o): undefined reference to symbol 'pthread_cancel@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
2. 缺少 -lz:
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/rtmpproto.c:1077: undefined reference to `inflateInit_'
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/rtmpproto.c:1087: undefined reference to `inflate'
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/rtmpproto.c:1105: undefined reference to `inflateEnd'
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/rtmpproto.c:1105: undefined reference to `inflateEnd'
3. 缺少 -lbz2:
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/matroskadec.c:1325: undefined reference to `BZ2_bzDecompressInit'
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/matroskadec.c:1340: undefined reference to `BZ2_bzDecompress'
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/matroskadec.c:1333: undefined reference to `BZ2_bzDecompressEnd'
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavformat/matroskadec.c:1343: undefined reference to `BZ2_bzDecompressEnd'
4. 缺少 -lswresample:
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_subpacket':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:379: undefined reference to `swr_is_initialized'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_frame':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:220: undefined reference to `swr_is_initialized'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_init_resample':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:161: undefined reference to `swr_init'
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:167: undefined reference to `swr_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_frame':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:234: undefined reference to `swr_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_flush_resample':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:115: undefined reference to `swr_convert'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_subpacket':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:411: undefined reference to `swr_close'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_flush':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:614: undefined reference to `swr_close'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_close':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:638: undefined reference to `swr_free'
/usr/local/lib/libavcodec.a(opusdec.o): In function `opus_decode_init':
/home/ecc/Documents/ffmpeg/ffmpeg-2.8.15/libavcodec/opusdec.c:705: undefined reference to `swr_alloc'
https://blog.csdn.net/leixiaohua1020/article/details/38868499