ffmpeg的那些事儿

今天在做编解码时,遇到一个奇怪的问题,就是av_image_alloc 导致内存泄漏,这点比较纳闷,场景是这样的,在视频传输过程中,需要根据网速来切换码流大小哦,如果带宽不够自动切换低码流传输,于是我将采集的1080p的视频转化成yuv格式发送。

过程如下:

首先初始化编解码环境:

	if (_thumbCodecContext != nullptr && _thumbCodec != nullptr)
	{
		return 0;
	}
	int ret;
	AVCodecID codec_id = AV_CODEC_ID_MJPEG;
	int in_w = width, in_h = height;
	_width = width;
	_height = height;
	int framenum = 1;

	_thumbCodec = avcodec_find_encoder(codec_id);
	if (!_thumbCodec) {
		return 40;
	}
	_thumbCodecContext = avcodec_alloc_context3(_thumbCodec);
	if (!_thumbCodecContext) {
		return 40;
	}
	_thumbCodecContext->bit_rate = 1024 *1024 * 10;
	_thumbCodecContext->width = scaleWidth;
	_thumbCodecContext->height = scaleHeight;
	_thumbCodecContext->time_base.num = 1;
	_thumbCodecContext->time_base.den = 11;
	_thumbCodecContext->gop_size = 10;
	_thumbCodecContex
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值