CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  图形处理/算法

怎么提取AVI文件的第一帧图象

楼主killin1(菜鸟)2005-04-03 11:42:34 在 VC/MFC / 图形处理/算法 提问

通商 问题点数:100、回复次数:1Top

1 楼killin(killin)回复于 2005-04-03 11:44:47 得分 100

function   GetAviFrame(AviFilename   :   String;   Index:   Integer;   var   bmp:   TBitmap):  
  boolean;  
  说明:  
  avifilename:   avi文件名  
  index:   要取的帧号  
  bmp:   存放返回图象,   如果为nil则自动建立一个bitmap.   如果存在则按bmp定义的大小存放stretch后的图象.  
  返回值:   true   成功,   false   失败  
  现在的问题是编译没有问题,但是我用一个Image控件显示得到的BMP图片时,却发现根本得不到第一帧的  
  图片,请DELPHI高手帮忙!!!,多谢!!!  
  函数代码如下:  
  unit   Unit_GetAviFrame;  
  interface  
  uses   windows,   graphics;  
  const  
      streamtypeAUDIO   :   longint   =   $73647561;  
      streamtypeVIDEO   :   longint   =   $73646976;  
  type  
      TAVIStream   =   record  
          fccType         :   longint;  
          fccHandler   :   longint;  
          dwFlags         :   longint;  
          dwCaps           :   longint;  
          wPriority     :   word;  
          wLanguage     :   word;  
          dwScale         :   longint;  
          dwRate           :   longint;  
          dwStart         :   longint;  
          dwLength       :   longint;  
          dwInitialFrames   :   longint;  
          dwSuggestedBufferSize   :   longint;  
          dwQuality         :   longint;  
          dwSampleSize   :   longint;  
          rcFrame             :   TRect;  
          dwEditCount     :   longint;  
          dwFormatChangeCount   :   longint;  
          Name   :   array   [0..64]   of   char;  
      end;  
      PAVIStream   =   ^TAVIStream;  
      PAVIFile   =   pointer;  
      TAVIFileInfo   =   record  
          dwMaxBytesPerSec   :   longint;  
          dwFlags                     :   longint;  
          dwCaps                       :   longint;  
          dwStreams                 :   longint;  
          dwSuggestedBufferSize   :   longint;  
          dwWidth                     :   longint;  
          dwHeight                   :   longint;  
          dwScale                     :   longint;  
          dwRate                       :   longint;  
          dwLength                   :   longint;  
          dwEditCount             :   longint;  
          szFileType               :   array[0..63]   of   char;  
      end;  
      PAVIFileInfo   =   ^TAVIFileInfo;  
      TAVIStreamInfo   =   record  
          fccType                               :   longint;  
          fccHandler                         :   longint;  
          dwFlags                               :   longint;  
          dwCaps                                 :   longint;  
          wPriority                           :   word;  
          wLanguage                           :   word;  
          dwScale                               :   longint;  
          dwRate                                 :   longint;  
          dwStart                               :   longint;  
          dwLength                             :   longint;  
          dwInitialFrames               :   longint;  
          dwSuggestedBufferSize   :   longint;  
          dwQuality                           :   longint;  
          dwSampleSize                     :   longint;  
          rcFrame                               :   TRect;  
          dwEditCount                       :   longint;  
          dwFormatChangeCount       :   longint;  
          szName     :   array[0..63]   of   char;  
      end;  
      PAVIStreamInfo   =   ^TAVIStreamInfo;  
  function     AVIFileOpen(avifile   :   pointer;   filename   :   pchar;   mode   :   integer;  
                                        CLSID   :   pointer)   :   integer;   stdcall;   external   'avifil32.dll  
  '   index   16;  
  function     AVIFileRelease(avifile   :   pointer)   :   longint;   stdcall;   external   'avif  
  il32.dll'   index   20;  
  function     AVIFileGetStream(avifile   :   pointer;   avistream   :   PAVIStream;  
   
   
                                                        streamtype   :   longint;   lParam   :   longint)   :   integer;  
  stdcall;  
  external   'avifil32.dll'   index   11;  
  function     AVIStreamGetFrameOpen(avistream   :   PAVIStream;   bitmapwanted   :   pointer  
  )   :   pointer;  
  stdcall;   external   'avifil32.dll'   index   42;  
  procedure   AVIStreamGetFrameClose(pget   :   pointer);   stdcall;   external   'avifil32.  
  dll'   index   41;  
  function     AVIStreamGetFrame(getframe   :   pointer;   position   :   longint)   :   pointer;  
    stdcall;  
  external   'avifil32.dll'   index   40;  
  procedure   AVIStreamRelease(avistream   :   PAVIStream);   stdcall;   external   'avifil3  
  2.dll'   index   53;  
  function     AVIStreamInfo(pstream   :   PAVIStream;   psi   :   PAVISTREAMINFO;   lsize   :   lo  
  ngint)   :  
  integer;   stdcall;   external   'avifil32.dll'   index   44;  
  function   GetAviFrame(AviFilename   :   String;   Index:   Integer;   var   bmp:   TBitmap):  
  boolean;  
  implementation  
  function   GetAviFrame(AviFilename   :   String;   Index:   Integer;   var   bmp:   TBitmap):  
  boolean;  
  var  
      FAviFile   :   Pointer;  
      FVideoStream   :   Pointer;  
      FGetFrame   :   Pointer;  
      info   :   TAVIStreamInfo;  
      FFrameWidth,   FFrameHeight   :   Integer;  
      FStartFrame,   FStopFrame   :   Integer;  
      image   :   pointer;  
      imagestart   :   Integer;  
  begin  
      result   :=   false;  
      if   (AVIFileOpen(@favifile,   pchar(AviFileName),   0,   nil)   <>   0)   then  
          exit;  
      if   (AVIFileGetStream(favifile,   @fvideostream,   streamtypeVIDEO,   0)   <>   0)   then  
     
      begin  
              AVIFileRelease(favifile);  
              exit;  
      end;  
      AVIStreamInfo(fvideostream,   @info,   sizeof(info));  
      with   info   do  
      begin  
              fFrameWidth   :=   rcframe.right   -   rcframe.left;  
              fFrameHeight   :=   rcframe.bottom   -   rcframe.top;  
              fStartFrame   :=   dwStart;  
              fStopFrame   :=   dwLength   -   1;  
      end;  
      if   (index   <fstartframe)   or   (index   >   fstopframe)   then  
      begin  
              AVIStreamRelease(fvideostream);  
              AVIFileRelease(favifile);  
              exit;  
      end;  
      fgetframe   :=   AVIStreamGetFrameOpen(fvideostream,   nil);  
      if   (fgetframe   =   nil)     then  
      begin  
              AVIStreamRelease(fvideostream);  
              AVIFileRelease(favifile);  
              exit;  
      end;  
        image   :=   AVIStreamGetFrame(fGetFrame,   Index);  
      if   assigned(image)   then  
      begin  
              if   not   assigned(bmp)   then  
              begin  
                  bmp   :=   tbitmap.create;  
                  bmp.width   :=   fframewidth;  
                  bmp.height   :=   fframeheight;  
              end  
              else   if   bmp.empty   then  
              begin  
                    bmp.width   :=   fframewidth;  
                    bmp.height   :=   fframeheight;  
              end;  
                imagestart   :=   TBitmapInfoHeader(image^).biSize   +  
                                                TBitmapInfoHeader(image^).biClrUsed   *   4;  
              StretchDIBits(bmp.canvas.handle,   0,   0,   bmp.width,   bmp.height,  
                                                0,   0,   fframewidth,   fframeheight,  
                                                pchar(image)   +   imagestart,  
                                                TBitmapInfo(image^),   0,   SRCCOPY);  
              result   :=   true;  
      end;  
      AVIStreamGetFrameClose(fgetframe);  
      AVIStreamRelease(fvideostream);  
      AVIFileRelease(favifile);  
  end;  
  end.  
   
  //显示图片的代码如下(在空白窗体上添加一个Image控件和Button控件)  
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
    bmp   :   Tbitmap;  
  begin  
    bmp   :=   Tbitmap.Create;  
    if   (Unit_GetAviFrame.GetAviFrame('2.avi',1000,bmp)   =   True)   then  
    begin  
    image1.Picture.Bitmap.Assign(bmp);  
    Image1.Refresh;  
    showmessage('ok');  
    end;  
    bmp.Free;  
  end;  
  Top

相关问题

  • 怎样打开图象数据文件,提取数据
  • 关于从avi中提取bmp图象的问题
  • 求救:如何从mpeg文件中提取一幅一幅的图象?
  • 为什么用Media Player 播放avi文件的时候没法出图象?
  • 工具推荐:资源提取器(可提取icl、exe、dll等文件中的ico、bmp、avi、html、gif、jpg)
  • 图象文件的保存
  • 如何提取文件名?
  • [Perl]文件的提取
  • 提取异地文件
  • 在VC6.0里对AVI文件格式的处理 怎么对一个给定的AVI文件得到当前帧的图象数据流? (在线等)

关键词

  • longint
  • fvideostream
  • favifile
  • rcframe
  • bmp
  • avifilerelease
  • fframeheight
  • fframewidth
  • fgetframe
  • 图象

得分解答快速导航

  • 帖主:killin1
  • killin

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo