.comment-link {margin-left:.6em;}

Sunday, October 30, 2005


Sample parameters for ffmpeg

Jay wanted sample parameters for ffmpeg to encode iPod compatible video, so here goes:

Right now, the latest thing I've encoded has the command line parameters:

ffmpeg.exe -i c:\input.avi -y -vcodec xvid -vtag mp4v -vprofile SP -4mv -b 1024 -acodec aac -ac 2 -ab 128 -f mp4 c:\test.mp4

Note that the output resolution (which is important) is NOT specified. This is because the content size I was encoding was within the ipod spec. If you want to be safe, you can scale down until the width is 320. To do this with an arbitrary size, do this:

Using our example size of 576x320.
1) Calculate the aspect ratio by dividing 576 by 320: 1.8
2) Divide 320 by 1.8: 178

OK, so to scale down to a width of 320 we'd use 320x178 for our widescreen content. note that if you get ~1.333 as your aspect ratio it is 4:3 and you can just encode at 320x240.

So how to specify size? The 's' parameter, like so:

ffmpeg.exe -i c:\input.avi -y -vcodec xvid -vtag mp4v -vprofile SP -4mv -b 1024 -acodec aac -ac 2 -ab 128 -f mp4 -s 320x178 c:\test.mp4

This will scale down the image. This video will work fine on the iPod. Keep in mind you can go out of spec a bit if you pick a resolution that has less than 230400 pixels. My video was 576x320 which actually has less pixels than that, so it worked fine to leave the resolution at that.

Friday, October 28, 2005


Update on iPod findings

Well, I've been messing with video for the iPod. I was taking notes, and then turned them into a pseudo-blog-post. I did this because of the ffmpeg frontend that I'm writing, as previously mentioned. I need to figure out how to encode my own video that will play on the thing, and I need to figure out what the out-of-spec limits of the iPod are, and how it handles various situations. That sort of thing. Here they are:

iPod Video findings:

- The iPod defaults to widescreen mode where it letterboxes widescreen content. It does this for any widescreen aspect ratio, not just 16:9

- You can feed the iPod any size video with at most 230,400 pixels. The actual specs Apple gives of max 480x480 is dumbed down. BTW, 480x480=230,400

- The max 4:3 res that can be handled that has whole number sizes is 552x414. That's actually a bit less than 230,400 so it gives a nice little buffer in case of 1 or 2 pixel sizing errors.

- The iPod cannot handle anamorphic content (It crops), so if the player detects less wide than 4:3 (like 1:1) then just scale it to 4:3. If size is too big just scale down to 552x414

- 4:3 content: If greater than 552x414, scale down. If not, leave res as-is.

- Widescreen content: If less pixels than 230,400 leave as-is. If not, figure out how much it needs to be scaled down to stay under 230,400

Much video will NOT need to be scaled down. For example, my DVD rips of Babylon 5 are encoded at 576x320. This is only 184,200 pixels, so I can just transcode the format without touching the resolution, and the iPod will letterbox it.

Why would I want to encode at higher resolutions than 320xSomething since that is the iPod native screen size? Well, because the higher resolutions are going to look sharper than just scaling it. You get a bit of moire patterns though, but it's worth it. Also, the iPod Video can output to TV via S-Video or Composite with the right cables, and it might only output at 320x240 but it might output the actual res too. I didn't buy the cables so I can't experiment.

While the ipod supports up to 2.5mbit for MPEG-4, if you actually set the res to the admittedly outside spec res of 552x414 and then run at 2.5 megabits, you're probably going to be stressing the video decoder some. Since the screen is still only 320x240, there is NO point encoding video at that kind of bitrate. I'm doing my test videos all at 1mbit, and I can't really see any visible artifacts. In the darker bits I can sort of make out macroblocks, but in normal brightness I can see none. So maybe you would try 1.5mbit, but not really any higher. I've set 1.5mbit as the max bitrate in my frontend's iPod profile, and I'm trying to decide if the default should be .75 megabit or 1 megabit.

The problem with encoding video by hand with ffmpeg is that you're going to have to figure all this stuff out. I could write a human script to run through for people to figure out what resolution to use, but it's going to be annoying to run through and it'll involve some annoyingly long math for some situations. The frontend should be able to handle all these situations by itself by default. Oddly enough the few other iPod converters that I found (One of which was based on ffmpeg too, the other used it's own encoder) did not do any of this on their own. They just scale to 320x240, and don't even correct the aspect ratio. They just assume the content is 4:3 and directly scale from anything to 320x240.

So, encoding using my frontend should be as simple as to open file(s), select iPod as profile, select bitrate, select resolution (320x240 or automatic max) and hit encode. Audio settings are handled by the program, it selects an audio bitrate based on your video bitrate. Yeah, I could let the user select that too, but really there is no need, since that adds useless complexity. They can make their own profile if they want.

I haven't checked how different framerates are handled yet. My Babylon 5 stuff is 24FPS (Well, 23.98). Hopefully 30FPS (Well, 29.97) is handled properly too. I'll experiment further later.

EDIT: If you're wondering why I'm not worrying about h.264, that's because there is not really any benefits to using it on the iPod. It is more limited than MPEG-4 so has lower quality. It encodes several times slower. It's really only useful for lower-bitrate lower-quality videos, and iPods are huge (30GB minimum now). YAGNI.


Money goes out, stuff comes in

I got me one of them new-fangled eye-pods. The one with the moving pictures. From those fruit people.

I've already been working on a nice ffmpeg GUI frontend, so now I'll actually be able to test the iPod profile I wrote.

I'll let you guys know when the frontend is done. It might run under linux/OSX, since it's written in C#, but Mono is pretty incomplete despite what they claim, so we'll see. Really it's target market is me, myself, and I, so that means primarily Windows.

Besides, OSX has the awesome ffmpegx, and linux folks are not the kind to use GUI frontends anyhow.

Wednesday, October 26, 2005


Technical Writing mark

Just got the technical writing mark, %68. A bit lower than I expected, but apparently it's pretty decent for this course.


Midterms complete

I've been meaning to post something for ages, but each time I see something and think "Gee, I should blog about that," it just slips my mind. So here I am, actualling posting something this time.

Well, midterm results are in and I didn't actually fail anything, which is good, I suppose. I did end up dropping Discrete, for lack of time. So far it looks like that is working out for the best; the same amount of time is being spent on courses, except now there is more to spend on cal.

So without further ado:

Calculus 1: %53
Linear Algebra (Vectors + Matrices): %82
System Hardware (Assembly programming): %90
Technical Writing: %50 to %100

%50 is a pass, so I technically passed Calculus. I'm not exactly thrilled with the mark, but it IS a pass, so I'll take it. The mark could have easily been 70 or higher had I simply remembered two very short very simple rules, but I blanked out. Not enough time spent studying, I guess.

As for technical writing, I don't yet know the mark (I'll find out in an hour or two), but I do know I passed. I'm going to guess %70 to %80, and I'll post an update when I find out.

Could be worse I suppose. Good news is I'm not failing anything so far, bad news is I still hate algebraic math like Calculus. I don't mind Linear that much, and assembly programming is great fun.

This page is powered by Blogger. Isn't yours?