Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;-----------------------------------------------------------------------------
- ; tinyavi.as : tiny video writer for HSP by gocha
- ;
- ; * フルカラーウィンドウからの画像出力のみをサポート
- ; * 画像の圧縮形式をユーザに選択させることができます
- ; * 未対応の圧縮形式もありえます (VfWよくわかんない)
- ; * 音声など、他形式ストリームの追加は一切できません
- ; * 複数の映像を同時に処理することはできません
- ; * その他、偏屈な仕様は随所に見られるでしょう
- ;
- ;-----------------------------------------------------------------------------
- #ifndef TINYAVI_AS
- #define TINYAVI_AS
- #module tinyavi
- #const true 1
- #const false 0
- #const null 0
- #uselib "msvfw32.dll"
- #func ICCompressorChoose "ICCompressorChoose" int, int, sptr, sptr, sptr, sptr
- #func ICCompressorFree "ICCompressorFree" sptr
- #uselib "avifil32.dll"
- #func AVIFileInit "AVIFileInit"
- #func AVIFileOpen "AVIFileOpen" sptr, sptr, int, sptr
- #func AVIFileCreateStream "AVIFileCreateStream" sptr, sptr, sptr
- #func AVIMakeCompressedStream "AVIMakeCompressedStream" sptr, sptr, sptr, sptr
- #func AVIStreamSetFormat "AVIStreamSetFormat" sptr, int, sptr, int
- #func AVIStreamWrite "AVIStreamWrite" sptr, int, int, sptr, int, int, sptr, sptr
- #func AVIStreamRelease "AVIStreamRelease" sptr
- #func AVIFileRelease "AVIFileRelease" sptr
- #func AVIFileExit "AVIFileExit"
- ;---------------------------------------
- ; >> 初期化処理
- ;---------------------------------------
- #deffunc tvw_init
- avi_recording = false
- avi_fp = null
- avi_strm = null
- avi_cstrm = null
- avi_cv = null
- return
- ;---------------------------------------
- ; >> ビデオ出力開始 (兼コーデック選択)
- ;---------------------------------------
- #deffunc tvw_start str _p1, int _p2, int _p3
- mref bmscr, 67
- avi_path = _p1
- avi_rate = _p2
- if (_p3 == 0) {
- avi_scale = 1
- } else {
- avi_scale = _p3
- }
- avi_recording = false
- AVIFileInit
- dim avi_cv, 16 ; COMPVARS avi_cv; SecureZeroMemory(&avi_cv, sizeof(COMPVARS));
- avi_cv.0 = 64 ; avi_cv.cbSize = sizeof(COMPVARS);
- avi_cv.1 = 0x01 ; avi_cv.dwFlags = ICMF_COMPVARS_VALID;
- avi_cv.4 = 0x20424944 ; avi_cv.fccHandler = comptypeDIB;
- avi_cv.12 = -1 ; avi_cv.lQ = ICQUALITY_DEFAULT;
- dupptr bmscr_bi, bmscr.6, 40
- dim bi, 10 : memcpy bi, bmscr_bi, 40
- ; ICCompressorChoose(bmscr.hwnd, 0, &bi, null, &avi_cv, null);
- ICCompressorChoose hwnd, 0, varptr(bi), null, varptr(avi_cv), null
- if (stat == 0) {
- AVIFileExit
- return false
- }
- dim si, 35 ; AVISTREAMINFO si; SecureZeroMemory(&si, sizeof(AVISTREAMINFO));
- si.0 = 0x73646976 ; si.fccType = streamtypeVIDEO;
- ; si.1 = avi_cv.4 ; si.fccHandler = avi_cv.fccHandler;
- si.5 = avi_scale ; si.dwScale = avi_scale;
- si.6 = avi_rate ; si.dwRate = avi_rate;
- si.10 = bmscr.16 ; si.dwSuggestedBufferSize = bmscr.bmpsize;
- ; si.11 = -1 ; si.dwQuality = -1;
- ; si.13 = 0 ; si.rcFrame.left = 0;
- ; si.14 = 0 ; si.rcFrame.top = 0;
- ; si.15 = ginfo_winx ; si.rcFrame.right = ginfo_winx;
- ; si.16 = ginfo_winy ; si.rcFrame.bottom = ginfo_winy;
- ; si.19 = 0x45444956,0x4F ; si.szName = "VIDEO";
- dim opt, 11 ; AVICOMPRESSOPTIONS opt; SecureZeroMemory(&opt, sizeof(AVICOMPRESSOPTIONS));
- opt.0 = avi_cv.fccType ; opt.fccType = avi_cv.fccType
- opt.1 = avi_cv.4 ; opt.fccHandler = avi_cv.fccHandler
- opt.2 = avi_cv.10 ; opt.dwKeyFrameEvery = avi_cv.lKey;
- opt.3 = avi_cv.12 ; opt.dwQuality = cv.lQ;
- opt.4 = avi_cv.11 ; opt.dwBytesPerSecond = cv.lDataRate;
- opt.5 = 0 ; opt.dwFlags =
- if (avi_cv.11 > 0): opt.5 += 2 ; ((cv.lDataRate > 0) ? AVICOMPRESSF_DATARATE : 0) |
- if (avi_cv.10 > 0): opt.5 += 4 ; ((cv.lKey > 0) ? AVICOMPRESSF_KEYFRAMES : 0);
- opt.6 = null ; opt.lpFormat = null;
- opt.7 = 0 ; opt.cbFormat = 0;
- opt.8 = avi_cv.14 ; opt.lpParms = cv.lpState;
- opt.9 = avi_cv.15 ; opt.cbParms = cv.cbState;
- opt.10 = 0 ; opt.dwInterleaveEvery = 0;
- buf = ""
- notesel buf
- notesave avi_path
- noteunsel
- ; exist avi_path
- ; if (strsize >= 0) {
- ; delete avi_path
- ; }
- ; AVIFileOpen(&avi_fp, avi_path, OF_CREATE | OF_WRITE, null);
- AVIFileOpen varptr(avi_fp), avi_path, 0x1001, null
- if (stat != 0) {
- AVIFileExit
- return false
- }
- ; AVIFileCreateStream(avi_fp, &avi_strm, &si);
- AVIFileCreateStream avi_fp, varptr(avi_strm), varptr(si)
- if (stat != 0) {
- AVIFileRelease avi_fp
- AVIFileExit
- return false
- }
- ; AVIMakeCompressedStream(&avi_cstrm, avi_strm, &opt, null);
- AVIMakeCompressedStream varptr(avi_cstrm), avi_strm, varptr(opt), null
- ; if (stat != AVIERR_OK)
- if (stat != 0) {
- AVIStreamRelease avi_strm
- AVIFileRelease avi_fp
- AVIFileExit
- return false
- }
- ; AVIStreamSetFormat(avi_cstrm, 0, &bi, sizeof(BITMAPINFOHEADER));
- AVIStreamSetFormat avi_cstrm, 0, varptr(bi), 40
- if (stat != 0) {
- AVIStreamRelease avi_cstrm
- AVIStreamRelease avi_strm
- AVIFileRelease avi_fp
- AVIFileExit
- return false
- }
- avi_recording = true
- avi_pos = 0
- avi_size = 0
- sdim avi_vram, bmscr.16
- return true
- ;---------------------------------------
- ; >> ビデオに画像を出力
- ;---------------------------------------
- #deffunc tvw_add int _p1
- mref vram, 66
- mref bmscr, 67
- if (_p1 == 0) {
- frames = 1
- } else {
- frames = _p1
- }
- if (avi_recording) {
- repeat frames
- memcpy avi_vram, vram, bmscr.16
- ; AVIStreamWrite(avi_cstrm, avi_pos, 1, &avi_vram, bmscr.bmpsize, AVIIF_KEYFRAME, null, null);
- AVIStreamWrite avi_cstrm, avi_pos, 1, varptr(avi_vram), bmscr.16, 0x10, null, varptr(avi_written): avi_pos++
- avi_size += avi_written
- loop
- }
- return
- ;---------------------------------------
- ; >> ビデオ出力終了
- ;---------------------------------------
- #deffunc tvw_end
- if (avi_recording) {
- AVIStreamRelease avi_cstrm
- avi_cstrm = null
- AVIStreamRelease avi_strm
- avi_strm = null
- AVIFileRelease avi_fp
- avi_fp = null
- if (avi_cv != null) {
- ICCompressorFree varptr(avi_cv)
- avi_cv = null
- }
- AVIFileExit
- avi_recording = 0
- }
- return
- #global
- tvw_init
- #endif ; !defined(TINYAVI_AS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement