Ways in which I can embed a video player into GFX window?

Game development specific discussions.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Ways in which I can embed a video player into GFX window?

Post by datwill310 »

I was part of a two year-old thread on this forum to do with videos and games, and how it would be possible to play movie files in games. While the answers to my initial question, and the help given, were great, I feel like, coming back to the same topic years later, none of the code snippets fully solved my issue.
This comes down to mistakes on my part; I wasn't clear enough about what I wanted, for one thing.
So I would like to revisit this topic, with a new question;
Is it possible to embed a video player into the GFX window set up with the screen command? And if so, what API, code, and other resources will I need in order to do so?
Here are my preferences;
  • I would like to be able to set at a custom, constant resolution. This is so the video player can embed 'properly' into my graphics windows (screen 20 for the game I am programming now, btw).
  • I would like to have full control over the functions that are available to the user, such as Play, Skip, Pause, and control over the time tracker if I'm lucky.
  • I would like to be able to control what videos I play, and not the user. The video player should also be able to play MP4 files.
I know of a few possible answers to my question; I know of the Windows Multimedia API, but am unsure if it will integrate well into the GFX window? And VLC, but the solutions produced in the linked thread did not integrate into the GFX window well or offered too much control via context menus.
What I'll be using it for: play cutscenes in the game, which will be triggered at certain times. The embedded video player should be able to play the video file when I want it to, and close when I want it to. I'll hopefully allow the user to pause the video, and skip the video. I might actually block the time tracker if I had the choice. i don't want the user to have control over what to play, I just want the embedded video player to play a video, then once completed, close then continue with execution.
If you've got any tips or answers I would love to hear them!
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: Ways in which I can embed a video player into GFX window?

Post by angros47 »

You should also consider if you want the player to be multiplatform, or if you want to support only windows
I'd recommend a multiplatform solution, in the future you might want to port your game to a different system
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Ways in which I can embed a video player into GFX window?

Post by datwill310 »

Yeah, I never specified that, soz T_T. While multi platform may be a better option, the game rn is specific to Windows only. So, as long as the solution works on the Windows platform, I’m fine with it.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Ways in which I can embed a video player into GFX window?

Post by datwill310 »

D.J.Peters wrote:VLCplayer /VideoLan
viewtopic.php?f=3&t=11295&p=99094&hilit=videolan#p99094

libVLC in FreeBASIC
viewtopic.php?f=14&t=24028&p=213010

Joshy
Hi Joshy,

VLC looks like the best option, I'll research some more and maybe come up with a code snippet I'll use for the game, and post it here.

Thank you for the help.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Ways in which I can embed a video player into GFX window?

Post by Boromir »

datwill310 wrote:
  • I would like to be able to set at a custom, constant resolution. This is so the video player can embed 'properly' into my graphics windows (screen 20 for the game I am programming now, btw).
  • I would like to have full control over the functions that are available to the user, such as Play, Skip, Pause, and control over the time tracker if I'm lucky.
  • I would like to be able to control what videos I play, and not the user. The video player should also be able to play MP4 files.
I know of a few possible answers to my question; I know of the Windows Multimedia API, but am unsure if it will integrate well into the GFX window? And VLC, but the solutions produced in the linked thread did not integrate into the GFX window well or offered too much control via context menus.
What I'll be using it for: play cutscenes in the game, which will be triggered at certain times. The embedded video player should be able to play the video file when I want it to, and close when I want it to. I'll hopefully allow the user to pause the video, and skip the video. I might actually block the time tracker if I had the choice. i don't want the user to have control over what to play, I just want the embedded video player to play a video, then once completed, close then continue with execution.
If you've got any tips or answers I would love to hear them!
Bink might be an option. It's really easy to use but you would have to use the .bik format for your cutscenes.

Edit:
Come to think of it. I believe you have to purchase a license if you want to distribute your game. So this may not be an option for you.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Ways in which I can embed a video player into GFX window?

Post by datwill310 »

@Boromir, if that is the case, it isn't all the suitable for us making the game. Sorry :(
On the other hand, libVLC does look like a viable option and I've explored some of the doc and it is good.
Thank you for all the help everyone.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Ways in which I can embed a video player into GFX window?

Post by D.J.Peters »

You have to render the video frames via libVLC in a pixelbuffer from FBGFX screen or FB image.

the key are: libvlc_video_set_callbacks

Joshy

