Playing Movies

Just starting out? Need help? Post your questions and find answers here.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Playing Movies

Post by chris319 »

How can I play movies other than .mp4 using PureBasic, i.e. .mov, .avi, .mkv, .mpg, .mxf movies?

Is such a thing even possible in PB?

Thank you.
salutcava
User
User
Posts: 10
Joined: Fri May 03, 2013 10:50 am

Re: Playing Movies

Post by salutcava »

Hello,
Yes it is possible.
I just tested *.mp4, *.mov, *.avi, *.mkv and these video files can be played with the same code from the documentation
(K-Lite Codec pack is installed on my system) :

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Movie example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

If InitMovie() = 0
  MessageRequester("Error", "Can't initialize movie playback !", 0) 
  End
EndIf

MovieName$ = OpenFileRequester("Choose the movie to play", "", "Movie files|*.avi;*.mpg|All Files|*.*", 0)
If MovieName$
  If LoadMovie(0, MovieName$)
  
    OpenWindow(0, 100, 150, MovieWidth(0), MovieHeight(0), "PureBasic - Movie")
    PlayMovie(0, WindowID(0))
      
    Repeat
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  Else
    MessageRequester("Error", "Can't load the movie...", 0)
  EndIf
EndIf 
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Playing Movies

Post by chris319 »

Unfortunately, the K-Lite codec pack caused problems with my system which disappeared when I uninstalled it.
BarryG
Addict
Addict
Posts: 4214
Joined: Thu Apr 18, 2019 8:17 am

Re: Playing Movies

Post by BarryG »

PlayMovie() supports any videos as long as their codecs are installed. If you remove codecs, then you can't blame PlayMovie() for failing.

Did you download K-Lite Codec Pack from the official website? It's totally safe from there -> https://codecguide.com/download_kl.htm

Don't download it from any other source, as it may not be safe if you do.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4984
Joined: Sun Apr 12, 2009 6:27 am

Re: Playing Movies

Post by RASHAD »

Forget about K-Lite Copdecs
Just search for LAV Codec it is free and will do every thing you need
But remember to deal with Windows Media Foundation you may have some trouble with it if you don't know how to fix it
Egypt my love
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Playing Movies

Post by chris319 »

Did you download K-Lite Codec Pack from the official website?
Yes I did.

It seemed to have video range "full" and "limited' reversed. I am using ffplay and WMP as my references for video levels. Both ffplay and WMP give me the same levels. I also could not play XDCAM files exported by Shotcut. Both of those problems disappeared when I uninstalled the K-Lite codec pack.

I installed the LAV Codecs and PlayMovie() in PB is unable to play anything but .mp4 files. All I get is a black window when playing non-mp4 files.
BarryG
Addict
Addict
Posts: 4214
Joined: Thu Apr 18, 2019 8:17 am

Re: Playing Movies

Post by BarryG »

chris319 wrote:How can I play movies other than .mp4 using PureBasic, i.e. .mov, .avi, .mkv, .mpg, .mxf movies?
What about this tip (from a thread you participated in) -> viewtopic.php?p=555699#p555699

Does that fix it?
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Playing Movies

Post by chris319 »

What about this tip (from a thread you participated in) -> viewtopic.php?p=555699#p555699

Does that fix it?
Nope.

I uninstalled the LAV filters and reinstalled the K-Lite "mega" codec pack, restarting the machine in between and after installations.

Now all it plays is .avi. No more .mp4.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4984
Joined: Sun Apr 12, 2009 6:27 am

Re: Playing Movies

Post by RASHAD »

Windows is using Media Foundation
PB Movie lib. is using Direct show
Search how to deal with Media Foundation
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Playing Movies

Post by IdeasVacuum »

Try JHPJHP's video player

https://jhpjhp.x10host.com
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Playing Movies

Post by chris319 »

A standalone player such as WMP, VLC or PotPlayer works fine.

I uninstalled K-Lite and reinstalled LAV Filters.

