Bennu Game Development

English Forums => Extensions => Topic started by: josebita on March 17, 2010, 05:58:15 PM

Title: mod_vlc
Post by: josebita on March 17, 2010, 05:58:15 PM
As the title says, I've created a BennuGD module which wraps around libvlc, so it's now possible to use basically any video format in BennuGD.
Windows download (http://www.mediafire.com/?yijlmwyzcly) (much bigger, but contains everything you need).
Linux download (http://forum.bennugd.org/index.php?action=dlattach;topic=1156.0;attach=997) (very small, but you need to have a recent version of VLC installed through your system's native package management software. Also, rename the .zip file to .tar.bz2).

The module will play videos with subtitles, if available.

Both contain a sample video player app. The hotkeys for the app are:


And the list of functions this module includes is:
[code language="bennu"]
/* Plays a video file with the given width/height
* Will play the video with subtitles, if found */
int video_play(string filename, int width, int height);

/* Stop a currently playing video.*/
int video_stop();

/* Pause/unpause the currently playing video*/
int video_pause();

/* Check if the video is currently playing */
int video_is_playing();

/* Get total length of the currentyl playing video, in centisecs */
int video_get_length();

/* Get current seeking position in the video, in centiseconds */
int video_get_time();

/* Seek through the video, must be given a time
* in centiseconds (what the bennu timer's use) */
int video_set_time(int time);

/* Get the width of the currently playing video */
int video_get_width();

/* Get the height of the currently playing video */
int video_get_height();

/* Get the muted/unmuted status */
int video_get_mute();

/* Mute/unmute the currently being played video */
int video_mute();

/* Get the volume of the currently playing video
* Will be 0<=volume<=200 */
int video_get_volume();

/* Set the volume of the currently playing video
* Must be 0<=volume<=200 */
int video_set_volume(int volume);

/* Get the number of available tracks in the video
* The first track (track number 0) is used for disabling audio */
int video_get_tracks();

/* Get the number of the currently being played track */
int video_get_track();

/* Set the audio track for a currently being played video */
int video_set_track(int track);

/* Get the description for an audio track.
* Not sure if it works correctly, must test it. */
string video_get_track_description();
[/code]

Hope you find it useful :)
Title: Re: mod_vlc
Post by: josebita on March 17, 2010, 06:00:44 PM
PS: the aspect ratio in the sample player will most probably be wrong. To know a video's aspect ratio you must use video_get_width() and video_get_height() once the video is playing.

The module will play just one video at a time right now. That might change in the future, depending on feedback.
Title: Re: mod_vlc
Post by: Imerion on March 21, 2010, 11:53:41 PM
Nice! This could sure be useful. The built-in .flv player is quite limited.
Title: Re: mod_vlc
Post by: Windgate on March 22, 2010, 12:13:41 PM
It sounds good, so we can play any video format like divx???

Im downloading now, karma up and thanks a lot!
Title: Re: mod_vlc
Post by: josebita on March 22, 2010, 02:35:25 PM
Yeah, you can play anything vlc can (basically every format).
I've not tested it but it should even support webcams, dvds, internet live streams...
Title: Re: mod_vlc
Post by: Windgate on March 23, 2010, 09:32:49 PM
Quote from: josebita on March 22, 2010, 02:35:25 PM
Yeah, you can play anything vlc can (basically every format).
I've not tested it but it should even support webcams, dvds, internet live streams...

lol then it could play from Youtube with the URL or something? Without the needing of have the video on disk? :O
Title: Re: mod_vlc
Post by: josebita on March 23, 2010, 11:32:22 PM
You should be able to. For some reason, Bennu crashes when you try to open an url not corresponding to a local file, I'll have to look deeper into that.
Title: Re: mod_vlc
Post by: Windgate on March 24, 2010, 08:36:23 AM
Ouch... Bennu and sockets again... I have to work with it...

Welll, I hope you can solve it :D

I owe you a karma xD
Title: Re: mod_vlc
Post by: FreeYourMind on March 24, 2010, 09:55:22 AM
It's posible a Wiz Port ?
Title: Re: mod_vlc
Post by: josebita on March 24, 2010, 01:24:13 PM
It's certainly possible, given it's a linux system.
The "only" thing I need is a working VLC port for the Wiz.
Title: Re: mod_vlc
Post by: DCelso on March 24, 2010, 01:28:15 PM
Only. As if this task was easy.
Title: Re: mod_vlc
Post by: josebita on March 24, 2010, 01:49:37 PM
Well, you asked if such a port was possible, not easy :)
I'll try to have a look at it, though.

