Hi Monks!

I'm new here, so please forgive me if I posted this to the wrong section, or if I unknowingly violate some posting rule(s). Below is a writeup of some background information about what I want to acheive, and some specific questions on what technologies I should look at to design a smooth video player frontend in Perl. Feel free to skip the 'Background' chapter if you're psychic ;-)

Background

I have been using Perl on and off for, oh maybe 6-7 years; mostly for processing text, migrating between databases, web automation, bulk image/file processing, a little mod_perl, the occasional Tk GUI, even some Curses stuff. In short I use Perl to solve relatively simple day-to-day problems; I am - in no sense of the words - a professional programmer. Actually I create multimedia shows for a living - the kind with lots of high-end projectors, plasma screens, holographic audio, moving lights, smoke, lasers and other cool stuff that I enjoy.

So basically what I want to do is build a replacement for (a subset of the features of) a BeOS-based video playback unit that I own (but do not particularily enjoy): Roland Edirol PR-50. There are several reasons why I wish to take on this project:

All the hard parts are already done (ie windowing toolkit, video playback), and what I plan on doing is advancing my skills by gluing together existing components into a usable piece of equipment, this will include some video scaling hardware, audio converters, extenders, and other stuff in addition to the software I discuss here. It is a hobby project and not related to or sponsored by my employer in any way.

What I need - Final product vision

I need two programs that run on individual displays on the same computer; one being the control GUI, the other video output. The control GUI will allow user to import video files and organize them into an arbitrary number of palettes (9x9 matrixes of thumbnails representing video clips), and configure a few parameters for each clip like in/out time, audio volume, aspect ratio (depending on chosen back-end and how practical it is to implement). Once a video is placed on a palette, playback can be started instantly on the output display by left-clicking on its thumbnail. Right-click will load the media file and pause on frame 0. That's about all I need.

Edit: Sorry, just discovered the readmore tag. Applied.

What are my options?

  1. Socket interface to VideoLAN VLC via rc/telnet interfaces: While this could potentially be a neat, simple cross-platform solution, unfortunally it requires a lot of ugly hacks to complete. Resulting playback will not be on par with the Edirol since VLC is not frame accurate ('jerking' on start/pause etc); also it is very difficult to maintain accurate state information about the player. http interface unexplored, since the showstoppers are, eventually, not problems with the rc/telnet interface, but with the VLC core.
  2. Socket interface to Guliverkli's Media Player Classic via http remote control interface. Seems like a solid option, initial testing indicate this will work. It is Win32 only, though, and if I lock to a platform I would prefer Linux.
  3. Win32::MCI::MultiMedia; I have barely tested this to confirm that I can play a video on Win32. I have not acheived fullscreen playback nor tested on-the-fly capabilities. I'd rather use MPC if I go for Win32.
  4. Video::Xine; From what I can gather (without testing)*, it should be possible to run the GUI on one display and an X11::Fullscreen Video::Xine player on the other. Communications could be via IPC(?) or sockets.
  5. GStreamer; This seems to be a good option, though I must admit I need to research this library more. From what I can tell (without testing)* it is be possible to acheive video playback in fullscreen; so I can communicate with the player process via IPC/sockets here also.
  6. The POGL page on Wikipedia has a sentence mentioning that it's possible to map video frames to OpenGL textures via ffmpeg.
  7. Gtk2::Ex::MplayerEmbed seems (without testing)* obsolete and lacking support for vital options

* I am currently defragging in order to resize partition and install Linux to get started with this - it will take some time before I'm up and running, though, as I need to backup the system etc.

The Most Important Questions

  1. Did I miss something when it comes to Perl's video playback capabilities? Are there other options except those listed I should explore?
  2. I have not found any examples or people stating they actually use the POGL-ffmpeg magic; I don't need 3d transformations on video playback, but it would certainly be an interesting addition. Is it practical to acheive full-framerate video playback in this way? Comments?
  3. Will either of the options allow me to 'overlay' the contents of the video output as a live thumbnail preview in the GUI application? This question particularily relates to GStreamer and Video::Xine.
  4. Obviously if I remote control VLC/other player, sockets will be necessary. But using GStreamer or Video::Xine, is it necessary to do the IPC/Socket thing to communicate between two distinct GUI/player processes? Or is it possible to control two windows on two displays from one single application, started on one of said displays?
  5. I plan on using POE; Are there any particular Gotchas I should consider with POE+GStreamer, POE+Video::Xine, POE+IPC?
  6. I plan on using Tk::Zinc to create a smooth/fancy GUI; Are there any particular Gotchas I should consider with Zinc+(POE|GStreamer|Video::Xine|IPC|POGL)?
  7. Using Video::Xine, GStreamer (or the mythical POGL-ffmpeg binding); will any of these provide frame-accurate playback, i.e. allow me to seek to a specific video frame and pause there?
  8. Which of the options would you rate as the most reliable/mature for production work?
  9. Ideally it should also be possible to do "dual channel", i.e. a quad head setup with two independent control/output displays. Are any of the approaches particularily well or not-well suited for this?
  10. Any particular reasons why this is or is not a suitable task for Perl? ;-)

