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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

?

準備工作

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

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

VC++

VC++的編譯是最簡單的,相關的include和lib都已經配置好了,可以直接編譯運行。

CL.exe

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

MinGW

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

直接安裝

(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

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

(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)前期準備

    某些Linux沒有安裝gcc/g++,需要先安裝gcc/g++

    進入超級管理員“su”

    (1)安裝相關的類庫

    [Debian/Ubuntu]

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

    [RedHat/Fedora/CentOS]

    需要手動編譯每個類庫

    (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)安裝相關的類庫

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

    進入超級管理員“su”

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

  • VC++



    使用devenv.exe進行編譯是最簡單的一種命令行編譯方式。這種編譯方式和使用VC++代開*.sln解決方案文件然后單擊“編譯”按鈕的效果是一樣的。由于項目解決方案中已經做過了include,lib以及相關選項的設置,所以不需要做各種參數的配置。下面這條命令編譯Debug版本程序:
    [plain] view plaincopy
  • devenv.exe?simplest_ffmpeg_player2.sln?/rebuild?Debug??
  • 下面這條命令編譯生成Release版本程序,同時將編譯過程中的日志輸出到“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進行編譯的時候,需要VC++運行環境,有2種方法可以設置:
    (1) ? ? ? 批處理調用VC++設置環境的腳本,例如對于VC2010來說,位于“D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat”
    (2) ? ? ? 在“Visual Studio 命令提示符”中運行批處理(或者編譯命令)。“Visual Studio 命令提示符”位于伴隨著VC++安裝,位于“Visual Studio Tools”目錄下。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_devenv_all.bat如下所示。將腳本拷貝至《最簡單的FFmpeg示例程序合集》所在目錄運行,就可以編譯所有項目的Release版本和Debug版本,并且輸出相關的編譯日志。
    ?
    [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屬于同一個層面的東西。一個基本的調用cl.exe編譯的命令行如下所示:
    [plain] view plaincopy
  • cl.exe?helloworld.cpp??
  • 上述命令執行完后即可在同一目錄下生成一個helloworld.exe的可執行程序。
    編譯包含類庫的程序相對來說要復雜一些,下面以Simplest FFmpeg Player為例看一下它的編譯腳本。Simplest FFmpeg Player使用CL.exe編譯的腳本保存在“compile_cl.bat”文件中,如下所示。
    [plain] view plaincopy
  • ::最簡單的基于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??

  • 這個腳本按照順序做了以下幾點工作:
    (1)設置VC++運行環境。這一步通過call "D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"實現。
    (2)設置include目錄。這一步設置FFmpeg以及SDL2的頭文件所在的目錄,通過修改include環境變量實現(在include環境變量前面加上項目文件夾中的“include”目錄)。
    (3)設置lib目錄。這一步設置FFmpeg以及SDL2的庫文件所在的目錄,通過修改lib環境變量實現(在lib環境變量前面加上項目文件夾中的“lib”目錄)。
    (4) 編譯和鏈接。這一步用于將simplest_ffmpeg_player.cpp編譯生成simplest_ffmpeg_player.exe。在這里需要注意幾點:
    a) 鏈接類庫使用/link
    b) 使用SDL類庫的時候,務必設置/MD選項(使用動態鏈接的庫)
    c) ?使用SDL類庫的時候,務必設置/SUBSYSTEM:WINDOWS
    d) ?使用FFmpeg類庫的時候,務必設置/OPT:NOREF 上述腳本運行完城后,生成simplest_ffmpeg_player.exe。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_cl_all.bat如下所示。將腳本拷貝至《最簡單的FFmpeg示例程序合集》所在目錄運行,就可以編譯所有的示例程序。注意這個腳本只是分別調用了各個程序目錄下的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編譯需要運行其安裝目錄下的msys.bat設置其環境變量。一個基本的調用MinGW gcc編譯的命令行如下所示:
    [plain] view plaincopy
  • gcc?helloworld.cpp?-o?helloworld.exe??
  • 上述命令執行完后即可在同一目錄下生成一個helloworld.exe的可執行程序。
    編譯包含類庫的程序相對來說要復雜一些,下面以Simplest FFmpeg Player為例看一下它的編譯腳本。Simplest FFmpeg Player使用MinGW GCC編譯的腳本保存在“compile_mingw.sh”文件中,如下所示。
    [plain] view plaincopy
  • #!?/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??
  • ?
    這個腳本使用MinGW中的g++完成編譯。在這里要注意一點,并不是gcc只能編譯c代碼,g++只能編譯c++代碼,而是gcc和g++都可以編譯C和C++代碼。源代碼文件后綴為.c的,gcc把它當作是C程序,而g++當作是c++程序;后綴為.cpp的,兩者都會認為是c++程序。上述編譯命令有以下幾點需要注意:
    (a) ?include目錄設置為/usr/local/include,要確保SDL2和FFmpeg的頭文件都安裝在這個目錄里(SDL2有可能沒有安裝在這里)
    (b) ?lib目錄設置為/usr/local/lib,要確保SDL2和FFmpeg的庫文件都安裝在這個目錄里(SDL2有可能沒有安裝在這里)
    (c) ?使用SDL類庫的時候,務必鏈接-lmingw32
    上述腳本運行完城后,生成simplest_ffmpeg_player.exe。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_mingw_all.sh如下所示。將腳本拷貝至《最簡單的FFmpeg示例程序合集》所在目錄運行,就可以編譯所有的示例程序。注意這個腳本只是分別調用了各個程序目錄下的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++程序,一個簡單的GCC編譯命令:
    [plain] view plaincopy
  • gcc?helloworld.cpp?-o?helloworld.out??
  • 上述命令執行完后即可在同一目錄下生成一個名稱為helloworld.out的可執行程序。
    編譯包含類庫的程序相對來說要復雜一些,下面以Simplest FFmpeg Player為例看一下它的編譯腳本。Simplest FFmpeg Player使用GCC編譯的腳本保存在“compile_gcc.sh”文件中,如下所示。
    [plain] view plaincopy
  • #!?/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完成編譯。上文中已經提到過一次,并不是gcc只能編譯c代碼,g++只能編譯c++代碼,而是gcc和g++都可以編譯C和C++代碼。源代碼文件后綴為.c的,gcc把它當作是C程序,而g++當作是c++程序;后綴為.cpp的,兩者都會認為是c++程序。上述編譯命令有以下幾點需要注意:
    (a) ?include目錄設置為/usr/local/include,要確保SDL2和FFmpeg的頭文件都安裝在這個目錄里
    (b) ?lib目錄設置為/usr/local/lib,要確保SDL2和FFmpeg的庫文件都安裝在這個目錄里
    (c) ?有些版本中的Linux可能沒有安裝gcc/g++編譯器,需要先裝好這兩個編譯器
    上述腳本運行完城后,生成simplest_ffmpeg_player.out。
    ?

    注意事項:Linux和MacOS的不同

    Linux和MacOS在SDL1.2的使用上有很大的不同。在MacOS下使用SDL1.2必須加上“-framework Cocoa”參數,否則編譯會出現錯誤。因此在MacOS下編譯使用SDL1.2的程序的時候,編譯命令如下所示(以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??
  • 對于這些采用SDL1.2的程序,保存了一個MacOS下專有的腳本“compile_gcc_mac.sh”。
    此外,Linux和MacOS在顯示上也有較大的不同。此前發現Windows和MacOS下可以正常顯示的程序在Ubuntu下卻會出現“綠屏”現象。不過隨著代碼的調整這一情況已經被消除了。
    ?
    完整的腳本simplest_ffmpeg_demos_compile_gcc_all.sh如下所示。將腳本拷貝至《最簡單的FFmpeg示例程序合集》所在目錄運行,就可以編譯所有的示例程序。注意這個腳本只是分別調用了各個程序目錄下的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?..??
  • ??
  • #=====================================================================================?
  • 總結

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

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。