Still, as the Wiz is a low power device, videos would have to be downscaled in order to be able to play them in the console smoothly.
Title: Re: mod_vlc
Post by: josebita on March 24, 2010, 01:58:14 PM
Aquí hay un port para maemo (linux sobre un ARM desarrollado por Nokia, creo que el kernel es parecido) de VLC. Quizás con eso se pueda implementarl.
Title: Re: mod_vlc
Post by: FreeYourMind on March 24, 2010, 02:35:34 PM
Let's start the port friends!  ;D
Title: Re: mod_vlc
Post by: josebita on March 24, 2010, 04:29:17 PM
Sorry, my mind exploded and I wrote in Spanish/without the link. I'll have a look at those files.
Title: Re: mod_vlc
Post by: josebita on May 31, 2010, 04:51:36 PM
I've created a page hosting the latest code and packs containing only the minimum set of libraries for playing some popular codecs for windows.
Right now, the I've got codec packs for:
 - WebM (3.4MiB).
 - Ogg Theora+Vorbis (1.4MiB).
 - Dirac (1.4MiB).
In the next few days I'll upload packs for non-free but popular codecs (flv, xvid, h264...).

http://code.google.com/p/bennugd-vlc/
Title: Re: mod_vlc
Post by: josebita on June 02, 2010, 01:53:34 PM
Support for MPEG4 video encapsulated as AVI. MPEG & AC3 surround audio support.
Title: Re: mod_vlc
Post by: panreyes on June 11, 2010, 09:49:39 PM
Hi Josebita,
I finally tried to put video in Bennu, and I used the mod_vlc's WebM package.
It works flawlessly the first time a video is played, but the second play_video would return -1.
May it be a bug?
Title: Re: mod_vlc
Post by: josebita on June 11, 2010, 10:05:25 PM
You're posting in the English forum!

I'll have a look at it, but do you stop the video? Also, please post your code so I can have a look at it, but I think I know where the problem might be coming from.
Title: Re: mod_vlc
Post by: panreyes on June 12, 2010, 10:40:06 AM
This is all the code about video:
graph = video_play("quizz/"+fichero+"/"+nombre_video+".webm",1024,768);
    while(! video_is_playing() && ! key(_esc)) // Wait for the video to actually start
        FRAME;
    end
while(! key(_esc) and video_is_playing())
        FRAME;
end
if(video_is_playing()) video_stop(); end
graph=0;

BTW, I had 2 options: moving the post or writing in again in english. I preferred the second XD Ups sorry, I meant LOL
Title: Re: mod_vlc
Post by: panreyes on June 12, 2010, 11:53:50 AM
Also, the error only occurs when I'm not stopping the video with stop_video() before it ends.

Little patch:
timer=0;
duration_in_ms=video_get_length()-100;
while(timer<duration_in_ms)
Title: Re: mod_vlc
Post by: josebita on June 12, 2010, 04:30:36 PM
Yes, I believe you should do stop_video() even if the video has actually finished playing. because stop_video also does some unloading.
Title: Re: mod_vlc
Post by: panreyes on June 12, 2010, 04:37:54 PM
If the video is stopped on his own because it has ended, if you use stop_video after that, the game will hang.
Title: Re: mod_vlc
Post by: josebita on June 12, 2010, 05:18:42 PM
I see... I'll fix it as soon as possible to make things a bit more "intelligent".
Title: Re: mod_vlc
Post by: Windgate on June 13, 2010, 08:48:33 AM
There are many "play video" projects now, there is any (very) simple demo at which we could play the oficial Prg BennuGD intro (mpg, divx...)?

It could be very very very useful for the current Great BennuGD Game Project.

¿Direct download, please?

Thanks ;)
Title: Re: mod_vlc
Post by: panreyes on June 17, 2010, 08:31:45 PM
I would also change the way mod_vlc searches the files on ./vlc

I use Bennu from %PATH%, and this module makes me have half module in c:\bennugd and the other in c:\proyecto\vlc

