Saturday, May 21, 2011

HD On an Old Mac With mplayer

Probably the one thing, judging by people's statements in the many Mac forums, that makes people upgrade to Intel more than any other is HD video playback. They say their old Powerbook/Powermac is too slow, playback is choppy, or even [shiver] slideshow-esque. But in my extensive studies;) on this issue, I've found this isn't only a hardware question. There is a software component that many people aren't adequately exploring.

It should be noted right here, though, that if you're talking about flash video streamed in HD over the internet, you're most probably permanently out of luck. Flash is dead on PPC, and it was never any good when in active development, and HD video pushes it past the edge on everything except maybe a G5 quad.

But if you're talking about H.264 files like mp4's and mkv's, you may be in luck. By now you've probably tried Quicktime with the Perian plug-in or VLC and found the results lacking. Playback stutters, your computer's too slow, and you're back to square one. However, there's another player that's much more CPU efficient called mplayer, specifically, running the mplayer binary from the command line.

You can download a GUI version, MPlayer OSX, that's a bit long in the tooth here (UPDATE: a newer binary is available inside this app package). Maybe you've tried it before and didn't like it because the GUI was old. But the real strength of mplayer is the many parameters you can use from the command line. There are literally hundreds, too many to fit into a GUI, and a few of them greatly enhance playback on slower computers.

So the point of the above download is not to use the GUI, but to extract the binary by control-clicking on the app and choosing "Show Package Contents." Open Contents-->Resources-->External_Binaries and control-click on "mplayer_ppc.app" if you're on a G4 or "mplayer_noaltivec.app" if you're on a G3. Choose "Show Package Contents" again and open Contents-->MacOS and there's your binary. Duplicate "mplayer" and move it somewhere convenient like your desktop or applications folder. Other people say create a symlink to your /usr/local/bin, but my system doesn't have that folder, and now is not a good time for me to break my system so I'm gonna steer clear of that, thanks very much. I just put it in my applications folder and invoke it with /Applications/mplayer in Terminal.app. Luckily I don't have to type this out every time as I can hit the up arrow key to cycle through my previous commands.

Now let's fire up mplayer and experiment with its parameters. The simplest way is to enter /Applications/mplayer in the terminal, then add a space, then drag the file you want to play onto the terminal window. You will now notice the path to file has been printed after the final space like this:

/Applications/mplayer /Users/username/Desktop/themostgodawfultabooyoucanthinkof.mp4

Now press return and a window should arise playing the movie. And there are several keys to control playback, a listing of which is here. Arrow keys for moving backward and forward, f for fullscreen, q for quit, etc. No command-key necessary.

At this point, you'll say, "Great, but it's not that much different than VLC or Quicktime. It still stutters." That's because you're not using any parameters (slapping you upside the head). Now try this (all on one line):

/Applications/mplayer -really-quiet -framedrop /Path/To/File (no space between -really and -quiet)

(Incidentally, you can download a Star Trek trailer here that we can use as a common reference. It's a 720p mp4, and it's dubbed in Spanish!)

The -really-quiet is for reducing the output in the terminal window as the movie plays. The -framedrop is to skip late frames and keep the audio in sync.

Now you may say it's a little better, but still not there. Well, it's a little better than VLC/Quicktime because there's no GUI taking away CPU cycles. It only displays the movie itself. Quick demonstration: Play a movie in MPlayer OSX PPC and open Activity Monitor (or run top if you prefer). Notice how there are two entries, one "MPlayer Window" (the video itself), and the other "MPlayer OSX PPC" (the GUI). Notice the GUI using an additional percentage of your CPU in addition to the movie playing?

Now let's go back to the command line and add another parameter like this (again on one line):

/Applications/mplayer -really-quiet -framedrop -lavdopts skiploopfilter=all /Path/To/File

With the above Star Trek trailer, I can now view it stutter-free on a 1.5 GHz G4 Powerbook, something I can't do with VLC or Quicktime. However, you may not have a 1.5 GHz G4, and you still can't see smooth playback. Is there anything else you can do? Yes, with a qualification. You can add another option to the -lavdopts parameter, skipframe=nonref, that will reduce CPU usage by about 50% by skipping some frames to decode. This will result in something of a blinky effect like you're looking at an old zoetrope, but it makes a lot of files playable that weren't before. You can try it and see if your eyes adjust to it or not. Enter this (all on one line):

/Applications/mplayer -really-quiet -framedrop -lavdopts skiploopfilter=all:skipframe=nonref /Path/To/File

Also, I don't have a dual processor to test this on, but you can assign two threads for decoding with the -lavdopts option "threads=2" so it would read (all on one line):

mplayer -really-quiet -framedrop -lavdopts skiploopfilter=all:threads=2 /Path/To/File

So there you have it, the tools necessary to run HD video on your PPC Mac. There is one minor hitch in that the binary we used above is from December, 2006, and although it works with almost any file you throw at it, it doesn't correctly decode some newer AVC files. So the only solution here is to get an up-to-date binary, which you can only do by compiling it yourself, which I have no idea how to do. So I'll be writing a future post on my adventures or misadventures in compiling, depending on how things go.

One last thing. I noticed on a Sawtooth with an ATI Rage 128 Pro video card, the option -vo quartz is less demanding on the CPU than the default CoreVideo, but there's no difference on an aluminum Powerbook. My guess is it's because the Sawtooth's video card is not Quartz Extreme capable, but in any event you might want to use -vo quartz if you're running on a calcified card like the Rage 128.

8 comments:

  1. CorePlayer, a shareware application, plays 720p without any problems on a PowerBook G4 1.67Ghz (at 80% cpu usage) and 1080p on G5. Probably most efficient decoder ever written on PPC, but plays only h.264 (mkv, flv, avi).

    ReplyDelete
  2. I use MPlayer OSX Extended. It plays EVERYTHING. Far better than VLC. Highly recommended. I haven´t tried the command line version. GUI works perfect for me on my PowerBook G4.

    As always, great post!

    ReplyDelete
  3. Ale Nu: Does that mean, thah MPlayer OSX Extended plays 1080p mkv files?

    ReplyDelete
  4. It does on my PB... I have noticed some sort of "latency" between image and sound sometimes, on highest quality files, but overall MPlayer does a terrific job.

    ReplyDelete
  5. Thanks for the great article (and blog in general). I've tried both binaries [from 1.0rc1 and 0.21], and I noticed that the OSD option:

    -dxr2 ol-osd

    doesn't work; just get an "Unknown option" error. Any luck getting an OSD when executing from the shell?

    ReplyDelete
    Replies
    1. OSD support has always been spotty for me. I've never gotten it to work completely.

      Delete
    2. C'est la vie ... was just looking for a way to get the [(P): Show progression bar, elapsed time and total duration on the OSD] key working.

      Anyways, thanks again for the blog, and keep up the good work!

      Delete
    3. Ha ha, that's exactly what I tried to get working. No luck!

      Delete