当前位置: 移动技术网 > IT编程>开发语言>C/C++ > FFmpeg 开发环境搭建及第一个程序 Hello FFmpeg 编写

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

2019年04月25日  | 移动技术网IT编程  | 我要评论

新婚快乐概不退货_搞笑__hao1,童安格,超牛网

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网