DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

VFrame可以被解釋為一個AVPicture來填充 data 和 linesize 欄位。 填充這些欄位最簡單的方法是使用 avpicture_fill 函數。

要填充AVFrame和V 緩衝區的Y,它取決於輸入數據和想要使用框架( 要寫入 AVFrame ) 。 或者保留副本) 。

如果緩衝區足夠大( 至少為 linesize[0] * height 數據,則為), linesize[1 or 2] * height/2 對於u/v 數據,可以直接使用輸入緩衝區:


//Initialize the AVFrame


AVFrame* frame = avcodec_alloc_frame();


frame->width = width;


frame->height = height;


frame->format = AV_PIX_FMT_YUV420P;



//Initialize frame->linesize


avpicture_fill((AVPicture*)frame, NULL, frame->format, frame->width, frame->height);



//Set frame->data pointers manually


frame->data[0] = inputBufferY;


frame->data[1] = inputBufferU;


frame->data[2] = inputBufferV;



//Or if your Y, U, V buffers are contiguous and have the correct size, simply use:


//avpicture_fill((AVPicture*)frame, inputBufferYUV, frame->format, frame->width, frame->height);



如果需要操作輸入數據,則需要計算所需的緩衝區大小,並在其中複製輸入數據。


//Initialize the AVFrame


AVFrame* frame = avcodec_alloc_frame();


frame->width = width;


frame->height = height;


frame->format = AV_PIX_FMT_YUV420P;



//Allocate a buffer large enough for all data


int size = avpicture_get_size(frame->format, frame->width, frame->height);


uint8_t* buffer = (uint8_t*)av_malloc(size);



//Initialize frame->linesize and frame->data pointers


avpicture_fill((AVPicture*)frame, buffer, frame->format, frame->width, frame->height);



//Copy data from the 3 input buffers


memcpy(frame->data[0], inputBufferY, frame->linesize[0] * frame->height);


memcpy(frame->data[1], inputBufferU, frame->linesize[1] * frame->height/2);


memcpy(frame->data[2], inputBufferV, frame->linesize[2] * frame->height/2);



完成AVFrame之後,不要忘了用 av_frame_free ( 以及 av_malloc 分配的任何緩衝區) 釋放它。

posted on   DoubleLi  阅读(218)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2014-07-23 Darwin Streaming server 的 Task 类
2013-07-23 信息系统项目管理师 高级 初始 寻挂靠
点击右上角即可分享
微信分享提示