01-流媒体-FFMPEG环境搭建

ubuntu18.04上搭建ffmpeg环境
1.首先是在官网上下载好对应的开发包,我电脑上下载的版本是ffmpeg-4.2.2。
ffmpeg源码地址:
https://ffmpeg.org/releases/ffmpeg-4.2.2.tar.bz2
2.配置在源码目录下建立一个my_build目录。此目录用于后面放编译出来的LIB和头文件。
3.环境安装

sudo apt-get update -qq && sudo apt-get -y install autoconf automake  build-essential cmake   git-core   libass-dev   libfreetype6-dev   libsdl2-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 nasm
sudo apt-get install yasm
sudo apt-get install libx264-dev -y
sudo apt-get install libx265-dev libnuma-dev -y
sudo apt-get install libvpx-dev -y
sudo apt-get install libfdk-aac-dev -y
sudo apt-get install libmp3lame-dev -y
sudo apt-get install libopus-dev -y

4.开始配置configure

./configure --prefix=./my_build --enable-static --enable-shared --extra-libs="-lpthread -lm" --enable-gpl --disable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-shared --enable-nonfree

5.生成对应的文件到my_build目录
make -j4
make install

6.编写对相应的验证程序。
[helloworld.cpp]

#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
#include <pthread.h>
//FIX
struct URLProtocol;
/**
 * Protocol Support Information
 */
char * urlprotocolinfo(){
	
	char *info=(char *)malloc(40000);
	memset(info,0,40000);
 
	av_register_all();
 
	struct URLProtocol *pup = NULL;
	//Input
	struct URLProtocol **p_temp = &pup;
	avio_enum_protocols((void **)p_temp, 0);
	while ((*p_temp) != NULL){
		sprintf(info, "%s[In ][%10s]\n", info, avio_enum_protocols((void **)p_temp, 0));
	}
	pup = NULL;
	//Output
	avio_enum_protocols((void **)p_temp, 1);
	while ((*p_temp) != NULL){
		sprintf(info, "%s[Out][%10s]\n", info, avio_enum_protocols((void **)p_temp, 1));
	}
 
	return info;
}
 
/**
 * 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=urlprotocolinfo();
	printf("\n<<URLProtocol>>\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;
}

7.将ffmpeg的lib与头文件放入工程中,并编写makefile,主要是加入以下的链接

LDFLAGS = -ldl -lX11 -lasound -lpthread -lmp3lame -lz -lrt -lm 
LDFLAGS += -L$(FFMPEG_LIB_DIR) -lavformat -lavdevice  -lavcodec -lavutil  -lavfilter -lpostproc  -lswresample -lswscale

8.编译工程,并将ffmpeg的lib中的文件的拷贝到系统的/usr/lib目录下。
9.运行目标进程,进程运行正常。

Makefile的编写方法,请看基础篇的一步一步写Makefile

注:邮箱:419902005@qq.com

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值