Advertisement
gocha

tinyavi.as : tiny video writer for HSP by gocha

May 2nd, 2013
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. ;-----------------------------------------------------------------------------
  2. ; tinyavi.as : tiny video writer for HSP by gocha
  3. ;
  4. ; * フルカラーウィンドウからの画像出力のみをサポート
  5. ; * 画像の圧縮形式をユーザに選択させることができます
  6. ; * 未対応の圧縮形式もありえます (VfWよくわかんない)
  7. ; * 音声など、他形式ストリームの追加は一切できません
  8. ; * 複数の映像を同時に処理することはできません
  9. ; * その他、偏屈な仕様は随所に見られるでしょう
  10. ;
  11. ;-----------------------------------------------------------------------------
  12.  
  13.  
  14. #ifndef TINYAVI_AS
  15. #define TINYAVI_AS
  16.  
  17.  
  18. #module tinyavi
  19.  
  20. #const true 1
  21. #const false 0
  22. #const null 0
  23.  
  24. #uselib "msvfw32.dll"
  25. #func ICCompressorChoose "ICCompressorChoose" int, int, sptr, sptr, sptr, sptr
  26. #func ICCompressorFree "ICCompressorFree" sptr
  27. #uselib "avifil32.dll"
  28. #func AVIFileInit "AVIFileInit"
  29. #func AVIFileOpen "AVIFileOpen" sptr, sptr, int, sptr
  30. #func AVIFileCreateStream "AVIFileCreateStream" sptr, sptr, sptr
  31. #func AVIMakeCompressedStream "AVIMakeCompressedStream" sptr, sptr, sptr, sptr
  32. #func AVIStreamSetFormat "AVIStreamSetFormat" sptr, int, sptr, int
  33. #func AVIStreamWrite "AVIStreamWrite" sptr, int, int, sptr, int, int, sptr, sptr
  34. #func AVIStreamRelease "AVIStreamRelease" sptr
  35. #func AVIFileRelease "AVIFileRelease" sptr
  36. #func AVIFileExit "AVIFileExit"
  37.  
  38. ;---------------------------------------
  39. ; >> 初期化処理
  40. ;---------------------------------------
  41. #deffunc tvw_init
  42. avi_recording = false
  43.  
  44. avi_fp = null
  45. avi_strm = null
  46. avi_cstrm = null
  47. avi_cv = null
  48. return
  49.  
  50. ;---------------------------------------
  51. ; >> ビデオ出力開始 (兼コーデック選択)
  52. ;---------------------------------------
  53. #deffunc tvw_start str _p1, int _p2, int _p3
  54. mref bmscr, 67
  55.  
  56. avi_path = _p1
  57. avi_rate = _p2
  58. if (_p3 == 0) {
  59. avi_scale = 1
  60. } else {
  61. avi_scale = _p3
  62. }
  63.  
  64. avi_recording = false
  65. AVIFileInit
  66.  
  67. dim avi_cv, 16 ; COMPVARS avi_cv; SecureZeroMemory(&avi_cv, sizeof(COMPVARS));
  68. avi_cv.0 = 64 ; avi_cv.cbSize = sizeof(COMPVARS);
  69. avi_cv.1 = 0x01 ; avi_cv.dwFlags = ICMF_COMPVARS_VALID;
  70. avi_cv.4 = 0x20424944 ; avi_cv.fccHandler = comptypeDIB;
  71. avi_cv.12 = -1 ; avi_cv.lQ = ICQUALITY_DEFAULT;
  72.  
  73. dupptr bmscr_bi, bmscr.6, 40
  74. dim bi, 10 : memcpy bi, bmscr_bi, 40
  75.  
  76. ; ICCompressorChoose(bmscr.hwnd, 0, &bi, null, &avi_cv, null);
  77. ICCompressorChoose hwnd, 0, varptr(bi), null, varptr(avi_cv), null
  78. if (stat == 0) {
  79. AVIFileExit
  80. return false
  81. }
  82.  
  83. dim si, 35 ; AVISTREAMINFO si; SecureZeroMemory(&si, sizeof(AVISTREAMINFO));
  84. si.0 = 0x73646976 ; si.fccType = streamtypeVIDEO;
  85. ; si.1 = avi_cv.4 ; si.fccHandler = avi_cv.fccHandler;
  86. si.5 = avi_scale ; si.dwScale = avi_scale;
  87. si.6 = avi_rate ; si.dwRate = avi_rate;
  88. si.10 = bmscr.16 ; si.dwSuggestedBufferSize = bmscr.bmpsize;
  89. ; si.11 = -1 ; si.dwQuality = -1;
  90. ; si.13 = 0 ; si.rcFrame.left = 0;
  91. ; si.14 = 0 ; si.rcFrame.top = 0;
  92. ; si.15 = ginfo_winx ; si.rcFrame.right = ginfo_winx;
  93. ; si.16 = ginfo_winy ; si.rcFrame.bottom = ginfo_winy;
  94. ; si.19 = 0x45444956,0x4F ; si.szName = "VIDEO";
  95. dim opt, 11 ; AVICOMPRESSOPTIONS opt; SecureZeroMemory(&opt, sizeof(AVICOMPRESSOPTIONS));
  96. opt.0 = avi_cv.fccType ; opt.fccType = avi_cv.fccType
  97. opt.1 = avi_cv.4 ; opt.fccHandler = avi_cv.fccHandler
  98. opt.2 = avi_cv.10 ; opt.dwKeyFrameEvery = avi_cv.lKey;
  99. opt.3 = avi_cv.12 ; opt.dwQuality = cv.lQ;
  100. opt.4 = avi_cv.11 ; opt.dwBytesPerSecond = cv.lDataRate;
  101. opt.5 = 0 ; opt.dwFlags =
  102. if (avi_cv.11 > 0): opt.5 += 2 ; ((cv.lDataRate > 0) ? AVICOMPRESSF_DATARATE : 0) |
  103. if (avi_cv.10 > 0): opt.5 += 4 ; ((cv.lKey > 0) ? AVICOMPRESSF_KEYFRAMES : 0);
  104. opt.6 = null ; opt.lpFormat = null;
  105. opt.7 = 0 ; opt.cbFormat = 0;
  106. opt.8 = avi_cv.14 ; opt.lpParms = cv.lpState;
  107. opt.9 = avi_cv.15 ; opt.cbParms = cv.cbState;
  108. opt.10 = 0 ; opt.dwInterleaveEvery = 0;
  109.  
  110. buf = ""
  111. notesel buf
  112. notesave avi_path
  113. noteunsel
  114. ; exist avi_path
  115. ; if (strsize >= 0) {
  116. ; delete avi_path
  117. ; }
  118.  
  119. ; AVIFileOpen(&avi_fp, avi_path, OF_CREATE | OF_WRITE, null);
  120. AVIFileOpen varptr(avi_fp), avi_path, 0x1001, null
  121. if (stat != 0) {
  122. AVIFileExit
  123. return false
  124. }
  125.  
  126. ; AVIFileCreateStream(avi_fp, &avi_strm, &si);
  127. AVIFileCreateStream avi_fp, varptr(avi_strm), varptr(si)
  128. if (stat != 0) {
  129. AVIFileRelease avi_fp
  130. AVIFileExit
  131. return false
  132. }
  133.  
  134. ; AVIMakeCompressedStream(&avi_cstrm, avi_strm, &opt, null);
  135. AVIMakeCompressedStream varptr(avi_cstrm), avi_strm, varptr(opt), null
  136. ; if (stat != AVIERR_OK)
  137. if (stat != 0) {
  138. AVIStreamRelease avi_strm
  139. AVIFileRelease avi_fp
  140. AVIFileExit
  141. return false
  142. }
  143.  
  144. ; AVIStreamSetFormat(avi_cstrm, 0, &bi, sizeof(BITMAPINFOHEADER));
  145. AVIStreamSetFormat avi_cstrm, 0, varptr(bi), 40
  146. if (stat != 0) {
  147. AVIStreamRelease avi_cstrm
  148. AVIStreamRelease avi_strm
  149. AVIFileRelease avi_fp
  150. AVIFileExit
  151. return false
  152. }
  153.  
  154. avi_recording = true
  155. avi_pos = 0
  156. avi_size = 0
  157. sdim avi_vram, bmscr.16
  158. return true
  159.  
  160. ;---------------------------------------
  161. ; >> ビデオに画像を出力
  162. ;---------------------------------------
  163. #deffunc tvw_add int _p1
  164. mref vram, 66
  165. mref bmscr, 67
  166.  
  167. if (_p1 == 0) {
  168. frames = 1
  169. } else {
  170. frames = _p1
  171. }
  172.  
  173. if (avi_recording) {
  174. repeat frames
  175. memcpy avi_vram, vram, bmscr.16
  176. ; AVIStreamWrite(avi_cstrm, avi_pos, 1, &avi_vram, bmscr.bmpsize, AVIIF_KEYFRAME, null, null);
  177. AVIStreamWrite avi_cstrm, avi_pos, 1, varptr(avi_vram), bmscr.16, 0x10, null, varptr(avi_written): avi_pos++
  178. avi_size += avi_written
  179. loop
  180. }
  181. return
  182.  
  183. ;---------------------------------------
  184. ; >> ビデオ出力終了
  185. ;---------------------------------------
  186. #deffunc tvw_end
  187. if (avi_recording) {
  188. AVIStreamRelease avi_cstrm
  189. avi_cstrm = null
  190. AVIStreamRelease avi_strm
  191. avi_strm = null
  192. AVIFileRelease avi_fp
  193. avi_fp = null
  194.  
  195. if (avi_cv != null) {
  196. ICCompressorFree varptr(avi_cv)
  197. avi_cv = null
  198. }
  199. AVIFileExit
  200.  
  201. avi_recording = 0
  202. }
  203. return
  204.  
  205. #global
  206. tvw_init
  207.  
  208. #endif ; !defined(TINYAVI_AS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement