FFmpeg 开发环境搭建及第一个程序 Hello FFmpeg 编写

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值