FFMpeg显示视频图像时候的内存问题

圣诞老人123 2011-01-28 05:31:06
我启动一个线程做图像解码 但是内存不断飙升 请大牛看看我代码的问题 谢谢了

---------------------------------------------------------线程代码--------------------------------------------


int video_Decode( void* ptr )
{
PlayerData* data = ( PlayerData* )ptr;
AVPacket pk1;
AVPacket* packet = &pk1;
AVFrame* frame;
int complete;
int len01;
double pts;

SDL_Overlay *bmp;
SDL_Rect rect;

frame = avcodec_alloc_frame();

if( data == NULL )
return -1;
data->pVCodecCtx->get_buffer = our_get_buffer;
data->pVCodecCtx->release_buffer = our_release_buffer;

for( ;; )
{
if( packet_queue_get( &(data->videoq), packet , 1 ) < 0 )
{
break;
}

global_video_pkt_pts = packet->pts;
len01 = avcodec_decode_video( data->pVCodecCtx, frame, &complete, packet->data, packet->size );

if( frame->opaque && *(uint64_t*)frame->opaque != AV_NOPTS_VALUE)
{
pts = *(uint64_t *)frame->opaque;
}else
{
pts = 0;
}

pts *= av_q2d( data->pVcodecstm->time_base );

if( complete )
{
bmp = SDL_CreateYUVOverlay(data->pVCodecCtx->width,
data->pVCodecCtx->height,
SDL_YV12_OVERLAY,
data->screen);
SDL_LockYUVOverlay(bmp);

AVPicture pict;
pict.data[0] = bmp->pixels[0];
pict.data[1] = bmp->pixels[2];
pict.data[2] = bmp->pixels[1];

pict.linesize[0] = bmp->pitches[0];
pict.linesize[1] = bmp->pitches[2];
pict.linesize[2] = bmp->pitches[1];

// Convert the image into YUV format that SDL uses
SwsContext *ctx = NULL;
ctx = sws_getContext(
data->pVCodecCtx->width,
data->pVCodecCtx->height,
data->pVCodecCtx->pix_fmt,
data->pVCodecCtx->width,
data->pVCodecCtx->height,
PIX_FMT_YUV420P,
SWS_BICUBIC, NULL, NULL, NULL);
sws_scale( ctx,frame->data,frame->linesize,0,data->pVCodecCtx->height,((AVPicture*)&pict)->data,((AVPicture*)&pict)->linesize);

SDL_UnlockYUVOverlay(bmp);
/**/
rect.x = 0;
rect.y = 0;
rect.w = data->pVCodecCtx->width * 2;
rect.h = data->pVCodecCtx->height * 2;
SDL_DisplayYUVOverlay(bmp, &rect);

sws_freeContext( ctx );
SDL_free( bmp );
SDL_free( &pict );

//得到一张frame转为picture
/**/
}


av_free_packet( packet );
}
av_free( frame );
return 0;
}
...全文
390 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
圣诞老人123 2011-01-30
  • 打赏
  • 举报
回复
找到原因了 释放layout失败 SDL_FreeYUVOverlay( bmp );对了我用的不是VC环境 在codeblocks里 怎么看是否有内存泄露的
CyberLogix 2011-01-30
  • 打赏
  • 举报
回复
你参考FFPLAY的代码,看那部分分配的内存没有释放
圣诞老人123 2011-01-30
  • 打赏
  • 举报
回复
恩 是这个原因但是我看不出来我这段代码哪里没有释放
CyberLogix 2011-01-30
  • 打赏
  • 举报
回复
codeblocks没用过,呵呵
CyberLogix 2011-01-29
  • 打赏
  • 举报
回复
内存不断飙升可能是内存没有及时释放导致。

2,542

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