MPG_GetSprite(Mpg)
MPG_GetTexture(mpg)
MPG_GetMaterial(mpg)
MPG_Image(mpg)
So you can render to Screen, Material, texture, image or window and canvas via image dynamically.
you should also be able to play multiple videos at once, though not tested
currently windows x64, should work on linux and mac if you compile the lib
Licence MIT
note Mpeg1 and MP2 are patent free, all claims have ceased since 2017 when Mp3 expired.
v 0.4
red and blue where reversed on windows
changed how to flip image vertically on windows
v 0.3
changed to mono for 3D sound
added draw to canvas gadget test
it will likely need fix ups for linux mac as windows draws upside down canvas should be ok
sprites might not
v 0.2
changed to use native sound functions so should be cross platform now
but you will need to compile pl_mpeg.c with gcc or clang like
clang -O2 -c pl_mpeg.c
To do:
add in additional functions as required
it's very light weight at 78kb
if you want to compile the c file your self, it's as easy asPL_MPEG - MPEG1 Video decoder, MP2 Audio decoder, MPEG-PS demuxer
https://github.com/phoboslab/pl_mpeg
clang -O2 -c pl_mpeg.c
Download ;includes test video
https://atomicwebserver.com/MPG.zip
Draw video to cube example
Code: Select all
XIncludeFile "mpg.pbi"
;compile thradsafe
UseModule MPG
#CameraSpeed = 4
Define.f KeyX, KeyY, MouseX, MouseY
Define.i mpg,sound,w,h
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops():dx=DesktopWidth(0)*0.8:dy=DesktopHeight(0)*0.8
OpenWindow(0, 0,0, DesktopUnscaledX(dx),DesktopUnscaledY(dy), " Sound3D - [Esc] quit",#PB_Window_ScreenCentered | #PB_Window_Invisible)
OpenWindowedScreen(WindowID(0), 0, 0, dx, dy, 0, 0, 0)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
;-load movie with 3D sound
mpg = MPG_LoadFile("bjork-all-is-full-of-love.mpg",#MPG_SOUND3D); Load MPG file set it to 3D sound mode
HideWindow(0,0)
Parse3DScripts()
;- Mesh
CreateCube(0, 100)
CreateSphere(1, 50)
CreateMaterial(0, #PB_Material_None)
GetScriptMaterial(1, "Color/Red")
;- Entity
CreateEntity(0, MeshID(0), MaterialID(0))
CreateEntity(1, MeshID(1), MaterialID(1))
;- Get the movie Sound
sound = MPG_GetSound(mpg)
If mpg
SoundVolume3D(sound, 100)
SoundRange3D(sound, 1, 500)
EndIf
If LoadSound3D(1, "Siren.ogg")
SoundVolume3D(1, 50)
SoundRange3D(1, 1, 500)
PlaySound3D(1, #PB_Sound3D_Loop)
EndIf
;- Node
; Create a node, so we can link the entity and the sound
CreateNode(0, -400, 0, 0)
AttachNodeObject(0, SoundID3D(sound))
AttachNodeObject(0, EntityID(0))
; Create a node, so we can link the entity and the sound
CreateNode(1, 400, 0, 0)
AttachNodeObject(1, SoundID3D(1))
AttachNodeObject(1, EntityID(1))
;- Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, -550, 70, 10, #PB_Absolute)
CameraLookAt(0, NodeX(1), NodeY(1), NodeZ(1))
;- Light
AmbientColor(0)
CreateLight(0, RGB(255, 255, 255), 0, 700, 0)
;- Sky
SkyBox("desert07.jpg")
;-Play movie
MPG_Play(MPG) ;Start movie playback
Repeat
While WindowEvent():Wend
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
;-Get frame as material
mat = MPG_GetMaterial(mpg)
If mat
SetMaterialColor(mat,#PB_Material_SelfIlluminationColor,RGB(255,255,255))
SetEntityMaterial(0,MaterialID(Mat)) ;Set material to cube
EndIf
RotateEntity(0, 0, 0.3, 0, #PB_Relative)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
SoundListenerLocate(CameraX(0), CameraY(0), CameraZ(0)) ; The 'ear' follows the camera
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
MPG_Free(mpg) ;free mpg
ffmpeg -i input.mp4 -c:v mpeg1video -q:v 0 -c:a libtwolame -b:a 224k -format mpeg output.mpg
-q:v sets a fixed video quality with a variable bitrate, where 0 is the highest. You may use -b:v to set a fixed bitrate instead; e.g. -b:v 2000k for 2000 kbit/s. Please refer to the ffmpeg documentation for more details.