PureBasic and now HTML5 in a browser only play .mp4. No mkv, mxf, mpg, mov or avi.

Something in my machine is hosed. Registry?
dige
Addict
Addict
Posts: 1416
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Playing Movies

Post by dige »

Does anyone know if it is planned to switch the Movie Lib to Windows Media Foundation?

The Windows 10 user is used to playing all videos. Only with the PureBasic software it does not.
It would be nice, if customers would not have to install a additional driver package to use the my software.
Is there a CodecPack that can be included in your own setup? Is licensing with LAV possible?

Tried K-Lite and LAV, on both there is the problem, that videos are not scaled smoothly.
Does anyone know of a workaround?

Greetz dige
"Daddy, I'll run faster, then it is not so far..."
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Playing Movies

Post by chris319 »

LAV Filters has an option to leave video levels "untouched", which I like, rather than forcing them to 16-235 or 0 - 255.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Playing Movies

Post by Lunasole »

Hi. Unfortunately built-in movie player has enough problems (and it is OK, as it's rather demo, than stuff suitable in any case).

I needed for examples seamless switching between videos, It was not possible to do with built-in.
I used libvlc instead, it's great, doesn't require any system codecs, and provides probably everything which may be needed. The only problem is it's size, libraries for x64 system taking whole 125MB :D (maybe this can be reduced by removing unnecessary plugins and other files, I didn't tried yet).

Here are my example bindings for it if someone needs.
Libvlc can be found here: https://www.videolan.org/vlc/libvlc.html

Code: Select all

EnableExplicit


