ffmpeg 内存 demo
来源:互联网 发布:seajs require其他js 编辑:程序博客网 时间:2024/04/30 03:53
CFile myfile;
VideoHead _VideoHead;//自己定义的数据结构
AVCodecContext * m_pavCoedContext;
AVCodec * m_pavCode;
AVFrame *m_pVidoeFrameRGB;
BYTE *m_buffer;
AVFrame *m_pVideoFrame;
m_pavCoedContext = avcodec_alloc_context();
m_pavCode=avcodec_find_decoder(CODEC_ID_MPEG4);
int wid=400;int hei=500;//初始设定的图像大小
m_pavCoedContext->width=wid;
m_pavCoedContext->height=hei;
m_pavCoedContext->codec_type=CODEC_TYPE_VIDEO;
m_pVideoFrame=avcodec_alloc_frame();
m_pVidoeFrameRGB=avcodec_alloc_frame();
if (m_pVidoeFrameRGB==NULL||m_pVideoFrame==NULL)
{
return;
}
int iBits=avpicture_get_size(PIX_FMT_RGB24,m_pavCoedContext->width,m_pavCoedContext->height);
m_buffer=new BYTE[iBits];
avpicture_fill((AVPicture*)m_pVidoeFrameRGB,m_buffer,
PIX_FMT_RGB24,m_pavCoedContext->width,
m_pavCoedContext->height);
if (avcodec_open(m_pavCoedContext,m_pavCode)<0)
{
return;
}
int _k=0;
int k= myfile.Open("c:\\m5.mp4",CFile::modeRead);
if (!k)
{
return ;
}
int iIndex =0;
while (myfile.Read(&_VideoHead,sizeof(VideoHead)))
{
int frameFinished=0;
int bytesRemaining=0;
int bytesDecoded=0;
uint8_t *rawData;
int _iBufferSize=_VideoHead.dwDataLen;
bytesRemaining=_iBufferSize;
BYTE* pInBuffer;pInBuffer=NULL;
pInBuffer=(BYTE *)malloc(_iBufferSize);
myfile.Read(pInBuffer,_iBufferSize);
switch(_VideoHead.iPlayType)
{
case 96://视频数据
if (bytesRemaining>0)
{
//memcpy(m_pVideoFrame->data,pInBuffer,bytesRemaining);
rawData=pInBuffer;
bytesDecoded=avcodec_decode_video(m_pavCoedContext,
m_pVideoFrame,
&frameFinished,rawData,bytesRemaining);
/*
解视频从rawdata 到pfrmae,解码器有pAVContect定义,bytesRemaining表示还剩多少数据没有解码,bytesDecoded表示此次解码的
数据长度,frameFinished表示这帧解码是否结束
*/
if(bytesDecoded < 0)
{
fprintf(stderr, "Error while decoding frame\n");
return ;
}
bytesRemaining-=bytesDecoded;
rawData+=bytesDecoded;
if (frameFinished)//解压结束
{
if (m_pavCoedContext->width!=wid||m_pavCoedContext->height!=hei)
{
wid=m_pavCoedContext->width;
hei=m_pavCoedContext->height;
delete m_buffer;
m_buffer=NULL;
int iBits=avpicture_get_size(PIX_FMT_RGB24,m_pavCoedContext->width,m_pavCoedContext->height);
m_buffer=new BYTE[iBits];
avpicture_fill((AVPicture*)m_pVidoeFrameRGB,m_buffer,
PIX_FMT_RGB24,m_pavCoedContext->width,
m_pavCoedContext->height);
}
img_convert((AVPicture *)m_pVidoeFrameRGB,PIX_FMT_RGB24,(AVPicture *)m_pVideoFrame,
m_pavCoedContext->pix_fmt,
m_pavCoedContext->width,m_pavCoedContext->height);
iIndex ++;
if (iIndex<100)
{
FILE *pFile;
char szFilename[32];
int y;
// Open file
sprintf(szFilename, "c:\\frame%d.raw", iIndex);
pFile=fopen(szFilename, "wb");
if(pFile==NULL)
return;
fwrite(m_pVidoeFrameRGB->data[0] , 1, m_pavCoedContext->width*3*m_pavCoedContext->height, pFile);
// Close file
fclose(pFile);
}
else
{
MessageBox("转化完成");
return;
}
}
}
break;
default:
break;
}
delete pInBuffer;
}
VideoHead _VideoHead;//自己定义的数据结构
AVCodecContext * m_pavCoedContext;
AVCodec * m_pavCode;
AVFrame *m_pVidoeFrameRGB;
BYTE *m_buffer;
AVFrame *m_pVideoFrame;
m_pavCoedContext = avcodec_alloc_context();
m_pavCode=avcodec_find_decoder(CODEC_ID_MPEG4);
int wid=400;int hei=500;//初始设定的图像大小
m_pavCoedContext->width=wid;
m_pavCoedContext->height=hei;
m_pavCoedContext->codec_type=CODEC_TYPE_VIDEO;
m_pVideoFrame=avcodec_alloc_frame();
m_pVidoeFrameRGB=avcodec_alloc_frame();
if (m_pVidoeFrameRGB==NULL||m_pVideoFrame==NULL)
{
return;
}
int iBits=avpicture_get_size(PIX_FMT_RGB24,m_pavCoedContext->width,m_pavCoedContext->height);
m_buffer=new BYTE[iBits];
avpicture_fill((AVPicture*)m_pVidoeFrameRGB,m_buffer,
PIX_FMT_RGB24,m_pavCoedContext->width,
m_pavCoedContext->height);
if (avcodec_open(m_pavCoedContext,m_pavCode)<0)
{
return;
}
int _k=0;
int k= myfile.Open("c:\\m5.mp4",CFile::modeRead);
if (!k)
{
return ;
}
int iIndex =0;
while (myfile.Read(&_VideoHead,sizeof(VideoHead)))
{
int frameFinished=0;
int bytesRemaining=0;
int bytesDecoded=0;
uint8_t *rawData;
int _iBufferSize=_VideoHead.dwDataLen;
bytesRemaining=_iBufferSize;
BYTE* pInBuffer;pInBuffer=NULL;
pInBuffer=(BYTE *)malloc(_iBufferSize);
myfile.Read(pInBuffer,_iBufferSize);
switch(_VideoHead.iPlayType)
{
case 96://视频数据
if (bytesRemaining>0)
{
//memcpy(m_pVideoFrame->data,pInBuffer,bytesRemaining);
rawData=pInBuffer;
bytesDecoded=avcodec_decode_video(m_pavCoedContext,
m_pVideoFrame,
&frameFinished,rawData,bytesRemaining);
/*
解视频从rawdata 到pfrmae,解码器有pAVContect定义,bytesRemaining表示还剩多少数据没有解码,bytesDecoded表示此次解码的
数据长度,frameFinished表示这帧解码是否结束
*/
if(bytesDecoded < 0)
{
fprintf(stderr, "Error while decoding frame\n");
return ;
}
bytesRemaining-=bytesDecoded;
rawData+=bytesDecoded;
if (frameFinished)//解压结束
{
if (m_pavCoedContext->width!=wid||m_pavCoedContext->height!=hei)
{
wid=m_pavCoedContext->width;
hei=m_pavCoedContext->height;
delete m_buffer;
m_buffer=NULL;
int iBits=avpicture_get_size(PIX_FMT_RGB24,m_pavCoedContext->width,m_pavCoedContext->height);
m_buffer=new BYTE[iBits];
avpicture_fill((AVPicture*)m_pVidoeFrameRGB,m_buffer,
PIX_FMT_RGB24,m_pavCoedContext->width,
m_pavCoedContext->height);
}
img_convert((AVPicture *)m_pVidoeFrameRGB,PIX_FMT_RGB24,(AVPicture *)m_pVideoFrame,
m_pavCoedContext->pix_fmt,
m_pavCoedContext->width,m_pavCoedContext->height);
iIndex ++;
if (iIndex<100)
{
FILE *pFile;
char szFilename[32];
int y;
// Open file
sprintf(szFilename, "c:\\frame%d.raw", iIndex);
pFile=fopen(szFilename, "wb");
if(pFile==NULL)
return;
fwrite(m_pVidoeFrameRGB->data[0] , 1, m_pavCoedContext->width*3*m_pavCoedContext->height, pFile);
// Close file
fclose(pFile);
}
else
{
MessageBox("转化完成");
return;
}
}
}
break;
default:
break;
}
delete pInBuffer;
}
- ffmpeg 内存 demo
- ffmpeg demo
- Ffmpeg demo
- ffmpeg hls demo
- FFMPEG编译并运行Demo
- 使用FFmpeg demo常见错误
- 仿照ffmpeg,命令设置demo
- ffmpeg内存释放问题
- ffmpeg 内存转码
- ffmpeg解码内存缓冲区
- ffmpeg 内存读写相关
- FFMPEG中的内存读取
- Linux_ 内存管理demo
- 生成内存溢出 demo
- 堆栈内存溢出demo
- ffmpeg 中hello-jni demo 示例
- ffmpeg for iOS,并调试iFrameExtractor demo
- PHP FFMpeg 生成缩略图通用类 demo
- Unable to execute dex: Java heap space 解决方案(如何为eclipse.int 添加内存)
- c语言指针数组
- 格式化XML文件,用msdn的工具
- PHP下,截取中文字符串
- WIN7 32位 破解 完美支持4G内存
- ffmpeg 内存 demo
- 谈VC++对象模型
- Powershell批量创建AD账户
- 超牛逼的芯片:无线数据传输速率将可高达30Gbps
- 计算机原理
- 选区的创建和编辑
- linux下LAMP环境搭建
- Mahout聚类分析
- webservice problems