New MPlayer scripts for Linux and OS X
I recently installed Debian Wheezy + LXDE on my eMac, and yesterday I was finally able to get 3d hardware acceleration working. So I decided to install MPlayer2 and try to write some new scripts for it. Once again we want to launch MPlayer from the shell. We are in Linux this time, so no AppleScript (see
post 55 for OS X scripts, and the end of this post for some new app). Luckily it wasn't as difficult as i was expecting.
Once again, this is based on the excellent work of the PPC Luddite. See his posts
here, and
here.
For this to work you will need to install MPlayer (as I said I went for MPlayer2) and xclip. This is very easy thanks to Synaptic. Xclip is an utility that will let you paste to/from the terminal from/to the clipboard.
We have four scripts. Two of them to open videos from the net, the other two to open files on your hard disk. Copy them to a text editor and save them to your folder of choice.
Then, and this is very important, make your scripts executable or they won't work at all. The easiest way to do this is right clicking on them,
selecting properties, going to the permissions pane and selecting "Make executable" (or something like that, on my system I'm not using English as system default, so there may be a few differences)
Here are the first two scripts:
netToMplayer
#!/bin/bash
cd
__PATH TO YOUR SCRIPTS FOLDER__
video=$(xclip -o)
(nohup mplayer -really-quiet -framedrop -cache 10000 -cache-min 10 "$video" >/dev/null &) && exit
netToMplayerHD
#!/bin/bash
cd
__PATH TO YOUR SCRIPTS FOLDER__
video=$(xclip -o)
(nohup mplayer -really-quiet -framedrop -lavdopts skiploopfilter=all:skipframe=nonref -cache 10000 -cache-min 10 "$video" >/dev/null &) && exit
Remember, of course, to add the path to your scripts folder. The first one is for standard definition videos, the second one for HD (it will slightly reduce the quality, see the Luddite's posts linked above for reference, or, even better the
MPlayer manual).
These two scripts require you to copy to the clipboard the link to a video file embedded in a webpage. If you have read this thread or the Luddite's blog you already know that there are several ways to do this. An extremely easy one is using the UnPlug add-on for FireFox/TenFourFox/IceWeasel. Once you have copied the link to the clipboard, you can launch the scripts by double clicking them or, much better, with a keyboard shortcut. To create keyboard shortcuts in LXDE login as root and open /root/.config/openbox/lxde-rc.xml in a text editor. Be very careful, this file configures many different features of your window manager, you don't want to damage it (in fact it would be wise to back it up before editing). Search for the line: " <!-- Keybindings for running applications -->", then add your shortcuts, using the following lines as a model:
<!-- Keybindings for running applications -->
<keybind key="W-S-m">
<action name="Execute">
<command>/home/mic/Script/netToMPlayer</command>
</action>
</keybind>
<keybind key="W-S-h">
<action name="Execute">
<command>/home/mic/Script/netToMplayerHD</command>
</action>
</keybind>
Let's try to understand what's happening here. I installed the scripts in /home/mic/Script/ , and I chose command-shift-m (i.e. W-S-m) to launch netToMPlayer and command-shift-h (i.e. W-S-h) to launch netToMPlayerHD. See
this link and
this link for further reference.
Save your lxde-rc.xml file, then open the terminal and launch this command:
openbox-lxde --reconfigure
Done! The scripts are ready to be used (did you remember to make them executable?).
Here are the other two:
launchMPlayer
#!/bin/bash
mplayer -really-quiet -framedrop -cache 10000 -cache-min 10 "$1"
launchMPlayerHD
#!/bin/bash
mplayer -framedrop -lavdopts skiploopfilter=all:skipframe=nonref -really-quiet -cache 10000 -cache-min 10 "$1"
As i said, these are to launch video files already on your hard disk. To make them work we need to create .desktop files for them, or, in other words, we have to promote them from simple scripts to applications. Go to /usr/share/applications, open your text editor and create two new files using the following as a model:
[Desktop Entry]
Encoding=UTF-8
Name=launchMPlayer
Comment=MPlayer2 launcher
Exec=/home/mic/Script/launchMPlayer
Type=Application
Categories=AudioVideo
[Desktop Entry]
Encoding=UTF-8
Name=launchMPlayerHD
Comment=MPlayer2 HD video launcher
Exec=/home/mic/Script/launchMPlayerHD
Type=Application
Categories=AudioVideo
Save as launchMPlayer.desktop and launchMPlayerHD.desktop . Please notice that if you want you can add an icon to your scripts, see the other files in the directory for reference (be careful not to damage them, I did and I had to reinstall one of my applications).
Now the scripts should work (once again, did you remember to make them executable?). If you open the audio and video section of your LXDE menu they should appear there. Right click on a video file and you should be able to open it in MPlayer. You should also be able to set up the scripts as default video players (right click on file --> properties), so that the next time you will just have to double click to open. It can't get easier than that!
There is one thing I would like to add. It's not as complicated as it may seem, it's actually easier done than said. In fact writing the original OS X scripts in AppleScript costed me much more work and effort. Sure, I'm a beginner with AppleScript, but when it comes to Linux I'm a complete, absolute noob!
Also, I'm a masochist! In fact when I saw that it's possible to launch a file in MPlayer by simply double clicking on it I decided that I had to get the same behavior in OS X. More AppleScript fun!
I attached the resulting scripts to this post. To be more precise they are applescripts saved as applications. Please notice that I'm assuming that MPlayer is in your Applications folder. This is likely not the case if you installed the player with MacPorts or TigerBrew. Open the applications with Applescript Editor and edit the path to your MPlayer binary as necessary.
NetToMPlayer is the new and much improved version of a similar application I wrote a few months ago (see
post 62) and has to be used with TenFourFox and the Open With add-on as detailed by the Luddite in one of the posts linked above. LaunchMPlayer works in the same way as its Linux counterpart. Right click on a video file and open it with the app (please notice that I wasn't able to get all the files of a certain kind, for example mp4, to open with LaunchMPlayer; for some reason QuickTime takes over). MPlayer Assistant is NetToMPlayer merged with LaunchMPlayer. It opens both online and offline videos and it's useful if you want to use only one of the applications. All three have their HD counterparts, and all three launch MPlayer in a separate process. In other words they quit immediately after having invoked the video player, so they won't waste resources during playback (this means you have to be patient when you open online videos; it takes Mplayer a second or so to come up after the script has finished its work).
Have fun, and let me know if you find ways to improve these scripts.