;{ LibVLC }

	; Simplified libvlc bindings (several main functions imported)
	; v 1.0.0.0
	;	2020			(c) Luna Sole


	; Player states
	Enumeration libvlc_state_t 0
		#libvlc_NothingSpecial
		#libvlc_Opening
		#libvlc_Buffering
		#libvlc_Playing
		#libvlc_Paused
		#libvlc_Stopped
		#libvlc_Ended
		#libvlc_Error
	EndEnumeration
	
	
	Global hLibVLC, hLibVLCcore
	CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
		hLibVLCcore = OpenLibrary(#PB_Any, GetPathPart(ProgramFilename()) + "libvlc\x86\libvlccore.dll")
		hLibVLC = OpenLibrary(#PB_Any, GetPathPart(ProgramFilename()) + "libvlc\x86\libvlc.dll")
		
	CompilerElse
		hLibVLCcore = OpenLibrary(#PB_Any, GetPathPart(ProgramFilename()) + "libvlc\x64\libvlccore.dll")
		hLibVLC = OpenLibrary(#PB_Any, GetPathPart(ProgramFilename()) + "libvlc\x64\libvlc.dll")
	CompilerEndIf
	
	If IsLibrary(hLibVLCcore) And IsLibrary(hLibVLC)
		
		; lib/init
		PrototypeC libvlc_new(arg1, arg2):	Global libvlc_new.libvlc_new = GetFunction(hLibVLC, "libvlc_new")
		
		; player/setup
		PrototypeC libvlc_media_player_new(*p_libvlc_instance):	Global libvlc_media_player_new.libvlc_media_player_new = GetFunction(hLibVLC, "libvlc_media_player_new")
		PrototypeC libvlc_media_player_set_hwnd(*p_mi, hwnd):	Global libvlc_media_player_set_hwnd.libvlc_media_player_set_hwnd = GetFunction(hLibVLC, "libvlc_media_player_set_hwnd")
		PrototypeC libvlc_media_player_get_hwnd(*p_mi):	Global libvlc_media_player_get_hwnd.libvlc_media_player_get_hwnd = GetFunction(hLibVLC, "libvlc_media_player_get_hwnd")
		PrototypeC libvlc_media_player_set_media(*p_mi, *p_md):	Global libvlc_media_player_set_media.libvlc_media_player_set_media = GetFunction(hLibVLC, "libvlc_media_player_set_media")
		PrototypeC libvlc_media_player_get_media(*p_mi):	Global libvlc_media_player_get_media.libvlc_media_player_get_media = GetFunction(hLibVLC, "libvlc_media_player_get_media")
		
		; player/commands
		PrototypeC libvlc_media_player_play(*p_mi):	Global libvlc_media_player_play.libvlc_media_player_play = GetFunction(hLibVLC, "libvlc_media_player_play")
		PrototypeC libvlc_media_player_set_pause(*p_mi, pause):	Global libvlc_media_player_set_pause.libvlc_media_player_set_pause = GetFunction(hLibVLC, "libvlc_media_player_set_pause")
		PrototypeC libvlc_media_player_stop_async(*p_mi):	Global libvlc_media_player_stop_async.libvlc_media_player_stop_async = GetFunction(hLibVLC, "libvlc_media_player_stop_async")
		PrototypeC libvlc_audio_set_volume(*p_mi, volume.i):	Global libvlc_audio_set_volume.libvlc_audio_set_volume = GetFunction(hLibVLC, "libvlc_audio_set_volume")
		PrototypeC libvlc_audio_get_volume(*p_mi):	Global libvlc_audio_get_volume.libvlc_audio_get_volume = GetFunction(hLibVLC, "libvlc_audio_get_volume")
		PrototypeC libvlc_media_player_set_position(*p_mi, pos.f, fast.b):	Global libvlc_media_player_set_position.libvlc_media_player_set_position = GetFunction(hLibVLC, "libvlc_media_player_set_position")
		PrototypeC.f libvlc_media_player_get_position(*p_mi):	Global libvlc_media_player_get_position.libvlc_media_player_get_position = GetFunction(hLibVLC, "libvlc_media_player_get_position")
		PrototypeC libvlc_media_player_get_state(*p_mi):	Global libvlc_media_player_get_state.libvlc_media_player_get_state = GetFunction(hLibVLC, "libvlc_media_player_get_state")
		PrototypeC libvlc_media_player_is_playing(*p_mi):	Global libvlc_media_player_is_playing.libvlc_media_player_is_playing = GetFunction(hLibVLC, "libvlc_media_player_is_playing")
		
		; media/files
		PrototypeC libvlc_media_new_path(*p_libvlc_instance, path.p-UTF8):	Global libvlc_media_new_path.libvlc_media_new_path = GetFunction(hLibVLC, "libvlc_media_new_path")
		PrototypeC libvlc_media_release(*p_md):	Global libvlc_media_release.libvlc_media_release = GetFunction(hLibVLC, "libvlc_media_release")
		
	EndIf
	
	
	; https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html#gaf6897a4ef07c684555fc600c7a63a8c4	
	
;}



; Replace it with your video path
Define File$ = "D:\2020-05-21 15-17-55.mp4"
Define File 

; Create new VLC instance
Define Inst = libvlc_new(0, 0)
; Create new VLC player instance
Define Plr = libvlc_media_player_new(Inst)


; Create window and bind player to use this window as output
OpenWindow(0, 200, 300, 400, 500, "", #PB_Window_SizeGadget|#PB_Window_SystemMenu)
libvlc_media_player_set_hwnd(Plr, WindowID(0))


Repeat

	Define State = libvlc_media_player_get_state(plr)
	Select State
		Case #libvlc_NothingSpecial, #libvlc_Ended, #libvlc_Error:
			; player is stopped, load the file
			File = libvlc_media_new_path(Inst, File$)
			; put loaded file into player
			libvlc_media_player_set_media(plr, File)
			; audio volume
			libvlc_audio_set_volume(plr, 50)
			; PLAY
			libvlc_media_player_play(plr)
			; loaded media may be released after it was transferred to a player
			libvlc_media_release(file)
	EndSelect

	If WaitWindowEvent(1) = #PB_Event_CloseWindow
		Break
	EndIf
ForEver

End
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Playing Movies

Post by chris319 »

Sorry, it fails at this line:

Code: Select all

Define Inst = libvlc_new(0, 0)
Post Reply