windows下編譯ffmpeg以及遇到的坑


 

遇事先百度,對,我就是這么干的,不過很多文章不適合我的情況;

我的電腦環境(win10、VS2019),無論是什么VS,沒什么差距;

找了很多文檔,目前斷定window不能直接編譯ffmpeg,那么就要在windows構建linux環境;

1,構建linux環境;

  構建環境有3種方案,wsl(ubuntu子系統)、cygwin、msys,那么坑來了,選型時肯定哪個簡單選哪個,wsl這個在windows store里(搜索ubuntu),但是這個方法由於su無法繼承當前用戶的環境變量,也找了很多方法改變su的環境變量,還是無法找到cl.exe,如果不適用su,又無法使用apt;

  后來選了msys,總算通過了。

  a,下載MSYS2,地址:https://www.msys2.org/

  b,安裝:無腦下一步

  c,啟動MSYS2:進入安裝目錄,啟動 msys2_shell.cmd

  d,下載依賴:

    安裝make: pacman -S make
    安裝yasm: pacman -S yasm
    安裝diffutils: pacman -S diffutils
    安裝pkg-config: pacman -S pkg-config
    安裝git: pacman -S git(如果已有源碼不需要安裝)
 
  2,配置環境
  a,關閉之前的msys2_shell.cmd
  b,根據情況打開vs命令
  

 

   c,用vs命令打開msys2.exe

  d,設置環境變量:    

export PATH="/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64":$PATH

 

    這個要根據自己的VS路徑設置;

 3,下載源碼
   Download FFmpeg,這兩處都可以下載, 然后CD到源碼目錄
  

 

4,配置

./configure --toolchain=msvc --arch=x86_64 --enable-x86asm --enable-shared --enable-w32threads --disable-doc --disable-static --prefix=output --enable-optimizations

  configure介紹

#!/bin/sh
...

#幫組選項
Help options:
  --help                   print this message
  --quiet                  Suppress showing informative output
  --list-decoders          show all available decoders
  --list-encoders          show all available encoders
  --list-hwaccels          show all available hardware accelerators
  --list-demuxers          show all available demuxers
  --list-muxers            show all available muxers
  --list-parsers           show all available parsers
  --list-protocols         show all available protocols
  --list-bsfs              show all available bitstream filters
  --list-indevs            show all available input devices
  --list-outdevs           show all available output devices
  --list-filters           show all available filters

#標准選項
#--disable  代表關閉狀態 ;--enable   代表開啟狀態
Standard options:
  --logfile=FILE           log tests and output to FILE [ffbuild/config.log]
  --disable-logging        do not log configure debug information
  --fatal-warnings         fail if any configure warning is generated
  
  #我們最終編譯好的動態靜態庫位置,必須設置
  --prefix=PREFIX          install in PREFIX [$prefix_default]
  
  --bindir=DIR             install binaries in DIR [PREFIX/bin]
  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
  --docdir=DIR             install documentation in DIR [PREFIX/share/doc/ffmpeg]
  --libdir=DIR             install libs in DIR [PREFIX/lib]
  --shlibdir=DIR           install shared libs in DIR [LIBDIR]
  --incdir=DIR             install includes in DIR [PREFIX/include]
  --mandir=DIR             install man page in DIR [PREFIX/share/man]
  --pkgconfigdir=DIR       install pkg-config files in DIR [LIBDIR/pkgconfig]
  --enable-rpath           use rpath to allow installing libraries in paths
                           not part of the dynamic linker search path
                           use rpath when linking programs (USE WITH CARE)
  --install-name-dir=DIR   Darwin directory name for installed targets

Licensing options:
  --enable-gpl             allow use of GPL code, the resulting libs
                           and binaries will be under GPL [no]
  --enable-version3        upgrade (L)GPL to version 3 [no]
  --enable-nonfree         allow use of nonfree code, the resulting libs
                           and binaries will be unredistributable [no]

Configuration options:
#開啟靜態庫
  --disable-static         do not build static libraries [no]