Here are this code works for images and the screen (if image=0)

Code: Select all

#include once "vlc/vlc.bi"

function lockCB cdecl (byval image as any ptr, byval pPlanes as any ptr ptr) as any ptr
  if (image=0) then ' we use the the FBGFX screen as target so we must lock it
    screenlock : pPlanes[0]=screenptr() ' get the address of the screen pixel buffer
  else ' we use any RGB image get the address of the pixel buffer 
    Imageinfo(image,,,,,pPlanes[0])
  end if
  return 0
end function

sub unlockCB cdecl (byval image as any ptr, byval pPicture as any ptr, byval pPlanes as any const ptr ptr)
  if (image=0) then screenunlock ' if we use the FBGFX screen we must unlock it
end sub

sub displayCB cdecl (byval image as any ptr, byval pPicture as any ptr)
  ' if we use the screen all rendering are done and we can go out here  
  if (image=0) then return
  ' use the decoded image for what ever here I blit on screen
  put (0,0),image,PSET
end sub
'
' main
'
dim as zstring ptr VIDEO = @"./HAL_9000_I_m_sorry_Dave_I_m_afraid_I_can_t_do_that.mp4"
dim as any ptr image

' make it the current path
chdir exepath() 

const SCR_W = 1280
const SCR_H =  800
screenres SCR_W,SCR_H,32

' we use an image here (if you comment it out the screen will be used)
image=imagecreate(SCR_W\4, SCR_H\4) 


dim as integer frameW,frameH,frameP
if image=0 then ' we use the screen
  screeninfo frameW,frameH,,,frameP
else ' we use an image
  imageinfo image,frameW,frameH,,frameP
end if


var instance = libvlc_new (0,NULL)
var media = libvlc_media_new_path(instance, VIDEO)
var player = libvlc_media_player_new_from_media(media)
libvlc_media_release(media)
libvlc_video_set_format(player,@"BGRA", frameW, frameH, frameP)
libvlc_video_set_callbacks(player, @lockCB, @unlockCB, @displayCB, image)

' start the video/audio decoder stream
var result = libvlc_media_player_play(player)
if (result<>0) then
  print "error: play ! ..."
  libvlc_media_player_release(player)
  libvlc_release(instance)
  beep : sleep : end 2
end if
  
print "decoding video/audio stream ..."
libvlc_audio_set_volume(player,80)
dim as libvlc_state_t PlayerState
while (inkey()="") and (PlayerState<>libvlc_Ended)
  PlayerState = libvlc_media_player_get_state(player)
  sleep 100
wend  
if (PlayerState<>libvlc_Ended) then libvlc_media_player_stop(player) : sleep 500,1
libvlc_media_player_release(player)
libvlc_release(instance)
DamageX
Posts: 130
Joined: Nov 21, 2009 8:42

Re: Ways in which I can embed a video player into GFX window?

Post by DamageX »

Bink might be an option. It's really easy to use but you would have to use the .bik format for your cutscenes.

Edit:
Come to think of it. I believe you have to purchase a license if you want to distribute your game. So this may not be an option for you.
Now that you mention it, wouldn't there be similar issues with MP4? (patent encumbrance)

My suggestion: get the Google VP8 VFW codec and put your videos in AVI format, then using AVI functions to decode/playback
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Ways in which I can embed a video player into GFX window?

Post by datwill310 »

DamageX wrote:
Bink might be an option. It's really easy to use but you would have to use the .bik format for your cutscenes.

Edit:
Come to think of it. I believe you have to purchase a license if you want to distribute your game. So this may not be an option for you.
Now that you mention it, wouldn't there be similar issues with MP4? (patent encumbrance)

My suggestion: get the Google VP8 VFW codec and put your videos in AVI format, then using AVI functions to decode/playback
So now I’m worried if the FLV format has similar issues (since this format was made by Adobe)? I’d like to avoid AVI as much as possible in place for a less space-hungry format.
EDIT:
I'm assuming the OGG audio format doesn't have patent issues?
EDIT:
So according to their website, I can use it?
https://xiph.org/vorbis/
Btw, this project is going to be open-source and non-commercial.
DamageX
Posts: 130
Joined: Nov 21, 2009 8:42

Re: Ways in which I can embed a video player into GFX window?

Post by DamageX »

