Glenn's Junk Chest

An assortment of Glenn's writings, photography, gaming resources, flash movies, and other creative output.

Tuesday, February 07, 2006

Video: DVD video onto a PSP using a Mac

Well, I've been looking into this a lot lately.

An MPEG4 file that is playable by the PSP has the following characteristics:
1) It is 320x240, 368x208 or 400x192
2) It has a framerate of 29.97 or 14.985 fps.
3) It has stereo AAC audio at 24000 hz.
4) Its total bitrate is no greater than 768 kbit/sec.
5) It is named in the format "M4V#####.MP4", where ##### are numerical digits, and placed on the PSP's memory stick in "/MP_ROOT/100MNV01/"
6) It has properly formed PSP-friendly headers.

Optionally, there can be a second "thumbnail" file accompanying the MP4, which is a 160x120 jpeg image named "M4V#####.THM", where the ##### are the same numbers as used for the video file. This file is entirely optional and has no other features.

If any of the above 6 things are not true, it won't play. If you're on a Macintosh, and you have arbitrary source material that Quicktime can read, I recommend using the altShiiva application. (google translated version). Since it reads files using Quicktime, it's very input friendly, and, once you figure out its quirks, quite dependable. If you produce output that is 368x208 or 400x192 you'll need to run it through a command line utility called PSPREZ before it will work, since files at those resolutions require deliberately malformed headers in order to work. (no kidding.)

I, of course, totally hate it. The documentation is in Japanese, it doesn't appear to be frequently updated, and there's no provision for saving your settings, so you have to make sure you get them right every time you launch the app. Many people prefer to use ffmpegX on the mac, but I find it buggy and the UI confusing, and some of what it's doing under the hood really perplexes me. What I really want to do is use ffmpeg from the command line, because that way I can simply record the command line I used and reuse it, modified as needed.

Here's what I currently do when I want to go from a DVD to PSP on my Mac. I capture the video using Handbrake, to a reasonably high quality MPEG4/MP3 AVI, typically at 480x272 resolution. I do this because I figure if I keep this file, it's a useful resolution for playback on my TV or Mac, and if I gain the ability to compress a better PSP version in the future it's already at the PSP's native resolution. (I also like this format because it will play on my PS2 over the net using the media player software from gameshark. In general, I find it a good format for legacy devices.)

Then I use the ffmpeg command line that's built in to the PSPWare application. ffmpeg can be compiled in a bunch of different ways, with a bunch of different options, but the one in PSPWare is already compiled with the necessary libraries and extensions to do proper PSP output, and is capable of reading the AVI I just created without modification.

I then issue a command like this:

./ -y -i /Vid_Movies/SteamBoy480.avi -title "SteamBoy" -s 368x208 -r 29.97 -b 450 -acodec aac -ac 2 -ar 24000 -ab 32 -f psp /Vid_Movies/M4V10102.MP4

The "-i /Vid_Movies/SteamBoy480.avi" is the source
The "-title "SteamBoy"" is the name that will appear in PSP menus
The "-s 368x208" specifies the video size.
The "-b" is the bitrate for the video
The "-ab" is the bitrate for the audio
The "-f psp" switch tells ffmpeg to do proper PSP output, and it does proper headers so there is no need for PSPREZ.
The "/Vid_Movies/M4V10102.MP4" is the output file name, already in a PSP-acceptable format.

ffmpeg has a lot more options, but I find that this is a pretty good starting place. I rarely use the others except sometimes for cropping or padding video.

As a bonus, the ouput of this command will work on a video iPod without further modification, though you'll probably want to change the filename to something less crufty.

If you're interested in compiling your own ffmpeg that will do this, I suggest you look at the one in PSPWare. It displays the following information when it is run:

ffmpeg version 0.4.9-pre1-based-MobileHackerz030, build 4743, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-faac --enable-a52 --enable-gpl --disable-ffserver --disable-ffplay --enable-memalign-hack --disable-vhook --extra-cflags=-mtune=970 --enable-pthreads --enable-faac --disable-mmx --disable-audio-oss --disable-audio-beos --disable-v4l --disable-debug --disable-pp --enable-g726 --disable-network --disable-gprof --extra-cflags=-force_cpusubtype_ALL --disable-strip --disable-shared
built on May 22 2005 23:36:15, gcc: 4.0.0 20041026 (Apple Computer, Inc. build 4061)

Sometimes, I want to do a compression from DVD to PSP overnight, without being on hand to initiate the second step of the two-step process. When that's the case, I often do something like this on the command line:

sleep 13800 ; ./ffmpeg -y -i /Vid_Movies/SteamBoy480.avi -title "SteamBoy" -s 368x208 -r 29.97 -b 450 -acodec aac -ac 2 -ar 24000 -ab 32 -f psp /Vid_Movies/M4V10102.MP4

This tells the shell to do nothing for 4 hours, then run the command that comes after the ;. Since I can count on handbrake being done by then, this allows me to have it happen without intervention. If I'm ripping multiple things from a DVD, I can even queue them up with multiple commands, separated by semicolons.

Update: My company, Clotho Advanced Media, Inc., has now written a command-line utility for OS X that allows for Quicktime conversions on the command line. Using it, I can now convert from a much wider variety of sources into PSP (and thus iPod) playable formats. In order to do this, I first convert it using our tool into an intermediary format that ffmpeg can process, and then use ffmpeg to convert it into PSP format. This is proving pretty succesful for us, and we're likely to put it together into a commercial offering at some point in the near future.


At 2:37 PM, Anonymous Anonymous said...

Where do i type in the command line. I dont see that in any of the apps options.

At 9:37 AM, Anonymous Anonymous said...

The trick is that the apps hide the command line stuff from you because they figure you don't want to see it. The way (on Mac OS X) that you can get at that command line is to look inside the application's package.

Typically, you'll do this from Apple's "Terminal" utility. If you've never used it, you'll probably want a quick primer from someone who has. Anyway, you get into directories (and thus application packages) by using the "cd" command, and you can list the contents of those directories using "ls".

Armed with that knowledge, you can cd into the package, follow the path "Contents/Resources/", and you'll find the ffmpeg command inside there. You can copy it out if you need. Once there, you can run it by typing ./ffmpeg [arguments]

At 12:41 AM, Anonymous Anonymous said...

To initiate two commands sequentially, separate them by '&&' (without quotes). If you type one command then on the same line the second command after the double-ampersand, the first will start, and when finished the second will begin.

At 12:46 AM, Blogger Glenn said...

Right, I belive you can also do this with a semi-colon. The reason I use the sleep 13800 in the above example is because the first operation is done with a GUI tool, and I don't know quite how long it will take, but 4 hours is certainly long enough.


Post a Comment

<< Home