Ubuntu 16.04.3下FFmpeg编译与开发环境搭建

PC环境: Ubuntu 16.04.3

编译步骤:

1, 安装相关工具:

  1. sudo apt-get install -y autoconf automake build-essential git libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev 
  2. sudo apt-get install -y nasam yasm cmake mercurial  

2,git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg,得到文件夹ffmpeg,进入ffmpeg文件夹:

  1. ./configure --enable-shared  --prefix=/usr/local/ffmpeg

安装到/usr/local/ffmpeg下,可通过“--prefix=安装目录”进行修改。--enable-shared:指定生成动态库,默认是静态库。静态库不方便后续开发。

      2.sudo make

      3.sudo make install  


3,添加ffmpeg库的链接:

在/etc/ld.so.conf中 末尾添加 /usr/local/ffmpeglib即可,执行

  1. sudo ldconfig 

4.安装VS Code

参考https://blog.csdn.net/u011258217/article/details/78693564

5.测试环境

#include <stdio.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavfilter/avfilter.h>

#define dbmsgc(fmt, args ...) printf("cong:%s[%d]: "fmt"\n", __FUNCTION__, __LINE__,##args)
//#define dbmsg(fmt, args ...) printf("cong:%s:%s[%d]: "fmt"\n",__FILE__, __FUNCTION__, __LINE__,##args)
int main(int argc, char **argv)
{
    int i=0;
    AVFormatContext *pFormatCtx = NULL;
    avcodec_register_all();
#if CONFIG_AVDEVICE
    avdevice_register_all();
#endif
   avfilter_register_all();
    av_register_all();

    if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)
        return -1; // Couldn't open file

    if(avformat_find_stream_info(pFormatCtx, NULL)<0)
        return -1; // Couldn't find stream inform
    av_dump_format(pFormatCtx,0, 0, 0);

    return 0;
}
6..编写Makefile
FFMPEG=/usr/local/ffmpeg
CC=gcc
CFLAGS=-g -I$(FFMPEG)/include
LDFLAGS = -L$(FFMPEG)/lib/ -lswscale -lswresample -lavformat -lavdevice -lavcodec -lavutil -lavfilter  -lm 
TARGETS=test
all: $(TARGETS)
test:test.c
    $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -std=c++11 #注意这里的-std=c++11

clean:
    rm -rf $(TARGETS)

7.make

8../test

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值