当前位置:网站首页>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;
}
边栏推荐
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
- Application of real estate management based on 3D GIS
- plantuml介绍与使用
- leetcode - 287. 寻找重复数
- Matlab traverses images, string arrays and other basic operations
- [intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
- Use of vscode
- 互联网的智算架构设计
- EasyExcel 复杂数据导出
- Simple interactive operation of electron learning (III)
猜你喜欢
[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
MySQL series transaction log redo log learning notes
Relationship and difference between enterprise architecture and project management
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
leetcode - 287. 寻找重复数
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
对象内存布局
[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
Icml2022 | interventional contrastive learning based on meta semantic regularization
I received a letter from CTO inviting me to interview machine learning engineer
随机推荐
Business visualization - make your flowchart'run'up
Simple interactive operation of electron learning (III)
CIO's discussion and Analysis on the definition of high-performance it team
二叉树的基本操作
MySQL empties table data
Go - exe corresponding to related dependency
为什么数字化转型战略必须包括持续测试?
The leader of the cloud native theme group of beacon Committee has a long way to go!
Why does blocprovider feel similar to provider?
【MySQL】索引的创建、查看和删除
Mask wearing detection method based on yolov5
Little p weekly Vol.11
收到一封CTO来信,邀约面试机器学习工程师
flink sql 命令行 连接 yarn
Recent public ancestor (LCA) online practices
快乐数[环类问题之快慢指针]
Classify boost libraries by function
Getting started with the lockust series
TOPS,处理器运算能力单位、每秒钟可进行一万亿次
Mysql——》MyISAM存储引擎的索引