BlitzMovie

Blitz3D Forums/Blitz3D Userlibs/BlitzMovie

This lib from Harriman Software is called BlitzMovie. Harriman software seems down, but the need for more compatibility, speed, and more capoablitities for video playback in Blitz is still there.

Version 1.3 of BlitzMovie is available here: http://www.melog.ch/dl/blitzmovie1.3-beta.zip

Version 2.0 exists but very hard to find.

Other threads related to BlitzMovie:
http://www.blitzbasic.com/Community/posts.php?topic=74408
http://www.blitzbasic.com/Community/posts.php?topic=56354
http://www.blitzbasic.com/Community/posts.php?topic=44383 BlitzMovie 1.2 release and map editor news
http://www.blitzbasic.com/Community/posts.php?topic=43958 Pause / resume video playback

Code example for version 1.3 on an image:
AppTitle "BlitzMovie Decode To Blitz3D Image Demo (C) 2005 Harriman Software"
; www.harrimansoftware.com/blitzmovie

Graphics3D 1024, 768, 32, 1
gr_w = GraphicsWidth()
gr_h = GraphicsHeight()

SetBuffer BackBuffer()

; init myResizeImage(img,w,h)
Global myResizeCamera=CreateCamera()
CameraClsMode myResizeCamera,0,1
Global myResizeQuad = CreateQuad()
Global myResizeTex = CreateTexture(1024,1024,256 Or 16 Or 32)
EntityTexture myResizeQuad, myResizeTex
EntityFX myResizeQuad,1
CameraRange myResizeCamera,0.01,100
TranslateEntity myResizeCamera,(1.0/1024.0),-(1.0/1024.0),-1.0
EntityParent myResizeQuad,myResizeCamera,1
; end of init myResizeImage(img,w,h)

movie_to_play$="liebing.avi"

dummy=BLITZMOVIE_Open(movie_to_play$)
m_width=BLITZMOVIE_GetWidth()
m_height=BLITZMOVIE_GetHeight()
BLITZMOVIE_Close()

Global image = CreateImage(m_width,m_height) ; create an image that we'll be decoding the movie to

; Open the movie in decode to Blitz3D dx7 surface mode
result = BLITZMOVIE_OpenDecodeToImage( movie_to_play$, image, True)
If Not result
	BLITZMOVIE_Close()
	RuntimeError "Error loading movie! Quitting..."
EndIf

; play the movie
result = BLITZMOVIE_Play()
If Not result
	BLITZMOVIE_Close()
	RuntimeError "Error playing movie! Quitting..."
EndIf

Global width = BLITZMOVIE_GetWidth()
Global height = BLITZMOVIE_GetHeight()

While BLITZMOVIE_IsPlaying() And (Not KeyHit(1))
    Delay 5
    dummy=myProjectImage(image,gr_w, gr_h)
	scanlines(gr_h) ; gives a scanline type TV Effect (rem it out to disable it)
	Flip 1
Wend

BLITZMOVIE_Stop()
BLITZMOVIE_Close()
FreeImage(image)
End

Function scanlines(h)
 Color 0,0,0
 w=GraphicsWidth()-1
 For i=0 To h Step 4
  Rect 0,i,w,3,0
 Next
End Function

Function myProjectImage(img,w#,h#)
; copies an image To a texture of a quad that is placed in front of a cam and then scaled to w,h
 img_w#=ImageWidth(img)
 img_h#=ImageHeight(img)
 If img_w>1024 Then img_w=1024
 If img_h>1024 Then img_h=1024
 If img_w<1 Then img_w=1
 If img_h<1 Then img_h=1

 If w>1024 Then w=1024
 If h>1024 Then h=1024
 If w<1 Then w=1
 If h<1 Then h=1

 w_rel#=w#/img_w#
 h_rel#=h#/img_h#
 g_rel#=1024.0/GraphicsWidth()

 CopyRect 0,0,img_w,img_h,512-(img_w/2.0),512-(img_h/2.0),ImageBuffer(img),TextureBuffer(myResizeTex)
 ScaleEntity myResizeQuad,w_rel*g_rel,h_rel*g_rel,0.0001
 RenderWorld()
End Function

Function CreateQuad()
  ; creates a quad, facing to the right side
  mesh=CreateMesh()
  surf=CreateSurface(mesh)
  v0=AddVertex(surf, -1.0,   1.0,0, 0,0 )
  v1=AddVertex(surf,  1.0,   1.0,0, 1,0 )
  v2=AddVertex(surf,  1.0,  -1.0,0, 1,1 )
  v3=AddVertex(surf, -1.0,  -1.0,0, 0,1 )
  AddTriangle(surf,v0,v1,v2)
  AddTriangle(surf,v0,v2,v3)
  UpdateNormals mesh
  Return mesh
End Function


What this lib permits, as of version 1.3:
- Play MPG, MPEG, AVI, WMV
- pause the playback
- Control on the audio output: mute, set volume
- Decode the video on an image
- Decode the video on a texture
- Get the size of the video in pixels
- Read pixels from the video feed

What this lib doesn't do:
- Play the video backwards
- set the play position in the video (other than stop and restart)
- change the play speed
- Read VOB (DVD movie files)

Other lib for video playback: http://www.blitzbasic.com/Community/posts.php?topic=52485

Note: Actually there are not a lot of functionnal tools to help anyone on Blitz3d to be able to reliably play videos in his title without the risk of corrupting memory both on the videocard or the main. This is the only lib I found that actually works for AVIs.

Cheers