That sums up some of the questions on my mind, I thank you for reading, and in advance for your comments and suggestions. I will definetly post more specific in the SoPW section during the Linux experiments. Defrag done, on to the backups..

All the best! :-)

  • Comment on Creating a video player frontend in Perl - what are my options?

Replies are listed 'Best First'.
Re: Creating a video player frontend in Perl - what are my options?
by Joost (Canon) on Oct 19, 2008 at 13:45 UTC
    With GStreamer you actually don't need sockets to do IPC: the whole stream framework runs in a separate thread that you can access using method calls/messages.

    If you use the standard playbin plugin as a base, you can probably set up a complete audio/video player in something like 10 lines of code (a couple more if you want to hook in custom audio/video processing).

    Gst works fine with Tk at least for audio playing (I haven't tried video), as long as you make sure you're syncing the Tk and Glib event loops. I devised a fairly hackish way of doing that, by polling the Tk events from within the Glib mainloop:

    # setup glib loop our $loop = Glib::MainLoop->new(undef,0); # handle tk events sub tk_loop { my $c = Tk::MainWindow->Count; if ($c) { 1 while (DoOneEvent(ALL_EVENTS | DONT_WAIT)); } else { $loop->quit; # quit glib loop if GUI is closed } $c; } Glib::Timeout->add(5,\&tk_loop); # call tk_loop every 5 ms $loop->run;
    This appears to be more than sufficient to run Tk and Gstreamer with good responsiveness, and you can probably reduce the interval for tk_loop if that takes up too much CPU resources.

Re: Creating a video player frontend in Perl - what are my options?
by zentara (Cardinal) on Oct 19, 2008 at 13:22 UTC
    That's one heck of a question and specifications list. I will offer you a simple suggestion to look at, it's mplayer's slave mode, which runs well from Tk ( with IPC::Open3), see Perl/Tk front-end to mplayer. If you are clever, you can separate the view window from the control window, and figure out the slave mode commands to do what you need.

    Another example for ripping videos is at z-charcoal-video-converter

    Any particular reasons why this is or is not a suitable task for Perl?

    It may be too slow for some heavy duty video tasks.

    I would concentrate on GStreamer if I were you, it has a perl module, but you may have better luck running it thru IPC, so it's forked off.


    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Creating a video player frontend in Perl - what are my options?
by ambrus (Abbot) on Oct 20, 2008 at 11:46 UTC

    The mplayer program has a so called slave mode where a frontend controls it completely. You could try to use that directly. The manpage says:

    -slave (also see -input)
    Switches on slave mode, in which MPlayer works as a backend for other programs. Instead of intercepting keyboard events, MPlayer will read commands separated by a newline (\n) from stdin. NOTE: See -input cmdlist for a list of slave commands and DOCS/tech/slave.txt for their description.
      Thank you for this very useful tip - I have come to realise that ideally I will have to support several playback backends; this certainly will make for an easy addition ;-)
        As a playback backend, I've not seen much which mplayer doesn't handle. It would be my choice of target.
Re: Creating a video player frontend in Perl - what are my options?
by Perlbotics (Archbishop) on Oct 19, 2008 at 16:16 UTC

    Nice project idea. Concerning question 5.): FWIW, I associated this project description immediately with POE and one of its application examples: How POE Saved BayCon TV, Helped Godzilla Destroy Tokyo, and Let Me Sleep (see PDF whitepaper). The asynchronous event handling required here and POEs capabilites to integrate with existing GUI event-loops, makes it a good choice. So, I would confirm your approach.

    Unfortunately, I am not qualified to answer your questions (5.), but you might ask/consult rcaputo who is the expert here.

Re: Creating a video player frontend in Perl - what are my options?
by Corion (Patriarch) on Oct 19, 2008 at 18:07 UTC

    I wrote something like that using OpenGL for the display and ffmpeg as the decoder. I pipe the media files from ffmpeg to standard output as raw video frames and then push them onto the display via OpenGL. This allows fairly quick playback, but no audio control (due to the single output stream) and no backward seeking. On the upside, it was almost trivial to code and works.

      Thanks for your input - could you post some example code for this?

        I have released the code at App::VideoMixer. Of course it's rough at the edges...

Re: Creating a video player frontend in Perl - what are my options?
by ambrus (Abbot) on Nov 24, 2009 at 11:38 UTC