当前位置:网站首页>QT uses ffmpeg4 to convert the qimage of ARGB to yuv422p
QT uses ffmpeg4 to convert the qimage of ARGB to yuv422p
2022-07-01 22:34:00 【F Xiaozhi】
Preface
use FFmpeg4 Implement a very simple argb transformation yuv422p Function of
1. adopt QPixmap obtain QLabel Display the interface and turn to image, Pass in the conversion function
QPixmap pixmap(subtitleLabel->size());
pixmap.fill(Qt::transparent);// Set up pixmap The background is transparent
subtitleLabel->render(&pixmap);
QImage image = pixmap.toImage();
unsigned char *imgBuf = image.bits();
argbToyuv(image.width(),image.height(),imgBuf);
2. establish rgbBuffer And fill in image Of rgbBuf data , establish yuvBuffer, establish SwsContext Conversion context , Use sws_scale convert
#define HI_ALIGN_UP(x, a) ( ( ((x) + ((a) - 1) ) / (a) ) * (a) )
int argbToyuv(int width, int height, unsigned char *rgbBuf)
{
int ret, numBytes = 0;
uint8_t *src_data[4], *dst_data[4];
int src_linesize[4], dst_linesize[4];
int src_w = width, src_h = height, dst_w, dst_h;
dst_w = HI_ALIGN_UP(src_w, 16);// Pixel alignment
dst_h = HI_ALIGN_UP(src_h, 16);
enum AVPixelFormat src_pix_fmt = AV_PIX_FMT_ARGB, dst_pix_fmt = AV_PIX_FMT_YUV422P;
SwsContext *sws_ctx = NULL;
/* create argbBuffer Before creating conversion , fill image Data buffer*/
numBytes = av_image_get_buffer_size(src_pix_fmt, src_w, src_h, 1);//1920*1080*4
uint8_t *argbBuffer = NULL;
(uint8_t*)av_malloc(numBytes*sizeof(uint8_t));
av_image_fill_arrays(src_data, src_linesize, argbBuffer, src_pix_fmt, src_w, src_h, 1);
src_data[0] = rgbBuf;
src_data[1] = src_data[0]+(width*height);
src_data[2] = src_data[1]+(width*2*height);
// FILE *output_rgb=fopen("/opt/vw30/bin/subtitle_rgb","ab+");
// fwrite(rgbBuf,(src_w*src_h)*3,1,output_rgb);
// fclose(output_rgb);
/* create yuvBuffer Create the received after conversion buffer*/
numBytes = av_image_get_buffer_size(dst_pix_fmt, dst_w, dst_h, 1);
uint8_t *yuvBuffer = NULL;
yuvBuffer = (uint8_t*)av_malloc(numBytes*sizeof(uint8_t));
av_image_fill_arrays(dst_data, dst_linesize, yuvBuffer ,dst_pix_fmt, dst_w, dst_h, 1);
/* create scaling context Create transformation context */
sws_ctx = sws_getContext(src_w, src_h, src_pix_fmt,
dst_w, dst_h, dst_pix_fmt,
SWS_BILINEAR, NULL, NULL, NULL);
if (!sws_ctx) {
fprintf(stderr,
"Impossible to create scale context for the conversion "
"fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
av_get_pix_fmt_name(src_pix_fmt), src_w, src_h,
av_get_pix_fmt_name(dst_pix_fmt), dst_w, dst_h);
ret = AVERROR(EINVAL);
goto end;
}
/*sws_scale Conversion function */
ret = sws_scale(sws_ctx, src_data, src_linesize, 0, src_h, dst_data, dst_linesize);
if (ret < 0){
qDebug()<<"sws_scale error";
goto end;
}
end:
if(yuvBuffer){
av_free(yuvBuffer);
}
if(argbBuffer){
av_free(argbBuffer);
}
if(sws_ctx){
sws_freeContext(sws_ctx);
}
// FILE *output=fopen("/opt/vw30/bin/subtitle.yuv","ab+");
// fwrite(dst_data[0],dst_w*dst_h,1,output);
// fwrite(dst_data[1],dst_w*dst_h/4,1,output);
// fwrite(dst_data[2],dst_w*dst_h/4,1,output);
return 0;
}
边栏推荐
- Mask wearing detection method based on yolov5
- 【juc学习之路第9天】屏障衍生工具
- PCB plug hole technology~
- Case of camera opening by tour
- Count the number of each character in the character
- MySQL empties table data
- 【生态伙伴】鲲鹏系统工程师培训
- Application of real estate management based on 3D GIS
- mysql 学习笔记-优化之SQL优化
- 名单揭晓 | 2021年度中国杰出知识产权服务团队
猜你喜欢

Flume interview questions

微软、哥伦比亚大学|GODEL:目标导向对话的大规模预训练

plantuml介绍与使用

Classify boost libraries by function

Aidl basic use

Application of real estate management based on 3D GIS

What is the difference between PMP and NPDP?

详解JMM

Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market

Why does blocprovider feel similar to provider?
随机推荐
详解Volatile关键字
为什么数字化转型战略必须包括持续测试?
Clean up system cache and free memory under Linux
linux下清理系统缓存并释放内存
EasyExcel 复杂数据导出
News classification based on LSTM model
What is the difference between PMP and NPDP?
MySQL数据库详细学习教程
flink sql 命令行 连接 yarn
【目标跟踪】|单目标跟踪指标
Why does blocprovider feel similar to provider?
上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
【juc学习之路第8天】Condition
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
flink sql-client 使用 对照并熟悉官方文档
Flume interview questions
详解JMM
91.(cesium篇)cesium火箭发射模拟
Recent public ancestor (LCA) online practices
MySQL的视图练习题