ffmpeg 入门教程

1.在terminal,安装ffmpeg开源库

#brew install ffmpeg 

2.新建一个目录first_ffmpeg,并在first_ffmpeg目录下新建ffmpeg目录

3.拷贝/usr/local/Cellar/ffmpeg/4.1.1/下的lib和include文件夹到上一步中的ffmpeg目录

4.在first_ffmpeg,创建如下内容的CMakeLists.txt


cmake_minimum_required(VERSION 2.8)

project(first_ffmpeg)

include_directories("/The/path/to/first_ffmpeg/ffmpeg/include")
link_directories("/The/path/to/first_ffmpeg/ffmpeg/lib")
link_libraries(libavcodec.a)
link_libraries(libavdevice.a)
link_libraries(libavfilter.a)
link_libraries(libavformat.a)
link_libraries(libavutil.a)
link_libraries(libpostproc.a)
link_libraries(libswresample.a)
link_libraries(libswscale.a)

add_executable(${PROJECT_NAME} "main.cpp")

5.书写main函数如下

#include <iostream>

using namespace std;

extern "C"
{
    #include "libavcodec/avcodec.h"
    #include "libavformat/avformat.h"
    #include "libswscale/swscale.h"
    #include "libavdevice/avdevice.h"
}

int main()
{
    cout << "Hello FFmpeg!" << endl;
    av_register_all();
    unsigned int version = avcodec_version();
    cout << "FFmpeg version is:" << version << endl;
    cout << "Hello World!" << endl;
    return 0;
}

6.编译运行

#mkdir build 
#cd build
#cmake ..
#make
#./first_ffmpeg

输出:

Hello FFmpeg!
FFmpeg version is:3810148
Hello World!

7.工程first_ffmpeg目录结构如下

#first_ffmpeg tree -L 2

.
├── CMakeLists.txt
├── build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   ├── Makefile
│   ├── cmake_install.cmake
│   └── first_ffmpeg
├── ffmpeg
│   ├── include
│   └── lib
└── main.cpp

posted @ 2019-02-11 17:49  drfxiaoliuzi  阅读(3594)  评论(0编辑  收藏  举报