ffmpeg在Linux下的编译与使用

ffmpeg在Linux下的编译请看文章:https://blog.csdn.net/yihuanyihuan/article/details/84405091

ffmpeg安装第三方库请看文章:https://blog.csdn.net/yihuanyihuan/article/details/84405111

linux下编译ffmpeg后会生成相关的动态文件与头文件,如何按照上述方法进行安装,其生成路径为/monchickey/ffmpeg,其目录下有四个文件夹,include,lib,bin,share。

.
├── bin
│   ├── ffmpeg
│   ├── ffprobe
│   └── ffserver
├── include
│   ├── libavcodec
│   ├── libavdevice
│   ├── libavfilter
│   ├── libavformat
│   ├── libavutil
│   ├── libswresample
│   └── libswscale
├── lib
│   ├── libavcodec.so -> libavcodec.so.57.64.101
│   ├── libavcodec.so.57 -> libavcodec.so.57.64.101
│   ├── libavcodec.so.57.64.101
│   ├── libavdevice.so -> libavdevice.so.57.1.100
│   ├── libavdevice.so.57 -> libavdevice.so.57.1.100
│   ├── libavdevice.so.57.1.100
│   ├── libavfilter.so -> libavfilter.so.6.65.100
│   ├── libavfilter.so.6 -> libavfilter.so.6.65.100
│   ├── libavfilter.so.6.65.100
│   ├── libavformat.so -> libavformat.so.57.56.101
│   ├── libavformat.so.57 -> libavformat.so.57.56.101
│   ├── libavformat.so.57.56.101
│   ├── libavutil.so -> libavutil.so.55.34.101
│   ├── libavutil.so.55 -> libavutil.so.55.34.101
│   ├── libavutil.so.55.34.101
│   ├── libswresample.so -> libswresample.so.2.3.100
│   ├── libswresample.so.2 -> libswresample.so.2.3.100
│   ├── libswresample.so.2.3.100
│   ├── libswscale.so -> libswscale.so.4.2.100
│   ├── libswscale.so.4 -> libswscale.so.4.2.100
│   ├── libswscale.so.4.2.100
│   └── pkgconfig
└── share
    └── ffmpeg

2.使用ffmpeg生成的动态库与头文件
程序可以打印出FFmpeg类库的基本信息,使用该程序通常可以验证FFmpeg是否正确的安装配置:

#include <stdio.h>  
  
#define __STDC_CONSTANT_MACROS  
  
#ifdef __cplusplus  
extern "C"  
{  
#endif  
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavfilter/avfilter.h"
#ifdef __cplusplus  
};  
#endif  
  
  
/** 
 * AVFormat Support Information 
 */  
char * avformatinfo(){  
  
    char *info=(char *)malloc(40000);  
    memset(info,0,40000);  
  
    av_register_all();  
  
    AVInputFormat *if_temp = av_iformat_next(NULL);  
    AVOutputFormat *of_temp = av_oformat_next(NULL);  
    //Input  
    while(if_temp!=NULL){  
        sprintf(info, "%s[In ] %10s\n", info, if_temp->name);  
        if_temp=if_temp->next;  
    }  
    //Output  
    while (of_temp != NULL){  
        sprintf(info, "%s[Out] %10s\n", info, of_temp->name);  
        of_temp = of_temp->next;  
    }  
    return info;  
}  
  
/** 
 * AVCodec Support Information 
 */  
char * avcodecinfo()  
{  
    char *info=(char *)malloc(40000);  
    memset(info,0,40000);  
  
    av_register_all();  
  
    AVCodec *c_temp = av_codec_next(NULL);  
  
    while(c_temp!=NULL){  
        if (c_temp->decode!=NULL){  
            sprintf(info, "%s[Dec]", info);  
        }  
        else{  
            sprintf(info, "%s[Enc]", info);  
        }  
        switch (c_temp->type){  
        case AVMEDIA_TYPE_VIDEO:  
            sprintf(info, "%s[Video]", info);  
            break;  
        case AVMEDIA_TYPE_AUDIO:  
            sprintf(info, "%s[Audio]", info);  
            break;  
        default:  
            sprintf(info, "%s[Other]", info);  
            break;  
        }  
  
        sprintf(info, "%s %10s\n", info, c_temp->name);  
  
        c_temp=c_temp->next;  
    }  
    return info;  
}  
  
/** 
 * AVFilter Support Information 
 */  
char * avfilterinfo()  
{  
    char *info=(char *)malloc(40000);  
    memset(info,0,40000);  
  
    avfilter_register_all();  
  
    AVFilter *f_temp = (AVFilter *)avfilter_next(NULL);  
      
    while (f_temp != NULL){  
        sprintf(info, "%s[%15s]\n", info, f_temp->name);  
        f_temp=f_temp->next;  
    }  
    return info;  
}  
  
/** 
 * Configuration Information 
 */  
char * configurationinfo()  
{  
    char *info=(char *)malloc(40000);  
    memset(info,0,40000);  
  
    av_register_all();  
  
    sprintf(info, "%s\n", avcodec_configuration());  
  
    return info;  
}  
  
int main(int argc, char* argv[])  
{  
    char *infostr=NULL;  
    infostr=configurationinfo();  
    printf("\n<<Configuration>>\n%s",infostr);  
    free(infostr);  
  
    infostr=avformatinfo();  
    printf("\n<<AVFormat>>\n%s",infostr);  
    free(infostr);  
  
    infostr=avcodecinfo();  
    printf("\n<<AVCodec>>\n%s",infostr);  
    free(infostr);  
  
    infostr=avfilterinfo();  
    printf("\n<<AVFilter>>\n%s",infostr);  
    free(infostr);  
  
    return 0;  
}

编译方法:

g++ -I ../include/ hello_world.cpp -o hello_world -L../lib/ -lavcodec -lavdevice -lavfilter -lavformat -lavutil

-I 指定头文件的搜索路径, -L指定动态库的搜索路径 -l指定要链接的动态库

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 FFmpeg 的 ffplay 工具,你需要先获取 FFmpeg 的源代码,并在 Linux 环境下安装交叉编译工具链。以下是编译步骤的简要概述: 1. 获取 FFmpeg 源代码 你可以从 FFmpeg 的官方网站或 Git 仓库中获取最新的源代码。 2. 安装交叉编译工具链 你需要安装适用于 arm64 架构的交叉编译工具链,例如 aarch64-linux-gnu-gcc。你可以从 Linux 发行版的软件仓库中安装,或者从交叉编译工具链的官方网站下载。 3. 配置编译选项 进入 FFmpeg 源代码目录,运行以下命令进行配置: ``` ./configure --arch=arm64 --target-os=linux --enable-gpl --enable-nonfree --enable-shared --enable-pic --cross-prefix=aarch64-linux-gnu- --prefix=/usr/local/arm/ffmpeg --extra-cflags="-I/usr/local/arm/include" ``` 这个命令与之前提到的类似,指定了 arm64 架构和 Linux 系统,启用了 GPL 和非自由组件,以及共享库和位置无关代码编译选项。额外的 CFLAGS 选项指定了头文件搜索路径。 4. 编译和安装 运行以下命令进行编译和安装: ``` make make install ``` 这个命令将编译 FFmpeg 和 ffplay 工具,并将它们安装到指定的目录中。如果编译过程出现错误,你可以查看编译日志和错误信息,然后尝试解决问题。 注意:编译 FFmpeg 需要一定的时间和系统资源,特别是在较慢的硬件上。你可以使用 make 命令的 -j 选项来指定并行编译任务的数量,以缩短编译时间。例如,make -j4 将使用 4 个并行任务编译代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值