科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道基础软件用AVIFile函数制做AVI文件基本步骤

用AVIFile函数制做AVI文件基本步骤

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

AVIFile,AVIFileOpen,AVIFileCreateStream....制做AVI文件,基相实现方法。

作者:海龙 来源:CSDN 2008年3月23日

关键字: AVI C++ C Linux

  • 评论
  • 分享微博
  • 分享邮件

AVIFileInit();

//创建AVI文件

if(AVIFileOpen(&m_aviFile,aviFileFullName,OF_CREATE|OF_WRITE,0))

{

MessageBox("create file '"+aviFileFullName+"' error");

return;

}

//设置视频流格式

AVISTREAMINFOW m_aviVideoStreamInfo;

m_aviVideoStreamInfo.fccType = streamtypeVIDEO;

m_aviVideoStreamInfo.fccHandler = 0;

m_aviVideoStreamInfo.dwFlags = 0;

m_aviVideoStreamInfo.dwCaps = 0;

m_aviVideoStreamInfo.wPriority = 0;

m_aviVideoStreamInfo.wLanguage = 0;

m_aviVideoStreamInfo.dwRate = 5; //每秒5帧

m_aviVideoStreamInfo.dwScale = 1;

m_aviVideoStreamInfo.dwQuality = 0;

m_aviVideoStreamInfo.dwSuggestedBufferSize = m_ImageWidth*m_ImageHeight*3;

m_aviVideoStreamInfo.dwStart = 0;

m_aviVideoStreamInfo.dwInitialFrames = 0;

m_aviVideoStreamInfo.dwSampleSize = 0;

m_aviVideoStreamInfo.rcFrame.left = 0;

m_aviVideoStreamInfo.rcFrame.top = 0;

m_aviVideoStreamInfo.rcFrame.right = m_ImageWidth;

m_aviVideoStreamInfo.rcFrame.bottom = m_ImageHeight;

m_aviVideoStreamInfo.dwEditCount = 0;

m_aviVideoStreamInfo.dwFormatChangeCount = 0;

strcpy((char *)m_aviVideoStreamInfo.szName,"ScreenCap.avi");

m_aviVideoStreamInfo.dwLength = 0;

//设置音频流格式

AVISTREAMINFOW m_aviAudioStreamInfo;

m_aviAudioStreamInfo.fccType = streamtypeAUDIO;

m_aviAudioStreamInfo.fccHandler = 0;

m_aviAudioStreamInfo.dwFlags = 0;

m_aviAudioStreamInfo.dwCaps = 0;

m_aviAudioStreamInfo.wPriority = 0;

m_aviAudioStreamInfo.wLanguage = 0;

m_aviAudioStreamInfo.dwScale = 1; //声道数

m_aviAudioStreamInfo.dwRate = 8000; //Hz

m_aviAudioStreamInfo.dwStart = 0;

m_aviAudioStreamInfo.dwInitialFrames = 0;

m_aviAudioStreamInfo.dwSuggestedBufferSize = m_dwBufferSize;

m_aviAudioStreamInfo.dwQuality = 0;

m_aviAudioStreamInfo.dwSampleSize = 1;

m_aviAudioStreamInfo.rcFrame.bottom = 0;

m_aviAudioStreamInfo.rcFrame.left = 0;

m_aviAudioStreamInfo.rcFrame.right = 0;

m_aviAudioStreamInfo.rcFrame.top = 0;

m_aviAudioStreamInfo.dwEditCount = 0;

m_aviAudioStreamInfo.dwFormatChangeCount = 0;

m_aviAudioStreamInfo.dwLength = 0;

//创建数据流

AVIFileCreateStream(m_aviFile,&m_aviVideoStream,(AVISTREAMINFO *)&m_aviVideoStreamInfo);

AVIFileCreateStream(m_aviFile,&m_aviAudioStream,(AVISTREAMINFO *)&m_aviAudioStreamInfo);

//写数据流

//-----视屏流

BITMAPINFOHEADER bmpInfoHdr;

bmpInfoHdr.biSize = sizeof(BITMAPINFOHEADER);

bmpInfoHdr.biWidth = m_ImageWidth;

bmpInfoHdr.biHeight = m_ImageHeight;

bmpInfoHdr.biBitCount = image1.GetBPP();

bmpInfoHdr.biCompression = BI_RGB;

bmpInfoHdr.biSizeImage = 0;

bmpInfoHdr.biClrImportant = 0;

bmpInfoHdr.biClrUsed = 0;

bmpInfoHdr.biXPelsPerMeter = 0;

bmpInfoHdr.biYPelsPerMeter = 0;

bmpInfoHdr.biPlanes = 1;

//设置帧格式

AVIStreamSetFormat(m_aviVideoStream,m_aviVideoFrames,&bmpInfoHdr,sizeof(bmpInfoHdr));

//写数据

AVIStreamWrite(m_aviVideoStream,m_aviVideoFrames ,1,(LPBYTE) buffer,size ,AVIIF_KEYFRAME,NULL,NULL);

m_aviVideoFrames++;

///-------------

//----音频流

WAVEFORMAT waveFormat;

waveFormat.nAvgBytesPerSec = m_Format.nAvgBytesPerSec;

waveFormat.nBlockAlign = m_Format.nBlockAlign;

waveFormat.nChannels = m_Format.nChannels;

waveFormat.nSamplesPerSec = m_Format.nSamplesPerSec;

waveFormat.wFormatTag = m_Format.wFormatTag;

//设置音频格式

AVIStreamSetFormat(m_aviAudioStream,m_aviAudioFrames,&m_Format,sizeof(m_Format));

//写数据

AVIStreamWrite(m_aviAudioStream,m_aviAudioFrames ,1,(LPBYTE)pBuffer,pWaveHdr->dwBytesRecorded ,AVIIF_KEYFRAME,NULL,NULL);

m_aviAudioFrames++;

///-----------

//释放数据流及文件

if(m_aviVideoStream)

{

m_aviVideoStream->Release();

m_aviVideoStream = NULL;

}

if(m_aviAudioStream)

{

m_aviAudioStream->Release();

m_aviAudioStream = NULL;

}

if(m_aviFile)

{

m_aviFile->Release();

m_aviFile = NULL;

}

AVIFileExit();

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章