设为首页 加入收藏

TOP

FFmpeg 开发环境搭建及第一个程序 Hello FFmpeg 编写
2019-05-23 14:39:46 】 浏览:104
Tags:FFmpeg 开发 环境 搭建 及第 一个 程序 Hello 编写

1. FFmpeg 的安装

./configure
make
make install

默认会将 FFmpeg 安装至 /usr/local 目录下(可通过 configure 使用 “-prefix=目录” 修改安装目录),
安装完成后分别会在 /usr/local 下的 bin、include、lib、share 四个目录下生成 FFmpeg 的二进制可执行文件、头文件、编译链接库、文档。
后面开发我们会用到 include、lib 里的头文件和编译链接库。

2. FFmpeg 版 Hello world

//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;
}

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:test.c
    $(CC) -o helloFF.o -c test.c  $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS)
clean:
    rm helloFF helloFF.o

FFmpeg 版本

[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
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MSP430F5438A的串口 下一篇软件工程结对作业1

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目