有一段mkv视频,想取的视频的时间长度,然后根据不同时间的 ,截取几张图,
例如 ,每隔10分钟,从视频截取一张。
请教 例子或者源码

解决方案 »

  1.   

    簡單截圖:function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall; external 'user32.dll' name 'PrintWindow'; 
    function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall; external 'user32.dll' name 'PrintWindow';<br/>procedure TForm1.Button2Click(Sender: TObject); 
    var 
      bmp : TBitmap; 
      wnd : cardinal; 
      rec : TRect; 
    begin 
      wnd := FindWindow(nil, '计算器'); // 查找窗口句柄,这里用计算器演示 
      GetWindowRect(wnd, rec); //获取到计算器窗口的举行 
      bmp := TBitmap.Create; 
      try 
        bmp.Width := rec.Right - rec.Left; 
        bmp.Height := rec.Bottom - rec.Top; 
        bmp.PixelFormat := pf24bit; 
        PrintWindow(wnd, bmp.Canvas.Handle, 0); 
        bmp.SaveToFile('cao.bmp'); 
      finally 
        bmp.Free; 
      end; 
    end;使用mediaPlay截視頻的例子; 
    unit   Unit1; interface   uses     Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,     Dialogs,   MPlayer,   ExtCtrls,   StdCtrls,   Menus;   type     TForm1   =   class(TForm)         MainMenu1:   TMainMenu;         filw1:   TMenuItem;         open1:   TMenuItem;         close1:   TMenuItem;         Button1:   TButton;         OpenDialog1:   TOpenDialog;         PaintBox1:   TPaintBox;         MediaPlayer1:   TMediaPlayer;         procedure   FormCreate(Sender:   TObject);         procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);         procedure   PaintBox1Paint(Sender:   TObject);         procedure   open1Click(Sender:   TObject);         procedure   Button1Click(Sender:   TObject);     private     imgbitmap:TBitmap;         {   Private   declarations   }     public         {   Public   declarations   }     end;   var     Form1:   TForm1;   implementation   {$R   *.dfm}   procedure   TForm1.FormCreate(Sender:   TObject); begin       imgbitmap:=TBitmap.Create;       imgbitmap.Height:=200;       imgbitmap.Width:=200;       imgbitmap.Canvas.Rectangle(0,0,200,200); end;   procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction); begin imgbitmap.Free; end;   procedure   TForm1.PaintBox1Paint(Sender:   TObject); begin PaintBox1.Canvas.CopyRect(Rect(0,0,200,200),imgbitmap.Canvas,Rect(0,0,200,200)); end;   procedure   TForm1.open1Click(Sender:   TObject); begin if   OpenDialog1.Execute   then begin MediaPlayer1.FileName:=OpenDialog1.FileName; MediaPlayer1.Open; MediaPlayer1.Display:=Form1; MediaPlayer1.DisplayRect:=Rect(10,10,200,200); end; end;   procedure   TForm1.Button1Click(Sender:   TObject); begin imgbitmap.Canvas.CopyRect(Rect(0,0,200,200),form1.Canvas,Rect(10,10,200,200)); PaintBox1.Invalidate; imgbitmap.SaveToFile( 'd:\1234567.bmp '); end;   end. 
      

  2.   

    可以截取layered窗口(包括透明窗口)的代码:  procedure CaptureScreen(AFileName: string);  
    const  
      CAPTUREBLT = $40000000;  
    var  
      hdcScreen: HDC;  
      hdcCompatible: HDC;  
      bmp: TBitmap;  
      hbmScreen: HBITMAP;  
    begin  
      hdcScreen := CreateDC(’DISPLAY’, nil, nil, nil);  
      hdcCompatible := CreateCompatibleDC(hdcScreen);  
      hbmScreen := CreateCompatibleBitmap(hdcScreen,  
        GetDeviceCaps(hdcScreen, HORZRES),  
        GetDeviceCaps(hdcScreen, VERTRES));  
      SelectObject(hdcCompatible, hbmScreen);  
      bmp := TBitmap.Create;  
      bmp.Handle := hbmScreen;  
      BitBlt(hdcCompatible,  
        0, 0,  
        bmp.Width, bmp.Height,  
        hdcScreen,  
        0, 0,  
        SRCCOPY or CAPTUREBLT);    bmp.SaveToFile(AFileName);  
      bmp.Free;  
      DeleteDC(hdcScreen);  
      DeleteDC(hdcCompatible);  
    end;  
    DX Primary Surface截图代码!包含DX8与DX9两个版本  ...  
    interface  {$DEFINE D3D9}  uses  
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
      Dialogs, StdCtrls, Buttons,  
    {$IFDEF D3D9}  
      // D3DX9, // use D3D to save surface  
      Direct3D9  
    {$ELSE}  
      // D3DX8, // use D3D to save surface  
      Direct3D8  
    {$ENDIF};  
    ...  
    procedure TForm1.BitBtn1Click(Sender: TObject);  
    // Capture screen through D3D.  
    var  
      BitsPerPixel: Byte;  
      {$IFDEF D3D9}  
      pD3D: IDirect3D9;  
      pSurface: IDirect3DSurface9;  
      g_pD3DDevice: IDirect3DDevice9;  
      {$ELSE}  
      pD3D: IDirect3D8;  
      pSurface: IDirect3DSurface8;  
      g_pD3DDevice: IDirect3DDevice8;  
      {$ENDIF}  
      D3DPP: TD3DPresentParameters;  
      ARect: TRect;  
      LockedRect: TD3DLockedRect;  
      BMP: TBitmap;  
      i, p: Integer;  
    begin  
      BitsPerPixel := GetDeviceCaps(Canvas.Handle, BITSPIXEL);  
      FillChar(d3dpp, SizeOf(d3dpp), 0);  
      D3DPP.Windowed := True;  
      D3DPP.Flags := D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;  
      D3DPP.SwapEffect := D3DSWAPEFFECT_DISCARD;  
      D3DPP.BackBufferWidth := Screen.Width;  
      D3DPP.BackBufferHeight := Screen.Height;  
      D3DPP.BackBufferFormat := D3DFMT_X8R8G8B8;  
      {$IFDEF D3D9}  
      pD3D := Direct3DCreate9(D3D_SDK_VERSION);  
      pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetDesktopWindow,  
        D3DCREATE_SOFTWARE_VERTEXPROCESSING, @D3DPP, g_pD3DDevice);  
      g_pD3DDevice.CreateOffscreenPlainSurface(Screen.Width, Screen.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, pSurface, nil);  
      g_pD3DDevice.GetFrontBufferData(0, pSurface);  
      {$ELSE}  
      pD3D := Direct3DCreate8(D3D_SDK_VERSION);  
      pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, GetDesktopWindow,  
        D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DPP, g_pD3DDevice);  
      g_pD3DDevice.CreateImageSurface(Screen.Width, Screen.Height, D3DFMT_A8R8G8B8, pSurface);  
      g_pD3DDevice.GetFrontBuffer(pSurface);  
      {$ENDIF}  
      // use D3D to save surface. Notes: D3DX%ab.dll is required!  
    //  D3DXSaveSurfaceToFile(’Desktop.bmp’, D3DXIFF_BMP, pSurface, nil,  nil);  
      // use Bitmap to save surface  
      ARect := Screen.DesktopRect;  
      pSurface.LockRect(LockedRect, @ARect, D3DLOCK_NO_DIRTY_UPDATE or D3DLOCK_NOSYSLOCK or D3DLOCK_READONLY);  
      BMP := TBitmap.Create;  
      BMP.Width := Screen.Width;  
      BMP.Height := Screen.Height;  
      case BitsPerPixel of  
        8:  BMP.PixelFormat := pf8bit;  
        16: BMP.PixelFormat := pf16bit;  
        24: BMP.PixelFormat := pf24bit;  
        32: BMP.PixelFormat := pf32bit;  
      end;  
      p := Cardinal(LockedRect.pBits);  
      for i := 0 to Screen.Height - 1 do  
        begin  
          CopyMemory(BMP.ScanLine[i], Ptr(p), Screen.Width * BitsPerPixel div 8);  
          p := p + LockedRect.Pitch;  
        end;  
      BMP.SaveToFile(’Desktop.bmp’);  
      BMP.Free;  
      pSurface.UnlockRect;  
    end;  以上DX截图代码,不需要额外的DLL支持,有DirectX 9.0即可
      

  3.   

    飞兄,,第一个 编译后 参数错误,
    第二个,MeidaPlay 不支持 视频格式第三和第四都没试。后来,我自己用了个 迅雷的APlayer, 解决了问题,,
    谢谢了