It should look for c:\bennugd\vlc instead of c:\proyecto\vlc. I mean, it should look into bgdi's folder, not project's folder :)
Title: Re: mod_vlc
Post by: josebita on June 17, 2010, 10:36:45 PM
I've been trying to find why the code crashes without any luck, yet. Sorry. I'll try to find a cause for the crash and make it play more than one video asap. :(

As of the thing with the paths... It's not that easy. The path to look for the vlc plugins is not hardcoded but is relative to the current working dir. I believe this is the best solution for distributing your game.
As for your development needs, I'm not sure but I believe that adding the path to the vlc modules dir to your global PATH variable should help.
Title: Re: mod_vlc
Post by: josebita on June 18, 2010, 01:21:35 AM
I believe the attached library should fix the bug that didn't allow more than one video to be played (only one video can be played at a time).

The interpreter will probably crash when quitting, however...

The following example (which is a slightly modified version of the bundled example player) will allow you to play more than one video. When you press the escape key the video playback will stop. If you press "q" the app will quit but if you press the space bar, video playback will restart.
[code language="bennu"]import "mod_key"
import "mod_vlc"
import "mod_video"
import "mod_mouse"
import "mod_say"
import "mod_map"
import "mod_file"
import "mod_proc"
import "mod_timers"

#define SCR_WIDTH  640
#define SCR_HEIGHT 480

/* Player main window */
Process main()
Private
    string fname="";
    int time=0, delay=30, track=1;

Begin
    // Handle the command line
    if(argc != 2)
        say("Must be given file to play, quitting.");
        exit();
    end;

    // Try to find the file that the user wants us to play, or die
    fname = argv[1];
    if(! fexists(fname))
        say("Couldn't find "+fname+" to be played, quitting.");
        exit();
    end

    /* Start the graphics subsystem */
    set_mode(SCR_WIDTH, SCR_HEIGHT, 16);

    /* Finally play the video and place it in the middle of the screen */
    graph = video_play(fname, SCR_WIDTH, SCR_HEIGHT);
    x = SCR_WIDTH/2; y = SCR_HEIGHT/2;
    while(! video_is_playing()) // Wait for the video to actually start
        FRAME;
    end;
    while(! key(_esc))
        if(timer[0] > time+delay)
            if(key(_space))
                video_pause();
                time = timer[0];
            end;
            if(key(_right))
                video_set_time(video_get_time()+100);
                time = timer[0];
            end;
            if(key(_left))
                video_set_time(video_get_time()-100);
                time = timer[0];
            end;
            if(key(_m))
                video_mute();
                time = timer[0];
            end;
            if(key(_up))
                video_set_volume(video_get_volume()+5);
                time = timer[0];
            end;
            if(key(_down))
                video_set_volume(video_get_volume()-5);
                time = timer[0];
            end;
            if(key(_enter))
                track = video_get_track()+1;
                if(track > video_get_tracks()-1)
                    track = 0;
                end;
                video_set_track(track);
                say("Audio track "+video_get_track()+" of "+video_get_tracks());
                say("            "+video_get_track_description());
                time = timer[0];
            end;
        end;
        FRAME;
    end;

    video_stop();
    while(! key(_q))
        // If you press space bar, we start over
        if(key(_space))
            main();
            return;
        end;
        FRAME;
    end;
End;[/code]
Title: Re: mod_vlc
Post by: Windgate on June 20, 2010, 06:31:15 PM
Im waiting for a .zip with a full working sample, with the .prg, the .dll and a sample video... Everything is separated now: Here a .prg sample, here the .dll, here other versions of the same .dll :-[, here an old working sample with a .mpg that doesn't work with the current BennuGD dlls...

Just download, compile and run, for stupid users like me... And you ;)

http://code.google.com/p/bennugd-vlc/

Google Code has 2Gb accounts, why not a FULL working sample? :(
Title: Re: mod_vlc
Post by: josebita on June 20, 2010, 11:41:24 PM
The packs there contain fully working examples. The idea of the packs is to include the bare minimum you need.
For example, download the webm pack & this video (http://people.opera.com/shwetankd/webm/sunflower.webm) and from the folder with the prg file do:

bgdc mod_vlc.prg
bgdi mod_vlc sunflower.webm

I find it pretty straightforward. The code and dll posted here are not definitive and will be updated on the packs once I have time to do it.
Title: Re: mod_vlc
Post by: josebita on August 29, 2010, 10:46:58 AM
I've updated the library to support the latest VLC >= 1.1.1 and to offer native support for 32bpp.
Changes:

* Code adapted to the new VLC >= 1.1.1 API.
* Now the graph created by video_play() uses the system color depth, so if you're at 16bpp you'll get a 16bpp video and if you're @ 32bpp, you'll get a 32bpp one. Up until now you'd get a 16bpp one. Please note that 8bpp is not (and won't probably ever be) supported.
* The crash that sometimes occurred while quitting BennuGD seems to be gone.

Here are the pre-compiled binaries:
* Win32 (http://bennugd-vlc.googlecode.com/svn/trunk/mod_vlc.dll).
* Linux (http://bennugd-vlc.googlecode.com/svn/trunk/mod_vlc.so).

Again, please note that these only work on VLC 1.1.1 and over, I'll update the packs on the project site asap to use the new version of the library.
Title: Re: mod_vlc
Post by: josebita on August 29, 2010, 12:39:02 PM
The packs for windows in the project webpage (http://code.google.com/p/bennugd-vlc/) have been updated and the new library has been uploaded to my PPA for those of you using Ubuntu Maverick.

Things seem to work fine for the windows packs, but as I've tested them through wine some things might be wrong. Please let me know if that's the case.
Title: Re: mod_vlc
Post by: josebita on September 11, 2010, 07:00:26 PM
Just uploaded the MPEG4 pack for MacOS X based on VLC 1.1.3 (latest available version for Mac).
Title: Re: mod_vlc
Post by: Windgate on September 19, 2010, 05:58:05 PM
It is fucking good, I see the sample prg need to be called with argv... Why not a .bat ready to launch or a .prg that just open an included video file?

Sorry, I like the EXTREME usability :D
Title: Re: mod_vlc
Post by: josebita on September 19, 2010, 06:23:19 PM
If you launch the example without any arguments, it should complain that it needs a video file to play.
I believe that's extreme usability (bgdi main Video.avi), anyway, I might upload a very simple example for those who don't want to read the 20 line source code.... :P