Vorbis shouldn't have any patents. I think that was pretty much the whole point of it. It can also be used with AVI (Vorbis ACM codec). I'm not sure why you think AVI would take more space, it depends 98% on which codecs are used, not so much on the container.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Ways in which I can embed a video player into GFX window?

Post by datwill310 »

DamageX wrote:Vorbis shouldn't have any patents. I think that was pretty much the whole point of it. It can also be used with AVI (Vorbis ACM codec). I'm not sure why you think AVI would take more space, it depends 98% on which codecs are used, not so much on the container.
Thanks for confirming with me.
The codecs I’ve been using with the AVI container take up more space as opposed to, say, the FLV container and the codec that uses. That’s just my experience so far and that’s why I said it.
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: Ways in which I can embed a video player into GFX window?

Post by Landeel »

D.J.Peters wrote:You have to render the video frames via libVLC in a pixelbuffer from FBGFX screen or FB image.

the key are: libvlc_video_set_callbacks

Joshy

Here are this code works for images and the screen (if image=0)

Code: Select all

#include once "vlc/vlc.bi"

function lockCB cdecl (byval image as any ptr, byval pPlanes as any ptr ptr) as any ptr
  if (image=0) then ' we use the the FBGFX screen as target so we must lock it
    screenlock : pPlanes[0]=screenptr() ' get the address of the screen pixel buffer
  else ' we use any RGB image get the address of the pixel buffer 
    Imageinfo(image,,,,,pPlanes[0])
  end if
  return 0
end function

sub unlockCB cdecl (byval image as any ptr, byval pPicture as any ptr, byval pPlanes as any const ptr ptr)
  if (image=0) then screenunlock ' if we use the FBGFX screen we must unlock it
end sub

sub displayCB cdecl (byval image as any ptr, byval pPicture as any ptr)
  ' if we use the screen all rendering are done and we can go out here  
  if (image=0) then return
  ' use the decoded image for what ever here I blit on screen
  put (0,0),image,PSET
end sub
'
' main
'
dim as zstring ptr VIDEO = @"./HAL_9000_I_m_sorry_Dave_I_m_afraid_I_can_t_do_that.mp4"
dim as any ptr image

' make it the current path
chdir exepath() 

const SCR_W = 1280
const SCR_H =  800
screenres SCR_W,SCR_H,32

' we use an image here (if you comment it out the screen will be used)
image=imagecreate(SCR_W\4, SCR_H\4) 


dim as integer frameW,frameH,frameP
if image=0 then ' we use the screen
  screeninfo frameW,frameH,,,frameP
else ' we use an image
  imageinfo image,frameW,frameH,,frameP
end if


var instance = libvlc_new (0,NULL)
var media = libvlc_media_new_path(instance, VIDEO)
var player = libvlc_media_player_new_from_media(media)
libvlc_media_release(media)
libvlc_video_set_format(player,@"BGRA", frameW, frameH, frameP)
libvlc_video_set_callbacks(player, @lockCB, @unlockCB, @displayCB, image)

' start the video/audio decoder stream
var result = libvlc_media_player_play(player)
if (result<>0) then
  print "error: play ! ..."
  libvlc_media_player_release(player)
  libvlc_release(instance)
  beep : sleep : end 2
end if
  
print "decoding video/audio stream ..."
libvlc_audio_set_volume(player,80)
dim as libvlc_state_t PlayerState
while (inkey()="") and (PlayerState<>libvlc_Ended)
  PlayerState = libvlc_media_player_get_state(player)
  sleep 100
wend  
if (PlayerState<>libvlc_Ended) then libvlc_media_player_stop(player) : sleep 500,1
libvlc_media_player_release(player)
libvlc_release(instance)
Hey Joshy,

you made my day sir.

I've been struggling with this for 4 days.

Thank you so much!
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Ways in which I can embed a video player into GFX window?

Post by D.J.Peters »

Landeel wrote:you made my day sir.
I've been struggling with this for 4 days.
I've been struggling with this for 4 hours. :-)

Joshy
PublioMaro_Virgilivs
Posts: 19
Joined: Nov 23, 2020 16:45
Contact:

Re: Ways in which I can embed a video player into GFX window?

Post by PublioMaro_Virgilivs »

Hi guys!

Maybe I'm totally lost, but I don't find VLC.BI file anywhere. I did download files related with VLC (like LibVLC in FreeBASIC) but I don't see such file. What I'm doing wrong?
Post Reply