FFmpeg编译-Linux平台

目录

  1. 参考
  2. 编译FFmpeg
  3. 编写测试代码

1. 参考

2. 编译FFmpeg

(1) 下载FFmpeg的源码 官方地址
(2) 配置编译参数

关于FFMPEG的配置参数,我们可以通过下面命令来查看:

./configure --help

编译动态库,不要静态库,不用说明文档的编译配置:

./configure --prefix=buildout --enable-shared --disable-static --disable-doc 

增加x264支持的编译配置

./configure --prefix=buildout --enable-shared --disable-static --disable-doc  --enable-gpl --enable-libx264

这一步执行成功,将会生成Makefile文件。
(3) 编译

make
make install

编译生成的库和头文件将会复制到前面指定的目录中(--prefix=../buildout)

3. 编写测试代码

这里我们使用与FFmpeg学习(三) Android平台FFmpeg的HelloWrold程序类似的例子,打印FFmpeg支持的文件格式、编码器、过滤器的信息。

测试代码如下

#include <stdio.h>
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libavfilter/avfilter.h"

int main() {
    av_register_all();
    AVInputFormat *inputFormat = av_iformat_next(NULL);
    AVOutputFormat *outputFormat = av_oformat_next(NULL);
    while (inputFormat) {
        printf("[In][%10s]\n", inputFormat->name);
        inputFormat = inputFormat->next;
    }
    while (outputFormat) {
        printf("[Out][%10s]\n", outputFormat->name);
        outputFormat = outputFormat->next;
    }

    AVCodec *codec = av_codec_next(NULL);
    while (codec) {
        if (codec->decode) {
            printf("[Dec]");
        } else {
            printf("[Eec]");
        }
        switch (codec->type) {
            case AVMEDIA_TYPE_VIDEO:
                printf("[Video]");
                break;
            case AVMEDIA_TYPE_AUDIO:
                printf("[Audio]");
                break;
            default:
                printf("[Other]");
                break;
        }
        printf("[%10s]\n", codec->name);
        codec = codec->next;
    }

    avfilter_register_all();
    AVFilter *filter  = avfilter_next(NULL);
    while (filter) {
        printf("[F][%s]\n", filter->name);
        filter = filter->next;
    }   
  return 0;
}

编译

gcc -o hello_ffmpeg hello_ffmpeg.c -Iffmpeg/include -Lffmpeg/lib/ -lavformat -lavfilter -lavcodec -lswscale -lavutil -lswresample 

说明:这里把编译生成的FFmpeg动态库和include文件放在了测试代码同级目录的ffmpeg文件夹下。

运行
执行测试程序之前需要先配置一下链接库的路径,否则运行的时候会报找不到FFmpeg的动态库的错误。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:ffmpeg/lib

配置好后再执行测试程序:

./hello_ffmpeg

输出示例如下:

[In][        aa]  
[In][       aac] 
[In][       ac3] 
[In][       acm] 
[In][       act] 
[In][       adf] 
[In][       adp] 
[In][       ads] 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一个故事。 半夜,我坐在床头,瞪着眼,在黑暗里寻摸。 屋外,月色幽暗,忽儿大放光明,好像月光暴发,可劲儿倾泄。 ...
    雪斩梅阅读 176评论 0 0
  • 人生的不如意,大多是你的环境造就的,你接触的人造就的。本质是自己选择了这些不如意的环境。一个聪明人,不断的反思自己...
    90后创业者阅读 292评论 0 0
  • 姓名:田宏宇~公司:四川普瑞照明工程有限公司 【日精进打卡第23天】20180403 【知~学习】听得到(逻辑思维...
    thy123456阅读 120评论 0 0
  • 有一种感觉,就是,你明明很喜欢他,却告诉自己不能喜欢。你明明很想他,却只能偷偷地翻他动态。 真是奇怪,可以骗得了自己。
    NOVEMBER_afdd阅读 439评论 0 0
  • 生活圈越来越小,朋友圈越来越大。这个世界更新的太快,朋友圈变成了我们获取信息和发表态度的最佳渠道,没有人不想在这里...
    赵慧姿阅读 282评论 4 6