MCIで動画キャプチャ(手抜き)
マシンスペックが相当ないとコマ落ちしますし、
そもそもキャプチャと再生が同期していないのでフレームがずれます。
・・・あまり使えませんね。(^_^;)
とりあえず、できるぞ!ってだけの証明ですね。
#include "hspcv.as"
#uselib "user32.dll"
#cfunc GetDC "GetDC" int
#cfunc GetWindowDC "GetWindowDC" int
#func ReleaseDC "ReleaseDC" int,int
#cfunc GetForegroundWindow "GetForegroundWindow"
#cfunc GetDesktopWindow "GetDesktopWindow"
#func GetWindowRect "GetWindowRect" int,int
#func GetClientRect "GetClientRect" int,int
#uselib "gdi32.dll"
#func BitBlt "BitBlt" int,int,int,int,int,int,int,int,int
#define SRCCOPY 0x00CC0020
dialog "mpg;*.avi;*.wmv;*.asf;*.3gp;*.mp4;*.flv;*.mkv",16,"動画など"
//↑環境依存
if stat=0:end //未選択時に終了
x=0:y=0:ax=640:ay=480 //動画の左上座標、動画サイズ
fname=refstr //ファイル名を代入
mci "open \""+fname+"\" alias f type MPEGVideo"
if stat=-1 : dialog "Open err":end //オープンエラー
mci "window f handle "+hwnd //ウィンドウハンドルをMCIに送信
mci "put f destination at -10 -10 -1 -1" //ウィンドウに貼り付け(見えない位置に)
mci "play f repeat"
mci "stop f"
//オーバーレイ対策のため
mci "open \""+fname+"\" alias f2 type MPEGVideo"
if stat=-1 : dialog "Open err":end //オープンエラー
mci "window f2 handle "+hwnd //ウィンドウハンドルをMCIに送信
mci "put f2 destination at "+x+" "+y+" "+ax+" "+ay //ウィンドウに貼り付け
mci "play f2 repeat"
wait 100
cvbuffer 0,640,480
id0_hwnd=hwnd //ウィンドウ0のハンドルを保存
buffer 2,640,480
cvmakeavi "C:\\test.avi",-1,29.97,0
repeat 50 //50コマ拾ってみる
dim rect, 4 ; RECT構造体
GetClientRect id0_hwnd, varptr(rect)
sx = rect(2) - rect(0)
sy = rect(3) - rect(1)
BitBlt hdc, 0, 0, sx, sy, GetDC(id0_hwnd), 0, 0, SRCCOPY
ReleaseDC id1_hwnd, GetDC(id0_hwnd)
redraw
cvputimg 0
cvputavi
loop
cvendavi
//開放
mci "close all"