日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

FFmpeg示例程序合集-批量编译脚本

發(fā)布時(shí)間:2023/12/13 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FFmpeg示例程序合集-批量编译脚本 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
此前做了一系列有關(guān)FFmpeg的示例程序,組成了《 最簡(jiǎn)單的FFmpeg示例程序合集》,其中包含了如下項(xiàng)目:
simplest ffmpeg player: ? ? ? ? ? ? ? ? ?最簡(jiǎn)單的基于FFmpeg的視頻播放器
simplest ffmpeg audio player: ? ? ? 最簡(jiǎn)單的基于FFmpeg的音頻播放器
simplest ffmpeg pic encoder: ? ? ? ?最簡(jiǎn)單的基于FFmpeg的圖像編碼器
simplest ffmpeg video encoder: ? ?最簡(jiǎn)單的基于FFmpeg的視頻編碼器
simplest ffmpeg audio encoder: ? 最簡(jiǎn)單的基于FFmpeg的音頻編碼器
simplest ffmpeg streamer: ? ? ? ? ? ? 最簡(jiǎn)單的基于FFmpeg的推流器(推送RTMP)
simplest ffmpeg mem handler: ? ? 最簡(jiǎn)單的基于FFmpeg的內(nèi)存讀寫例子
simplest ffmpeg device: ? ? ? ? ? ? ? ? 最簡(jiǎn)單的基于FFmpeg的AVDevice例子
simplest ffmpeg format: ? ? ? ? ? ? ? ? 最簡(jiǎn)單的基于FFmpeg的封裝格式方面的例子
simplest ffmpeg video filter: ? ? ? ? ?最簡(jiǎn)單的基于FFmpeg的AVfilter例子(水印疊加)
simplest ffmpeg swscale: ? ? ? ? ? ? 最簡(jiǎn)單的基于FFmpeg的libswscale的示例
?
開(kāi)始的時(shí)候,我只是在VC2010下調(diào)試通過(guò)了這些程序。去年就有不少朋友跟我提建議希望能把代碼改成跨平臺(tái)的。后來(lái)我調(diào)查了一下也發(fā)現(xiàn)FFmpeg確實(shí)在各個(gè)平臺(tái)都有廣泛的應(yīng)用,因此也產(chǎn)生了把代碼改成跨平臺(tái)的意愿。但是改成跨平臺(tái)代碼的工作量比較大,所以一直也沒(méi)有做出實(shí)際行動(dòng)。今年春節(jié)前夕可算是得到了一陣相對(duì)自由的時(shí)間,于是果斷進(jìn)行了一陣子“連續(xù)戰(zhàn)斗”,終于實(shí)現(xiàn)了這些工程在VC++,cl.exe,MinGW,Linux GCC以及MacOS GCC上面順利的編譯。在這個(gè)過(guò)程中,也寫了各種編譯器的編譯腳本,在這里記錄一下。
本文記錄以下幾種編譯腳本:
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

? ? ? ???? ? ? ? ? ? ?? ? ? ? ? ?

下載地址:
【Github】 https://github.com/leixiaohua1020/leixiaohua1020.github.io/tree/master/batch

?

準(zhǔn)備工作

在記錄具體的編譯腳本之前,首先簡(jiǎn)單記錄一下在不同平臺(tái)下編譯這些FFmpeg工程需要做的準(zhǔn)備工作。注意這一步驟針對(duì)的是一臺(tái)完全空白未做任何配置的“裸機(jī)”。如果已經(jīng)編譯安裝過(guò)FFmpeg,就可以直接跳過(guò)這一步驟。

PS:一些示例程序需要安裝SDL2,方法類似,不再記錄。

VC++

VC++的編譯是最簡(jiǎn)單的,相關(guān)的include和lib都已經(jīng)配置好了,可以直接編譯運(yùn)行。

CL.exe

基本上等同于使用VC++編譯,可以直接編譯運(yùn)行。

MinGW

兩種方法:直接安裝和源代碼編譯

直接安裝

