操作系统: 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


 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