1. ffmpeg 的安装
./configure
make
sudo make install
默认会将ffmpeg安装至/usr/local目录下(可通过configure使用“-prefix=目录”修改安装目录),
安装完成后分别会在/usr/local下的bin、include、lib、share四个目录下生成ffmpeg的二进制可执行文件、头文件、编译链接库、文档。
后面开发我们会用到include、lib里的头文件和编译链接库。
2. ffmpeg 版 Hello world
//helloFF.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;
}
3. Makefile 编写
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:helloFF.c
$(CC) -o helloFF.o -c helloFF.c $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS)
clean:
rm helloFF helloFF.o