(1)從FFmpeg Windows Build (http://ffmpeg.zeranoe.com/) 網(wǎng)站下載最新的shared 和dev版本的FFmpeg。

(2)在Msys安裝目錄下創(chuàng)建“l(fā)ocal”文件夾,“l(fā)ocal”文件夾下創(chuàng)建“include”和“l(fā)ib”文件夾。

(3)將FFmpeg的dev版本下的include拷貝至{msys}/local/include;lib拷貝至{msys}/local/lib。

(4)將FFmpeg的shared版本下的Dll拷貝至{mingw}/bin。

源代碼編譯

(1)安裝Yasm

從官網(wǎng)下載yasmXXX.exe,然后重命名為yasm.exe,拷貝至{mingw}/bin

PS:也可以下載源代碼自己編譯,稍微麻煩些,不再記錄。

(2)編譯安裝SDL

PS:注意SDL的安裝路徑如果沒(méi)有安裝在{msys}/local目錄下的話,configure的時(shí)候設(shè)置一下。

(3)編譯安裝libx264

(3)編譯安裝libfaac

(4)編譯安裝FFmpeg

[plain] view plaincopy
  • ./configure?--enable-shared?--enable-libfaac?--enable-libx264?--enable-gpl?--enable-nonfree??
  • make??
  • make?install??

  • Linux

    (0)前期準(zhǔn)備

    某些Linux沒(méi)有安裝gcc/g++,需要先安裝gcc/g++

    進(jìn)入超級(jí)管理員“su”

    (1)安裝相關(guān)的類庫(kù)

    [Debian/Ubuntu]

    [plain] view plaincopy
  • apt-get?-y?install?yasm?libfaac-dev?libx264-dev?libsdl1.2-dev??
  • PS:這些類庫(kù)也可以下載源代碼手動(dòng)編譯,稍微麻煩些,不再記錄。

    [RedHat/Fedora/CentOS]

    需要手動(dòng)編譯每個(gè)類庫(kù)

    (2)編譯安裝FFmpeg

    [plain] view plaincopy
  • ./configure?--enable-shared?--enable-libfaac?--enable-libx264?--enable-gpl?--enable-nonfree??
  • make??
  • make?install??

  • MacOS

    兩種方法:直接安裝和源代碼編譯

    直接安裝

    (1)安裝Homebrew

    [plain] view plaincopy
  • ruby?-e?"$(curl?-fsSL?https://raw.githubusercontent.com/Homebrew/install/master/install)"??
  • (2)安裝FFmpeg

    [plain] view plaincopy
  • brew?install?ffmpeg??

  • 源代碼編譯

    (1)安裝Homebrew

    [plain] view plaincopy
  • ruby?-e?"$(curl?-fsSL?https://raw.githubusercontent.com/Homebrew/install/master/install)"??
  • (2)安裝相關(guān)的類庫(kù)

    [plain] view plaincopy
  • brew?install?yasm?faac?x264?sdl??
  • (3)編譯安裝FFmpeg

    進(jìn)入超級(jí)管理員“su”

    [plain] view plaincopy
  • ./configure?--enable-shared?--enable-libfaac?--enable-libx264?--enable-gpl?--enable-nonfree??
  • make??
  • make?install??

  • VC++



    使用devenv.exe進(jìn)行編譯是最簡(jiǎn)單的一種命令行編譯方式。這種編譯方式和使用VC++代開(kāi)*.sln解決方案文件然后單擊“編譯”按鈕的效果是一樣的。由于項(xiàng)目解決方案中已經(jīng)做過(guò)了include,lib以及相關(guān)選項(xiàng)的設(shè)置,所以不需要做各種參數(shù)的配置。下面這條命令編譯Debug版本程序:
    [plain] view plaincopy
  • devenv.exe?simplest_ffmpeg_player2.sln?/rebuild?Debug??
  • 下面這條命令編譯生成Release版本程序,同時(shí)將編譯過(guò)程中的日志輸出到“sf_player_release_ compile_log.txt”文件中:
    [plain] view plaincopy
  • devenv.exe?simplest_ffmpeg_player2.sln?/rebuild?Release?/Out?sf_player_release_?compile_log.txt??
  • 使用devenv進(jìn)行編譯的時(shí)候,需要VC++運(yùn)行環(huán)境,有2種方法可以設(shè)置:
    (1) ? ? ? 批處理調(diào)用VC++設(shè)置環(huán)境的腳本,例如對(duì)于VC2010來(lái)說(shuō),位于“D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat”
    (2) ? ? ? 在“Visual Studio 命令提示符”中運(yùn)行批處理(或者編譯命令)。“Visual Studio 命令提示符”位于伴隨著VC++安裝,位于“Visual Studio Tools”目錄下。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_devenv_all.bat如下所示。將腳本拷貝至《最簡(jiǎn)單的FFmpeg示例程序合集》所在目錄運(yùn)行,就可以編譯所有項(xiàng)目的Release版本和Debug版本,并且輸出相關(guān)的編譯日志。
    ?
    [plain] view plaincopy
  • @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



    cl.exe 是Microsoft C/C++編譯器,和GCC屬于同一個(gè)層面的東西。一個(gè)基本的調(diào)用cl.exe編譯的命令行如下所示:
    [plain] view plaincopy
  • cl.exe?helloworld.cpp??
  • 上述命令執(zhí)行完后即可在同一目錄下生成一個(gè)helloworld.exe的可執(zhí)行程序。
    編譯包含類庫(kù)的程序相對(duì)來(lái)說(shuō)要復(fù)雜一些,下面以Simplest FFmpeg Player為例看一下它的編譯腳本。Simplest FFmpeg Player使用CL.exe編譯的腳本保存在“compile_cl.bat”文件中,如下所示。
    [plain] view plaincopy
  • ::最簡(jiǎn)單的基于FFmpeg的視頻播放器?2----命令行編譯??
  • ::Simplest?FFmpeg?Player?2----Compile?in?Cmd??
  • ::??
  • ::雷霄驊?Lei?Xiaohua??
  • ::leixiaohua1020@126.com??
  • ::中國(guó)傳媒大學(xué)/數(shù)字電視技術(shù)??
  • ::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??

  • 這個(gè)腳本按照順序做了以下幾點(diǎn)工作:
    (1)設(shè)置VC++運(yùn)行環(huán)境。這一步通過(guò)call "D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"實(shí)現(xiàn)。
    (2)設(shè)置include目錄。這一步設(shè)置FFmpeg以及SDL2的頭文件所在的目錄,通過(guò)修改include環(huán)境變量實(shí)現(xiàn)(在include環(huán)境變量前面加上項(xiàng)目文件夾中的“include”目錄)。
    (3)設(shè)置lib目錄。這一步設(shè)置FFmpeg以及SDL2的庫(kù)文件所在的目錄,通過(guò)修改lib環(huán)境變量實(shí)現(xiàn)(在lib環(huán)境變量前面加上項(xiàng)目文件夾中的“l(fā)ib”目錄)。
    (4) 編譯和鏈接。這一步用于將simplest_ffmpeg_player.cpp編譯生成simplest_ffmpeg_player.exe。在這里需要注意幾點(diǎn):
    a) 鏈接類庫(kù)使用/link
    b) 使用SDL類庫(kù)的時(shí)候,務(wù)必設(shè)置/MD選項(xiàng)(使用動(dòng)態(tài)鏈接的庫(kù))
    c) ?使用SDL類庫(kù)的時(shí)候,務(wù)必設(shè)置/SUBSYSTEM:WINDOWS
    d) ?使用FFmpeg類庫(kù)的時(shí)候,務(wù)必設(shè)置/OPT:NOREF 上述腳本運(yùn)行完城后,生成simplest_ffmpeg_player.exe。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_cl_all.bat如下所示。將腳本拷貝至《最簡(jiǎn)單的FFmpeg示例程序合集》所在目錄運(yùn)行,就可以編譯所有的示例程序。注意這個(gè)腳本只是分別調(diào)用了各個(gè)程序目錄下的compile_cl.bat文件。
    ?
    [plain] view plaincopy
  • @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?..??
  • ???
  • ::=====================================================================================??


  • ?

    MinGW



    MinGW是Windows下的GCC/G++編譯器。使用MinGW編譯需要運(yùn)行其安裝目錄下的msys.bat設(shè)置其環(huán)境變量。一個(gè)基本的調(diào)用MinGW gcc編譯的命令行如下所示:
    [plain] view plaincopy
  • gcc?helloworld.cpp?-o?helloworld.exe??
  • 上述命令執(zhí)行完后即可在同一目錄下生成一個(gè)helloworld.exe的可執(zhí)行程序。
    編譯包含類庫(kù)的程序相對(duì)來(lái)說(shuō)要復(fù)雜一些,下面以Simplest FFmpeg Player為例看一下它的編譯腳本。Simplest FFmpeg Player使用MinGW GCC編譯的腳本保存在“compile_mingw.sh”文件中,如下所示。
    [plain] view plaincopy
  • #!?/bin/sh??
  • #最簡(jiǎn)單的基于FFmpeg的視頻播放器?2----MinGW命令行編譯??
  • #Simplest?FFmpeg?Player?2----Compile?in?MinGW??
  • #??
  • #雷霄驊?Lei?Xiaohua??
  • #leixiaohua1020@126.com??
  • #中國(guó)傳媒大學(xué)/數(shù)字電視技術(shù)??
  • #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??
  • ?
    這個(gè)腳本使用MinGW中的g++完成編譯。在這里要注意一點(diǎn),并不是gcc只能編譯c代碼,g++只能編譯c++代碼,而是gcc和g++都可以編譯C和C++代碼。源代碼文件后綴為.c的,gcc把它當(dāng)作是C程序,而g++當(dāng)作是c++程序;后綴為.cpp的,兩者都會(huì)認(rèn)為是c++程序。上述編譯命令有以下幾點(diǎn)需要注意:
    (a) ?include目錄設(shè)置為/usr/local/include,要確保SDL2和FFmpeg的頭文件都安裝在這個(gè)目錄里(SDL2有可能沒(méi)有安裝在這里)
    (b) ?lib目錄設(shè)置為/usr/local/lib,要確保SDL2和FFmpeg的庫(kù)文件都安裝在這個(gè)目錄里(SDL2有可能沒(méi)有安裝在這里)
    (c) ?使用SDL類庫(kù)的時(shí)候,務(wù)必鏈接-lmingw32
    上述腳本運(yùn)行完城后,生成simplest_ffmpeg_player.exe。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_mingw_all.sh如下所示。將腳本拷貝至《最簡(jiǎn)單的FFmpeg示例程序合集》所在目錄運(yùn)行,就可以編譯所有的示例程序。注意這個(gè)腳本只是分別調(diào)用了各個(gè)程序目錄下的compile_mingw.sh文件。
    ?
    [plain] view plaincopy
  • 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 (Linux/MacOS)


    ? ? ? ??? ? ? ??

    GCC是Linux/MacOS下的C/C++編譯器。在Linux/MacOS下可以使用GCC編譯C/C++程序,一個(gè)簡(jiǎn)單的GCC編譯命令:
    [plain] view plaincopy
  • gcc?helloworld.cpp?-o?helloworld.out??
  • 上述命令執(zhí)行完后即可在同一目錄下生成一個(gè)名稱為helloworld.out的可執(zhí)行程序。
    編譯包含類庫(kù)的程序相對(duì)來(lái)說(shuō)要復(fù)雜一些,下面以Simplest FFmpeg Player為例看一下它的編譯腳本。Simplest FFmpeg Player使用GCC編譯的腳本保存在“compile_gcc.sh”文件中,如下所示。
    [plain] view plaincopy
  • #!?/bin/sh??
  • #最簡(jiǎn)單的基于FFmpeg的視頻播放器?2----命令行編譯??
  • #Simplest?FFmpeg?Player?2----Compile?in?Shell??
  • #??
  • #雷霄驊?Lei?Xiaohua??
  • #leixiaohua1020@126.com??
  • #中國(guó)傳媒大學(xué)/數(shù)字電視技術(shù)??
  • #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??
  • ?
    這個(gè)腳本使用gcc完成編譯。上文中已經(jīng)提到過(guò)一次,并不是gcc只能編譯c代碼,g++只能編譯c++代碼,而是gcc和g++都可以編譯C和C++代碼。源代碼文件后綴為.c的,gcc把它當(dāng)作是C程序,而g++當(dāng)作是c++程序;后綴為.cpp的,兩者都會(huì)認(rèn)為是c++程序。上述編譯命令有以下幾點(diǎn)需要注意:
    (a) ?include目錄設(shè)置為/usr/local/include,要確保SDL2和FFmpeg的頭文件都安裝在這個(gè)目錄里
    (b) ?lib目錄設(shè)置為/usr/local/lib,要確保SDL2和FFmpeg的庫(kù)文件都安裝在這個(gè)目錄里
    (c) ?有些版本中的Linux可能沒(méi)有安裝gcc/g++編譯器,需要先裝好這兩個(gè)編譯器
    上述腳本運(yùn)行完城后,生成simplest_ffmpeg_player.out。
    ?

    注意事項(xiàng):Linux和MacOS的不同

    Linux和MacOS在SDL1.2的使用上有很大的不同。在MacOS下使用SDL1.2必須加上“-framework Cocoa”參數(shù),否則編譯會(huì)出現(xiàn)錯(cuò)誤。因此在MacOS下編譯使用SDL1.2的程序的時(shí)候,編譯命令如下所示(以simplest_ffmpeg_grabdesktop為例,該程序采用了SDL1.2)。
    [plain] view plaincopy
  • 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??
  • 對(duì)于這些采用SDL1.2的程序,保存了一個(gè)MacOS下專有的腳本“compile_gcc_mac.sh”。
    此外,Linux和MacOS在顯示上也有較大的不同。此前發(fā)現(xiàn)Windows和MacOS下可以正常顯示的程序在Ubuntu下卻會(huì)出現(xiàn)“綠屏”現(xiàn)象。不過(guò)隨著代碼的調(diào)整這一情況已經(jīng)被消除了。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_gcc_all.sh如下所示。將腳本拷貝至《最簡(jiǎn)單的FFmpeg示例程序合集》所在目錄運(yùn)行,就可以編譯所有的示例程序。注意這個(gè)腳本只是分別調(diào)用了各個(gè)程序目錄下的compile_gcc.sh文件。
    [plain] view plaincopy
  • 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?..??
  • ??
  • #=====================================================================================?
  • 總結(jié)

    以上是生活随笔為你收集整理的FFmpeg示例程序合集-批量编译脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。