【Linux】【ffmpeg】ubuntu安装ffmpeg并运行简单的例子

12 篇文章 0 订阅

操作系统: Ubuntu 16.04.3 

编译步骤:

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  
sudo apt-get install -y nasam yasm cmake mercurial  

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

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

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

 make -j4
 make install  

3,添加ffmpeg库:

在/etc/ld.so.conf中 末尾添加 /usr/local/ffmpeg/lib   

执行

sudo ldconfig  

 

4.测试文件test.c

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


5.1.编写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)

然后

make

运行 

./test test.flv

 

5.2也可以直接通过命令进行运行

gcc test.c -L/usr/local/ffmpeg/lib/ -lswscale -lswresample -lavformat -lavdevice -lavcodec -lavutil -lavfilter -o test

运行结果

trust100@ubuntu:~/Downloads/ffmpeg-4.2.1/doc/examples/test$ ./test /home/trust100/ffmpeg/test.flv 
Input #0, flv, from '(null)':
  Metadata:
    metadatacreator : modify by youku.com in 20090909
    hasKeyframes    : true
    hasVideo        : true
    hasAudio        : true
    hasMetadata     : true
    canSeekToEnd    : false
    datasize        : 6163342
    videosize       : 5249918
    audiosize       : 883196
    lasttimestamp   : 207
    lastkeyframetimestamp: 202
    lastkeyframelocation: 6117561
  Duration: 00:03:26.84, start: 0.003000, bitrate: 238 kb/s
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 512x288 [SAR 1:1 DAR 16:9], 201 kb/s, 15 fps, 15 tbr, 1k tbn, 30 tbc
    Stream #0:1: Audio: aac (HE-AAC), 44100 Hz, stereo, fltp, 32 kb/s


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GLL_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值