./configure make make install
默認會將 FFmpeg 安裝至 /usr/local 目錄下(可經過 configure 使用 「-prefix=目錄」 修改安裝目錄),
安裝完成後分別會在 /usr/local 下的 bin、include、lib、share 四個目錄下生成 FFmpeg 的二進制可執行文件、頭文件、編譯連接庫、文檔。
後面開發咱們會用到 include、lib 裏的頭文件和編譯連接庫。ubuntu
//testFFmpeg.c #include <stdio.h> #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> int main(int argc, char *argv[]) { printf("hello FFmpeg\n"); AVFormatContext *pFormatCtx = avformat_alloc_context(); if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)) { fprintf(stderr, "open input failed\n"); return -1; } if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { fprintf(stderr, "find stream info failed\n"); return -1; } int videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); printf("nb:%d, url:%s, time:%ld, duration:%ld, bitRate:%ld, videoStream:%d\n", pFormatCtx->nb_streams, pFormatCtx->url, pFormatCtx->start_time, pFormatCtx->duration, pFormatCtx->bit_rate, videoStream); return 0; }
all:helloFF CC=gcc CLIBSFLAGS=-lavformat -lavcodec -lavutil -lswresample -lz -llzma -lpthread -lm FFMPEG=/usr/local CFLAGS=-I$(FFMPEG)/include/ LDFLAGS = -L$(FFMPEG)/lib/ helloFF:helloFF.o $(CC) -o helloFF helloFF.o $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS) helloFF.o:test.c $(CC) -o helloFF.o -c test.c $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS) clean: rm helloFF helloFF.o
[ubuntu@ubuntu-virtual-machine testFFmpeg]$ ffmpeg -version ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3) configuration: libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100