FFmpeg 4.1:avcodec_encode_video2()已被声明为已否决

11 篇文章 0 订阅

1 原因

FFmepg新版本已经将该API丢弃,需要新的API接口代替

解决方案1:将SDL检查设置为否(不推荐)

在这里插入图片描述

解决方案2:修改为新的API接口函数

  • 旧API函数写法示例
int AnimationMp4VideoGeneration::WriteVideoFrame(AVFormatContext * oc, OutputStream * ost)
{
	int ret;
	AVCodecContext *c;
	AVFrame *frame;
	int got_packet = 0;
	AVPacket pkt = { 0 };
	c = ost->enc;
	frame = GetVideoFrame(ost);
	av_init_packet(&pkt);
	/* encode the image */
	ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
	if (ret < 0) {
		LOG("Error encoding video frame: %s\n");
		exit(1);
	}
	if (!got_packet) {
		ret = WriteFrame(oc, &c->time_base, ost->st, &pkt);
	}
	else {
		ret = 0;
	}

	if (ret < 0)
	{
		LOG("Error while writing video frame: %s\n");
		exit(1);
	}
	
	return (frame || got_packet) ? 0 : 1;
}
  • 新API函数写法修改示例
int AnimationMp4VideoGeneration::WriteVideoFrame(AVFormatContext * oc, OutputStream * ost)
{
	int ret;
	AVCodecContext *c;
	AVFrame *frame;
	int got_packet = 0;
	AVPacket pkt = { 0 };
	c = ost->enc;
	frame = GetVideoFrame(ost);
	av_init_packet(&pkt);
	/* encode the image */
	ret = avcodec_send_frame(c, frame);
	if (ret < 0) {
		LOG("Error encoding video frame: %s\n");
		exit(1);
	}
	got_packet = avcodec_receive_packet(c, &pkt);
	if (!got_packet) {
		ret = WriteFrame(oc, &c->time_base, ost->st, &pkt);
	}
	else {
		ret = 0;
	}
	if (ret < 0)
	{
		LOG("Error while writing video frame: %s\n");
		exit(1);
	}
	
	return (frame || got_packet) ? 0 : 1;
}

如果您觉得这篇博文有用,请访问我的个人站:http://www.stubbornhuang.com/,更多博文干货等着您。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HW140701

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值