• H264解码之YUV格式转换及缩放


    int video_decoder::swscale(const char* srcbuf, int ntype, int nsrcwidth, int nsrcheight, int ndstwidth, int ndstheight, unsigned char* dstbuf)
    {
    	if (5 != ntype && 3 != ntype)
    	{
    		return -1;
    	}
    	if (!srcbuf || !dstbuf)
    		return -1;
    	AVPixelFormat srcpixfmt = AV_PIX_FMT_YUV420P;
    	AVPixelFormat dstpixfmt = AV_PIX_FMT_BGR32;
    	uint8_t* src_y = 0;
    	uint8_t* src_u = 0;
    	uint8_t* src_v = 0;
    	if (3 == ntype)
    	{
    		src_y = (uint8_t*)srcbuf;
    		src_v = (uint8_t*)srcbuf + nsrcwidth * nsrcheight;
    		src_u = (uint8_t*)srcbuf + nsrcwidth * nsrcheight + nsrcwidth * nsrcheight / 4;
    	}
    	else
    	{
    		src_y = (uint8_t*)srcbuf;
    		src_u = (uint8_t*)srcbuf + nsrcwidth * nsrcheight;
    		src_v = (uint8_t*)srcbuf + nsrcwidth * nsrcheight + nsrcwidth * nsrcheight / 4;
    	}
    	uint8_t* src[3] = { src_y, src_v, src_u };
    	int srcstride[3] = { nsrcwidth, nsrcwidth / 2, nsrcwidth / 2 };
    	srcstride[0] = nsrcwidth;
    	srcstride[1] = nsrcwidth / 2;
    	srcstride[2] = nsrcwidth / 2;
    	src[0] += srcstride[0] * (nsrcheight - 1);
    	srcstride[0] *= -1;
    	src[1] += srcstride[1] * (nsrcheight / 2 - 1);
    	srcstride[1] *= -1;
    	src[2] += srcstride[2] * (nsrcheight / 2 - 1);
    	srcstride[2] *= -1;
    
    	uint8_t* dst[4] = { dstbuf, NULL, NULL, NULL };
    	int dststride[4] = { ndstwidth * 4, 0, 0, 0 };
    	SwsContext* s = sws_getContext(nsrcwidth, nsrcheight, srcpixfmt, ndstwidth, ndstheight, dstpixfmt, SWS_BICUBIC, NULL, NULL, NULL);
    	if (NULL == s)
    	{
    		return 0;
    	}
    	sws_scale(s, src, srcstride, 0, nsrcheight, dst, dststride);
    	sws_freeContext(s);
    	return 0;
    }
  • 相关阅读:
    Android
    十大基础有用算法之迪杰斯特拉算法、最小生成树和搜索算法
    【随想】android是个什么东西,andorid机制随想
    【Unity3D】【NGUI】Atlas的动态创建
    Java集合01----ArrayList的遍历方式及应用
    JAVA线程
    VC++的project文件
    selector的button选中处理问题
    单元測试和白盒測试相关总结
    leetCode(40):Path Sum
  • 原文地址:https://www.cnblogs.com/SunkingYang/p/11049140.html
Copyright © 2020-2023  润新知