当前位置:网站首页>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;
}
边栏推荐
- AirServer2022最新版功能介绍及下载
- The leader of the cloud native theme group of beacon Committee has a long way to go!
- Flume interview questions
- Application of real estate management based on 3D GIS
- Introduction and download of the latest version of airserver2022
- 【MySQL】索引的创建、查看和删除
- Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
- ICML2022 | 基于元语义正则化的介入性对比学习
- #yyds干货盘点# 解决名企真题:扭蛋机
- Matlab traverses images, string arrays and other basic operations
猜你喜欢

"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition

首席信息官对高绩效IT团队定义的探讨和分析

Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue

plantuml介绍与使用

Is PMP certificate really useful?

Indicator trap: seven KPI mistakes that it leaders are prone to make

Go - exe corresponding to related dependency

What is the difference between PMP and NPDP?

从零开始学 MySQL —数据库和数据表操作

配置筛选机
随机推荐
100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
RestTemplate 远程调用工具类
Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
MySQL的视图练习题
AIDL基本使用
Simple interactive operation of electron learning (III)
[deep learning] use deep learning to monitor your girlfriend's wechat chat?
【单体】流辰信息I-BPSv3服务器推荐配置
【MySQL】索引的创建、查看和删除
记录一次spark on yarn 任务报错 Operation category READ is not supported in state standby
Clean up system cache and free memory under Linux
二叉树的基本操作
One of the basic learning of function
Icml2022 | interventional contrastive learning based on meta semantic regularization
flink sql 命令行 连接 yarn
Gaussdb (DWS) active prevention and troubleshooting
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
What is the difference between PMP and NPDP?
LC501. 二叉搜索树中的众数
按照功能对Boost库进行分类