Ubuntu 16.04.3下FFmpegコンパイルと開発環境構築

3857 ワード

PC環境:Ubuntu 16.04.3
コンパイル手順:
1、関連ツールのインストール:
sudo apt-get install -y autoconf automake build-essential git libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev 
sudo apt-get install -y nasam yasm cmake mercurial  
2,git clone git://source.ffmpeg.org/ffmpeg.gitffmpeg、フォルダffmpegを取得し、ffmpegフォルダに入ります:
./configure --enable-shared  --prefix=/usr/local/ffmpeg
/usr/local/ffmpegにインストールすると、「--prefix=インストールディレクトリ」で変更できます.--Enable-shared:動的ライブラリの生成を指定します.デフォルトは静的ライブラリです.静的ライブラリは後続の開発に不便です.
      2.sudo make
      3.sudo make install  
3、ffmpegライブラリのリンクを追加します:
/etc/ld.so.confの末尾に/usr/local/ffmpeglibを追加すれば、実行
sudo ldconfig 
4.VSコードを取り付ける
リファレンスhttps://blog.csdn.net/u011258217/article/details/78693564
5.テスト環境
#include 
#include 
#include 
#include 

#define dbmsgc(fmt, args ...) printf("cong:%s[%d]: "fmt"
", __FUNCTION__, __LINE__,##args)
//#define dbmsg(fmt, args ...) printf("cong:%s:%s[%d]: "fmt"
",__FILE__, __FUNCTION__, __LINE__,##args)
int main(int argc, char **argv) { int i=0; AVFormatContext *pFormatCtx = NULL; avcodec_register_all(); #if CONFIG_AVDEVICE avdevice_register_all(); #endif avfilter_register_all(); av_register_all(); if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0) return -1; // Couldn't open file if(avformat_find_stream_info(pFormatCtx, NULL)<0) return -1; // Couldn't find stream inform av_dump_format(pFormatCtx,0, 0, 0); return 0; }
6..Makefileの作成
FFMPEG=/usr/local/ffmpeg
CC=gcc
CFLAGS=-g -I$(FFMPEG)/include
LDFLAGS = -L$(FFMPEG)/lib/ -lswscale -lswresample -lavformat -lavdevice -lavcodec -lavutil -lavfilter  -lm 
TARGETS=test
all: $(TARGETS)
test:test.c
    $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -std=c++11 #     -std=c++11

clean:
    rm -rf $(TARGETS)

7.make
8../test