TROGDOR has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I've spent the last couple hours doing extensive perlmonks/CPAN/Yahoo searches for any module or widget that will allow me to play video in perl, preferably perltk. The closest I got was tkMovie, but that's only for tcl. I see that someone asked the same question back in 2002, but there was never a distinct answer. My preferred format is mpg4 or divx, but mpg2 would work in a pinch. My target OS is Windows.

I'm trying to write my own Laserdisc-style game, hopefully using perltk and video clips. This task shouldn't be too bad if I could just find a perl video player that would allow me to switch between streams quickly, or to seek quickly inside one large stream. Imagine laserdisc-style games of Star Wars, InuYasha, Dukes of Hazard, etc...

Any advice, exalted ones?

Thanks,
TROGDOR

Replies are listed 'Best First'.
Re: Playing video with perl / perltk
by PodMaster (Abbot) on Oct 28, 2004 at 09:24 UTC
    My target OS is Windows.
    On CPAN, windows is called Win32 :D and what you'd do is grab Win32::API and then head on to MSDN and do some reading, so that you can write something similar to Win32::GUI::AxWindow or Wx::ActiveX::WMPlayer or ....

    http://perltk.org => http://www.perltk.org/ptknews/recall_me.cgi?Search=video => Re: Embedding media players in Tk ?

    Take a look at Win32::MultiMedia (it's on ppm for both ActivePerl 5.6 and 5.8)

    It uses the MCI interface to play any kind of audio/video using MediaPlayer. You can embed the video in any Tk frame using the id of the frame:

    use strict; use Tk; use Win32::MultiMedia::Mci; my $file = shift || 'test.mpg'; my $video_frame = $mw->Frame( -width => 352, -height => 240, -background => 'black' )->pack(-expand => 1); my $mci = Win32::MultiMedia::Mci->open($file, shareable => 1, style => 'child', parent => hex($frame->id) ); $mci->play('');
    Hope this helps, Thomas
    update: MCI is as easy as Win32::MCI::Basic (just look at Win32::MCI::CD).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Thanks PodMaster and Courage,
      > But first you must install Tcl/Tk with said widget
      I don't want to deal with a full Tcl install, so I bailed on this idea. But thanks for the suggestion, Courage.
      > Take a look at Win32::MultiMedia
      This worked great! I got it up and running in 5 mins. It did require some debug on the code example, though:
      use strict; use Tk; use Win32::MultiMedia::Mci; my $file = shift || 'test.wmv'; my $mw = MainWindow->new(); my $video_frame = $mw->Frame( -width => 352, -height => 240, -background => 'black' )->pack(-expand => 1); my $mci = Win32::MultiMedia::Mci->open($file, shareable => 1, style => 'child', parent => hex($video_frame->id) ); $mci->play(''); MainLoop();

      There are 3 bugs in the code:
    • $mw was not defined, so I added a MainWindow-new().
    • The mci parent pointed to $frame. It needs to point to $video_frame.
    • Without the MainLoop(), the program exits immediately without playing the video.

      The above code displays a nice little test video window on my screen. This is why I love perl. :)

      Thanks again,
      TROGDOR

      Janitored by Arunbear - replaced pre tags with code tags, as per Monastery guidelines

Re: Playing video with perl / perltk
by Courage (Parson) on Oct 28, 2004 at 17:42 UTC
    Tcl-only actually available to Perl with http://search.cpan.org/~vkon/, that CPAN module makes available perlTk or pure-Tcl syntax, at your wish.

    See my post about video on perlTk at Re: Video components for Tk?

    Also you could follow links at the bottom of my home node id to get an idea how to do the trick.

    Win32-specific answer to you question is using Win32::OLE to manage existing registered media player.

    Best regards,
    Courage, the Cowardly Dog
Re: Playing video with perl / perltk
by mattr (Curate) on Oct 29, 2004 at 07:55 UTC
    There is Wx::ActiveX::WMPlayer which I have not yet tried, and a video player using the WxPerl system called videobox with source code. Don't know if useful for you.
Re: Playing video with perl / perltk
by Anonymous Monk on Jul 23, 2019 at 13:03 UTC
    in the sample code. is there a way to play multiple video files? i.e. play video1.wmv then video2.wmv then video3.wmv and repeat loop (video1,video2,video3)?

    sample code

    use strict; use Tk; use Win32::MultiMedia::Mci; my $file = shift || 'test.wmv'; my $mw = MainWindow->new(); my $video_frame = $mw->Frame( -width => 352, -height => 240, -background => 'black' )->pack(-expand => 1); my $mci = Win32::MultiMedia::Mci->open($file, shareable => 1, style => 'child', parent => hex($video_frame->id) ); $mci->play(''); MainLoop();
    Thanks
    John