VC++:simplest_ffmpeg_demos_compile_devenv_all.bat
CL.exe:simplest_ffmpeg_demos_compile_cl_all.bat
MinGW:simplest_ffmpeg_demos_compile_mingw_all.sh
GCC (Linux/MacOS):simplest_ffmpeg_demos_compile_gcc_all.sh
在记录具体的编译脚本之前,首先简单记录一下在不同平台下编译这些FFmpeg工程需要做的准备工作。
PS:一些示例程序需要安装SDL2,方法类似,不再记录。
VC++的编译是最简单的,相关的include和lib都已经配置好了,可以直接编译运行。
基本上等同于使用VC++编译,可以直接编译运行。
两种方法:直接安装和源代码编译
直接安装
(1)从FFmpeg Windows Build (http://ffmpeg.zeranoe.com/) 网站下载最新的shared 和dev版本的FFmpeg。
(2)在Msys安装目录下创建“local”文件夹,“local”文件夹下创建“include”和“lib”文件夹。
(3)将FFmpeg的dev版本下的include拷贝至{msys}/local/include;lib拷贝至{msys}/local/lib。
(4)将FFmpeg的shared版本下的Dll拷贝至{mingw}/bin。
源代码编译
(1)安装Yasm
从官网下载yasmXXX.exe,然后重命名为yasm.exe,拷贝至{mingw}/bin
PS:也可以下载源代码自己编译,稍微麻烦些,不再记录。
(2)编译安装SDL
从官网下载源代码,编译安装:
./configure make make install
PS:注意SDL的安装路径如果没有安装在{msys}/local目录下的话,configure的时候设置一下。
(3)编译安装libx264
从官网下载源代码,编译安装:
./configure --enable-shared make make install
(3)编译安装libfaac
从官网下载源代码,编译安装:
./configure --enable-shared make make install
(4)编译安装FFmpeg
./configure --enable-shared --enable-libfaac --enable-libx264 --enable-gpl --enable-nonfree make make install
(0)前期准备
某些Linux没有安装g++,需要先安装g++
进入超级管理员“su”
(1)安装相关的类库
[Debian/Ubuntu]
apt-get -y install yasm libfaac-dev libx264-dev libsdl1.2-dev
[RedHat/Fedora/CentOS]
yum -y install yasm libfaac-dev libx264-dev libsdl1.2-dev
PS:这些类库也可以下载源代码手动编译,稍微麻烦些,不再记录。
(2)编译安装FFmpeg
./configure --enable-shared --enable-libfaac --enable-libx264 --enable-gpl --enable-nonfree make make install
两种方法:直接安装和源代码编译
直接安装
(1)安装Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(2)安装FFmpeg
brew install ffmpeg
源代码编译
(1)安装Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(2)安装相关的类库
brew install yasm faac x264 sdl
(3)编译安装FFmpeg
进入超级管理员“su”
./configure --enable-shared --enable-libfaac --enable-libx264 --enable-gpl --enable-nonfree make make install
devenv.exe simplest_ffmpeg_player2.sln /rebuild Debug下面这条命令编译生成Release版本程序,同时将编译过程中的日志输出到“sf_player_release_ compile_log.txt”文件中:
devenv.exe simplest_ffmpeg_player2.sln /rebuild Release /Out sf_player_release_ compile_log.txt使用devenv进行编译的时候,需要VC++运行环境,有2种方法可以设置:
@echo off echo --------------------------------------------- echo simplest ffmpeg demos list ---- Devenv compile all echo Lei Xiaohua echo Communication University of China / Digital TV Technology echo leixiaohua1020@126.com echo http://blog.csdn.net/leixiaohua1020 echo --------------------------------------------- set logfile=compile_log.txt ::VS2010 Environment call "D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" ::===================================================================================== echo. echo Compile simplest_ffmpeg_player... cd simplest_ffmpeg_player devenv.exe simplest_ffmpeg_player2.sln /rebuild Debug /Out ../sf_player_debug_%logfile% devenv.exe simplest_ffmpeg_player2.sln /rebuild Release /Out ../sf_player_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_audio_player... cd simplest_ffmpeg_audio_player devenv.exe simplest_ffmpeg_audio_player2.sln /rebuild Debug /Out ../sf_audio_player_debug_%logfile% devenv.exe simplest_ffmpeg_audio_player2.sln /rebuild Release /Out ../sf_audio_player_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_picture_encoder... cd simplest_ffmpeg_picture_encoder devenv.exe simplest_ffmpeg_picture_encoder.sln /rebuild Debug /Out ../sf_picture_encoder_debug_%logfile% devenv.exe simplest_ffmpeg_picture_encoder.sln /rebuild Release /Out ../sf_picture_encoder_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_video_encoder... cd simplest_ffmpeg_video_encoder devenv.exe simplest_ffmpeg_video_encoder.sln /rebuild Debug /Out ../sf_video_encoder_debug_%logfile% devenv.exe simplest_ffmpeg_video_encoder.sln /rebuild Release /Out ../sf_video_encoder_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_audio_encoder... cd simplest_ffmpeg_audio_encoder devenv.exe simplest_ffmpeg_audio_encoder.sln /rebuild Debug /Out ../sf_audio_encoder_debug_%logfile% devenv.exe simplest_ffmpeg_audio_encoder.sln /rebuild Release /Out ../sf_audio_encoder_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_streamer... cd simplest_ffmpeg_streamer devenv.exe simplest_ffmpeg_streamer.sln /rebuild Debug /Out ../sf_streamer_debug_%logfile% devenv.exe simplest_ffmpeg_streamer.sln /rebuild Release /Out ../sf_streamer_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_mem_handler... cd simplest_ffmpeg_mem_handler devenv.exe simplest_ffmpeg_mem_handler.sln /rebuild Debug /Out ../sf_mem_handler_debug_%logfile% devenv.exe simplest_ffmpeg_mem_handler.sln /rebuild Release /Out ../sf_mem_handler_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_device... cd simplest_ffmpeg_device devenv.exe simplest_ffmpeg_device.sln /rebuild Debug /Out ../sf_device_debug_%logfile% devenv.exe simplest_ffmpeg_device.sln /rebuild Release /Out ../sf_device_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_format... cd simplest_ffmpeg_format devenv.exe simplest_ffmpeg_format.sln /rebuild Debug /Out ../sf_format_debug_%logfile% devenv.exe simplest_ffmpeg_format.sln /rebuild Release /Out ../sf_format_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_video_filter... cd simplest_ffmpeg_video_filter devenv.exe simplest_ffmpeg_video_filter.sln /rebuild Debug /Out ../sf_video_filter_debug_%logfile% devenv.exe simplest_ffmpeg_video_filter.sln /rebuild Release /Out ../sf_video_filter_release_%logfile% cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_swscale... cd simplest_ffmpeg_swscale devenv.exe simplest_ffmpeg_swscale.sln /rebuild Debug /Out ../sf_swscale_debug_%logfile% devenv.exe simplest_ffmpeg_swscale.sln /rebuild Release /Out ../sf_swscale_release_%logfile% cd .. ::=====================================================================================
cl.exe helloworld.cpp上述命令执行完后即可在同一目录下生成一个helloworld.exe的可执行程序。
::最简单的基于FFmpeg的视频播放器 2----命令行编译 ::Simplest FFmpeg Player 2----Compile in Cmd :: ::雷霄骅 Lei Xiaohua ::leixiaohua1020@126.com ::中国传媒大学/数字电视技术 ::Communication University of China / Digital TV Technology ::http://blog.csdn.net/leixiaohua1020 :: ::VS2010 Environment call "D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" ::include @set INCLUDE=include;%INCLUDE% ::lib @set LIB=lib;%LIB% ::compile and link cl simplest_ffmpeg_player.cpp /MD /link SDL2.lib SDL2main.lib avcodec.lib ^ avformat.lib avutil.lib avdevice.lib avfilter.lib postproc.lib swresample.lib swscale.lib ^ /SUBSYSTEM:WINDOWS /OPT:NOREF exit
a) 链接类库使用/link上述脚本运行完城后,生成simplest_ffmpeg_player.exe。
b) 使用SDL类库的时候,务必设置/MD选项(使用动态链接的库)
c) 使用SDL类库的时候,务必设置/SUBSYSTEM:WINDOWS
d) 使用FFmpeg类库的时候,务必设置/OPT:NOREF
@echo off echo --------------------------------------------- echo simplest ffmpeg demos list ---- CL compile all echo Lei Xiaohua echo Communication University of China / Digital TV Technology echo leixiaohua1020@126.com echo http://blog.csdn.net/leixiaohua1020 echo --------------------------------------------- ::===================================================================================== echo. echo Compile simplest_ffmpeg_player... cd simplest_ffmpeg_player cd simplest_ffmpeg_player start /wait compile_cl.bat cd .. cd simplest_ffmpeg_player_su start /wait compile_cl.bat cd .. cd simplest_ffmpeg_decoder_pure start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_audio_player... cd simplest_ffmpeg_audio_player cd simplest_ffmpeg_audio_player start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_picture_encoder... cd simplest_ffmpeg_picture_encoder cd simplest_ffmpeg_picture_encoder start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_video_encoder... cd simplest_ffmpeg_video_encoder cd simplest_ffmpeg_video_encoder start /wait compile_cl.bat cd .. cd simplest_ffmpeg_video_encoder_pure start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_audio_encoder... cd simplest_ffmpeg_audio_encoder cd simplest_ffmpeg_audio_encoder start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_streamer... cd simplest_ffmpeg_streamer cd simplest_ffmpeg_streamer start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_mem_handler... cd simplest_ffmpeg_mem_handler cd simplest_ffmpeg_mem_player start /wait compile_cl.bat cd .. cd simplest_ffmpeg_mem_transcoder start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_device... cd simplest_ffmpeg_device cd simplest_ffmpeg_grabdesktop start /wait compile_cl.bat cd .. cd simplest_ffmpeg_readcamera start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_format... cd simplest_ffmpeg_format cd simplest_ffmpeg_demuxer start /wait compile_cl.bat cd .. cd simplest_ffmpeg_demuxer_simple start /wait compile_cl.bat cd .. cd simplest_ffmpeg_muxer start /wait compile_cl.bat cd .. cd simplest_ffmpeg_remuxer start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_video_filter... cd simplest_ffmpeg_video_filter cd simplest_ffmpeg_video_filter start /wait compile_cl.bat cd .. cd .. ::===================================================================================== echo. echo Compile simplest_ffmpeg_swscale... cd simplest_ffmpeg_swscale cd simplest_ffmpeg_swscale start /wait compile_cl.bat cd .. cd simplest_pic_gen start /wait compile_cl.bat cd .. cd .. ::=====================================================================================
gcc helloworld.cpp -o helloworld.exe上述命令执行完后即可在同一目录下生成一个helloworld.exe的可执行程序。
#! /bin/sh #最简单的基于FFmpeg的视频播放器 2----MinGW命令行编译 #Simplest FFmpeg Player 2----Compile in MinGW # #雷霄骅 Lei Xiaohua #leixiaohua1020@126.com #中国传媒大学/数字电视技术 #Communication University of China / Digital TV Technology #http://blog.csdn.net/leixiaohua1020 # #compile g++ simplest_ffmpeg_player.cpp -g -o simplest_ffmpeg_player.exe -I /usr/local/include -L /usr/local/lib -lmingw32 -lSDL2main -lSDL2 -lavformat -lavcodec -lavutil -lswscale
echo "=============================================" echo "simplest ffmpeg demos list ---- MinGW compile all" echo "Lei Xiaohua" echo "Communication University of China / Digital TV Technology" echo "leixiaohua1020@126.com" echo "http://blog.csdn.net/leixiaohua1020" echo "=============================================" #===================================================================================== echo "" echo "Compile simplest_ffmpeg_player..." cd simplest_ffmpeg_player cd simplest_ffmpeg_player sh compile_mingw.sh cd .. cd simplest_ffmpeg_player_su sh compile_mingw.sh cd .. cd simplest_ffmpeg_decoder_pure sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_audio_player..." cd simplest_ffmpeg_audio_player cd simplest_ffmpeg_audio_player sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_picture_encoder..." cd simplest_ffmpeg_picture_encoder cd simplest_ffmpeg_picture_encoder sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_video_encoder..." cd simplest_ffmpeg_video_encoder cd simplest_ffmpeg_video_encoder sh compile_mingw.sh cd .. cd simplest_ffmpeg_video_encoder_pure sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_audio_encoder..." cd simplest_ffmpeg_audio_encoder cd simplest_ffmpeg_audio_encoder sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_streamer..." cd simplest_ffmpeg_streamer cd simplest_ffmpeg_streamer sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_mem_handler..." cd simplest_ffmpeg_mem_handler cd simplest_ffmpeg_mem_player sh compile_mingw.sh cd .. cd simplest_ffmpeg_mem_transcoder sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_device..." cd simplest_ffmpeg_device cd simplest_ffmpeg_grabdesktop sh compile_mingw.sh cd .. cd simplest_ffmpeg_readcamera sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_format..." cd simplest_ffmpeg_format cd simplest_ffmpeg_demuxer sh compile_mingw.sh cd .. cd simplest_ffmpeg_demuxer_simple sh compile_mingw.sh cd .. cd simplest_ffmpeg_muxer sh compile_mingw.sh cd .. cd simplest_ffmpeg_remuxer sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_video_filter..." cd simplest_ffmpeg_video_filter cd simplest_ffmpeg_video_filter sh compile_mingw.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_swscale..." cd simplest_ffmpeg_swscale cd simplest_ffmpeg_swscale sh compile_mingw.sh cd .. cd simplest_pic_gen sh compile_mingw.sh cd .. cd .. #=====================================================================================
gcc helloworld.cpp -o helloworld.out上述命令执行完后即可在同一目录下生成一个名称为helloworld.out的可执行程序。
#! /bin/sh #最简单的基于FFmpeg的视频播放器 2----命令行编译 #Simplest FFmpeg Player 2----Compile in Shell # #雷霄骅 Lei Xiaohua #leixiaohua1020@126.com #中国传媒大学/数字电视技术 #Communication University of China / Digital TV Technology #http://blog.csdn.net/leixiaohua1020 # #compile 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
gcc simplest_ffmpeg_grabdesktop.cpp -g -o simplest_ffmpeg_grabdesktop.out -framework Cocoa -I /usr/local/include -L /usr/local/lib -lSDLmain -lSDL -lavformat -lavcodec -lavutil -lavdevice -lswscale对于这些采用SDL1.2的程序,保存了一个MacOS下专有的脚本“compile_gcc_mac.sh”。
echo "=============================================" echo "simplest ffmpeg demos list ---- GCC compile all" echo "Lei Xiaohua" echo "Communication University of China / Digital TV Technology" echo "leixiaohua1020@126.com" echo "http://blog.csdn.net/leixiaohua1020" echo "=============================================" #===================================================================================== #OS kernel kernel=$(uname -s) #change the access permissions (--recursive) chmod -R 777 ./ echo "" echo "Compile simplest_ffmpeg_player..." cd simplest_ffmpeg_player cd simplest_ffmpeg_player sh compile_gcc.sh cd .. cd simplest_ffmpeg_player_su sh compile_gcc.sh cd .. cd simplest_ffmpeg_decoder_pure sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_audio_player..." cd simplest_ffmpeg_audio_player cd simplest_ffmpeg_audio_player sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_picture_encoder..." cd simplest_ffmpeg_picture_encoder cd simplest_ffmpeg_picture_encoder sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_video_encoder..." cd simplest_ffmpeg_video_encoder cd simplest_ffmpeg_video_encoder sh compile_gcc.sh cd .. cd simplest_ffmpeg_video_encoder_pure sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_audio_encoder..." cd simplest_ffmpeg_audio_encoder cd simplest_ffmpeg_audio_encoder sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_streamer..." cd simplest_ffmpeg_streamer cd simplest_ffmpeg_streamer sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_mem_handler..." cd simplest_ffmpeg_mem_handler cd simplest_ffmpeg_mem_player if [ "$kernel" == "Darwin" ];then sh compile_gcc_mac.sh else sh compile_gcc.sh fi cd .. cd simplest_ffmpeg_mem_transcoder sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_device..." cd simplest_ffmpeg_device cd simplest_ffmpeg_grabdesktop if [ "$kernel" == "Darwin" ];then sh compile_gcc_mac.sh else sh compile_gcc.sh fi cd .. cd simplest_ffmpeg_readcamera if [ "$kernel" == "Darwin" ];then sh compile_gcc_mac.sh else sh compile_gcc.sh fi cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_format..." cd simplest_ffmpeg_format cd simplest_ffmpeg_demuxer sh compile_gcc.sh cd .. cd simplest_ffmpeg_demuxer_simple sh compile_gcc.sh cd .. cd simplest_ffmpeg_muxer sh compile_gcc.sh cd .. cd simplest_ffmpeg_remuxer sh compile_gcc.sh cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_video_filter..." cd simplest_ffmpeg_video_filter cd simplest_ffmpeg_video_filter if [ "$kernel" == "Darwin" ];then sh compile_gcc_mac.sh else sh compile_gcc.sh fi cd .. cd .. #===================================================================================== echo "" echo "Compile simplest_ffmpeg_swscale..." cd simplest_ffmpeg_swscale cd simplest_ffmpeg_swscale sh compile_gcc.sh cd .. cd simplest_pic_gen sh compile_gcc.sh cd .. cd .. #=====================================================================================
原文地址:http://blog.csdn.net/leixiaohua1020/article/details/43898125