#關閉動態庫
  --enable-shared          build shared libraries [no
#可以優化庫的大小
  --enable-small           optimize for size instead of speed
  --disable-runtime-cpudetect disable detecting CPU capabilities at runtime (smaller binary)
  --enable-gray            enable full grayscale support (slower color)
  --disable-swscale-alpha  disable alpha channel support in swscale
  --disable-all            disable building components, libraries and programs
  --disable-autodetect     disable automatically detected external libraries [no]

Program options:
#我們不需要使用程序,不需要在Windows中執行,某.exe程序,我們只需要在代碼中使用  [此命令操作的是下面三項]
  --disable-programs       do not build command line programs
  #使用FFmpeg命令
  --disable-ffmpeg         disable ffmpeg build
  #播放器
  --disable-ffplay         disable ffplay build
  --disable-ffprobe        disable ffprobe build

Documentation options:
  --disable-doc            do not build documentation
  --disable-htmlpages      do not build HTML documentation pages
  --disable-manpages       do not build man documentation pages
  --disable-podpages       do not build POD documentation pages
  --disable-txtpages       do not build text documentation pages

#模塊選項
Component options:
#可以操控我們的攝像頭-(Android中是不支持))
  --disable-avdevice       disable libavdevice build
#audio video codec(編碼 和 解碼)
  --disable-avcodec        disable libavcodec build
#音視頻格式生成和解析相關
  --disable-avformat       disable libavformat build
#音頻重采樣(如果想把單聲道,變成雙聲道)
  --disable-swresample     disable libswresample build
#對視頻顯示相關(對視頻的縮放,放大 縮小)
  --disable-swscale        disable libswscale build
#后期處理,很少用,可以關閉掉
  --disable-postproc       disable libpostproc build
#給視頻加水印,加字幕,特殊效果
  --disable-avfilter       disable libavfilter build
  --enable-avresample      enable libavresample build (deprecated) [no]
  --disable-pthreads       disable pthreads [autodetect]
  --disable-w32threads     disable Win32 threads [autodetect]
  --disable-os2threads     disable OS/2 threads [autodetect]
  --disable-network        disable network support [no]
  --disable-dct            disable DCT code
  --disable-dwt            disable DWT code
  --disable-error-resilience disable error resilience code
  --disable-lsp            disable LSP code
  --disable-lzo            disable LZO decoder code
  --disable-mdct           disable MDCT code
  --disable-rdft           disable RDFT code
  --disable-fft            disable FFT code
  --disable-faan           disable floating point AAN (I)DCT code
  --disable-pixelutils     disable pixel utils in libavutil

Individual component options:
  --disable-everything     disable all components listed below
  --disable-encoder=NAME   disable encoder NAME
  --enable-encoder=NAME    enable encoder NAME
#編碼可以去關閉掉
  --disable-encoders       disable all encoders
  --disable-decoder=NAME   disable decoder NAME
  --enable-decoder=NAME    enable decoder NAME
  --disable-decoders       disable all decoders
  --disable-hwaccel=NAME   disable hwaccel NAME
  --enable-hwaccel=NAME    enable hwaccel NAME
  --disable-hwaccels       disable all hwaccels
  --disable-muxer=NAME     disable muxer NAME
  --enable-muxer=NAME      enable muxer NAME
  #混合封裝(音視頻等於 一段音頻 一段視頻 合並在一起 就是.mp4,不想這樣就可以關閉)
  --disable-muxers         disable all muxers
  --disable-demuxer=NAME   disable demuxer NAME
  --enable-demuxer=NAME    enable demuxer NAME
  --disable-demuxers       disable all demuxers
  --enable-parser=NAME     enable parser NAME
  --disable-parser=NAME    disable parser NAME
  --disable-parsers        disable all parsers
  --enable-bsf=NAME        enable bitstream filter NAME
  --disable-bsf=NAME       disable bitstream filter NAME
  --disable-bsfs           disable all bitstream filters
  --enable-protocol=NAME   enable protocol NAME
  --disable-protocol=NAME  disable protocol NAME
  --disable-protocols      disable all protocols
  --enable-indev=NAME      enable input device NAME
  --disable-indev=NAME     disable input device NAME
  --disable-indevs         disable input devices
  --enable-outdev=NAME     enable output device NAME
  --disable-outdev=NAME    disable output device NAME
  --disable-outdevs        disable output devices
  --disable-devices        disable all devices
  --enable-filter=NAME     enable filter NAME
  --disable-filter=NAME    disable filter NAME
  --disable-filters        disable all filters
...

 

5,編譯

  make install

  生成目錄 msys64\home\root\ffmpeg\output

  據實際使用release和debug是同一套;

 6,幫助文檔

  FFmpeg: Main Page

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM