• FFmpeg 开发环境搭建及第一个程序 Hello FFmpeg 编写


    1. FFmpeg 的安装

    ./configure
    make
    make install
    

    默认会将 FFmpeg 安装至 /usr/local 目录下(可通过 configure 使用 “-prefix=目录” 修改安装目录),
    安装完成后分别会在 /usr/local 下的 bin、include、lib、share 四个目录下生成 FFmpeg 的二进制可执行文件、头文件、编译链接库、文档。
    后面开发我们会用到 include、lib 里的头文件和编译链接库。

    2. FFmpeg 版 Hello world

    //testFFmpeg.c
    #include <stdio.h>
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    
    int main(int argc, char *argv[])
    {
        printf("hello FFmpeg
    ");
        AVFormatContext *pFormatCtx = avformat_alloc_context();
    
        if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)) {
            fprintf(stderr, "open input failed
    ");
            return -1;
        }
    
        if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
            fprintf(stderr, "find stream info failed
    ");
            return -1;
        }
    
        int videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
    
        printf("nb:%d, url:%s, time:%ld, duration:%ld, bitRate:%ld, videoStream:%d
    ", 
                pFormatCtx->nb_streams, pFormatCtx->url, pFormatCtx->start_time, pFormatCtx->duration, 
                pFormatCtx->bit_rate, videoStream);
        return 0;
    }
    

    3. Makefile 编写

    all:helloFF
    CC=gcc
    CLIBSFLAGS=-lavformat -lavcodec -lavutil -lswresample -lz -llzma -lpthread -lm
    FFMPEG=/usr/local
    CFLAGS=-I$(FFMPEG)/include/
    LDFLAGS = -L$(FFMPEG)/lib/
    helloFF:helloFF.o
    	$(CC) -o helloFF helloFF.o $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS)
    helloFF.o:test.c
    	$(CC) -o helloFF.o -c test.c  $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS)
    clean:
    	rm helloFF helloFF.o
    
    

    FFmpeg 版本

    [ubuntu@ubuntu-virtual-machine testFFmpeg]$ ffmpeg -version
    ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
    built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
    configuration: 
    libavutil      56. 22.100 / 56. 22.100
    libavcodec     58. 35.100 / 58. 35.100
    libavformat    58. 20.100 / 58. 20.100
    libavdevice    58.  5.100 / 58.  5.100
    libavfilter     7. 40.101 /  7. 40.101
    libswscale      5.  3.100 /  5.  3.100
    libswresample   3.  3.100 /  3.  3.100
    
  • 相关阅读:
    金步国作品列表
    GCC编译优化指南【作者:金步国】
    g++优化选项
    C++中实现对map按照value值进行排序
    C++ STL中Map的相关排序操作:按Key排序和按Value排序
    How-To: add EPEL repository to Centos 6.x is Easy!
    如何为linux释放内存和缓存
    用Python对体积较大的CSV文件进行比较的经验
    The mmap module
    Python逐块读取大文件行数的代码
  • 原文地址:https://www.cnblogs.com/ichenwin/p/10761084.html
Copyright © 2020-2023  润新知