zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    Scrapy框架
    描述符类
    完整的blog设计过程
    钉钉机器人设置步骤
    homework登录和支付mock两个接口
    jsonpath的用法和nnlog的使用
    mp4格式文件转码后处理(qt-faststart).md
    html5视音频标签参考.md
    ffmpeg文档43-开发者
    ffmpeg文档42-参考/看
  • 原文地址:https://www.cnblogs.com/ichenwin/p/10761084.html
Copyright © 2011-2022 走看看