plex.us logo section: outbursts
about
archives
news-portal
photographs
videos
 

General notes

Changelog for this page.

Using ffmpegX 0.0.9r 0.0.9s to encode, which uses mencoder (docs) to do the heavy lifting.

I convert movies to XviD so I can fit more of them onto my iBook for use when travelling. I use Handbrake most of the time, since it's fast (uses both cpus too) and does a good job. Sometimes it falls down though, and that's why I got into ffmpegX. Ironically, I use the ffmpeg setting in Handbrake, but when using ffmpegX, I use mencoder.

QuickTime player audio sync is off when playing movies I made with AC3 audio. I'm using a third-party AC3 plugin to support AC3 playback.

Using mplayer osx version 2b8r4 for playback testing.

Hardware: MDD G4 with two 1.42GHz G4 cpus. OS = Mac OS X 10.3.8.

I found that using MPEG4/mencoder is quite fast - it seems to be multi-CPU-aware and I achieved effective speeds of 25-30fps (per pass) on a recent encoding run with High Quality and Trellis Quantization turned on.


>>Real world example with Sling Blade (1996)

Output size and cropping

This is the first challenge I faced. Ideally this gets done automatically, but it wasn't working.

Cropping

I needed to do cropping to kill the black bars. Going to the Filters tab and hitting Preview forked a child process (I saw it briefly appear in the dock and then disappear). Preview didn't work! That would make cropping a very laborious process.

I decided to just encode one chapter of the movie as a test, so I put chap 3-3 in the Video tab. This was a lucky guess for me - Preview worked fine for this chapter and I was able to see the video and adjust the cropping parameters accordingly. It seems that ffmpegX version 0.0.9s uses a more sane method for cropping (according to the release notes) but I haven't tried it yet.

Preview didn't work for any other chapters I tried, but chapter 3 was good enough, and mplayer showed a white box indicating the cropped area.

Also I should mention that Autocrop didn't work for this movie. It either put in all zeroes, or a bunch of negative (!) numbers.

Version 0.0.9s handled all this correctly and autocrop and preview worked for all chapters.

Determining the aspect ratio and dimensions

ffmpegX 0.0.9r chose 720 x 480 as the size and 3:2 as the aspect ratio. Version 0.0.9s chose 640 x 272 at 2.35:1. Neither one was correct.

So I did the cropping but was still having problems with the aspect ratio. 3:2 was clearly not right and 1.85:1 (720 x 384) was horizontally stretching the video too much. At this point I should mention I used 716 348 2 66 as the cropping params. So the video was 720 x 348 (note! 348 not 384) final output size.

I was in error here: in the testing I was so busy looking at quality that I overlooked the fact that the video was still playing at the wrong aspect ratio (about 2.05:1 at this point).

Then I chose 16:9 aspect and ffmpegX put the correct size of 720 x 400 (1.8:1). Encoded this and it was correct and matched the DVD.

But then I realized that was going to scale the video up by 4 pixels horizontally from 716 to 720 which seems less than ideal. Up-scaling just seems unnecessary. Perhaps more importantly, I thought, I was taking a 348-pixel vertical crop and scaling up to 400. So I decided to go with 348 as a final output height.

Now (348 x 16) / 9 = 618.67 so I wanted to use 618 as the final output width. ffmpegX would not allow this: width must be divisible by 16! I took 618 / 16 = 38.625 and rounded that up to 39, then did 39 x 16 = 624 to get my final output width. I left the height the same at 348, for a final size of 624 x 348.

Guess what? 624 x 348 is a 1.85:1 aspect ratio. Looks like everything's finally working out mathematically. Sometimes I do things the hard way. If there's an easier way, I didn't find it. Even though the aspect ratio is set to 16:9, the actual ratio is 1.85:1, which might be explained by taking into account the non-square pixels that DVDs use. I'm not gonna do that math here.

(Using version 0.0.9s, ffmpegX chose 640 x 352 as the video output dimensions when I chose 16:9 aspect. This seems like it would be OK, but I didn't try it. The cropped size was 350 under 0.0.9s, so scaling up 2 pixels to 352 seems less than ideal. I would just change the cropped size to 348 again.)

Since the width must be a multiple of 16, I think it best to start from 720 pixels and work your way down. This gives us some options for 16:9:

720 x 404
704 x 396
688 x 387
672 x 378
656 x 369
640 x 360

Video encoding

I tried four different combinations of codecs and encoders. I didn't realize MPEG4 meant Divx, or I would have ignored it. Anyway, I like the output from mencoder so I stuck with XviD using mencoder and an AVI container. One goal I had here was to make something with pretty wide playback compatibility, so I ignored things like the MP4 container, AAC audio, etc.

MPEG4 (Divx) / mencoder - non-ideal quality even with maximum quality settings!
audio OK

XviD / mencoder - ok quality, fast
audio OK

MPEG4 / ffmpeg - quality problem

XviD / ffmpeg - ? I think there was an audio sync problem

Bitrate

I determined this by the video dimensions. I kept entering rates until the indicator was green in color. That was at about 1100 kbit/s for my chosen dimensions. You can also use the built-in calculator to make the movie fit on different media types. So I used the Best option to give 1169 kbit/s.

Quality settings

I chose high quality and Trellis quantization because the colors came out looking somewhat better. There isn't that much of a difference in my eyes, but that may be due to the source video more than anything else.

Audio encoding

Sling Blade has an AC3 audio track. The ffmpegX instructions say to use 448Kbit for calculation purposes.

(I tried MP3 and it worked fine. Ultimately I decided to use Passthrough to add the AC3 audio without any re-encoding. That's cool!)

However, it looks like the audio was being reduced to 2-channel no matter what options I chose. Still not sure what's up with this. I double-checked the DVD itself and the English audio is AC3 6-channel (5.1). But mencoder thinks the source audio is 2-channel at 192 kbit/s so it's just using that bitrate. It must be correct - even though other tools say the audio is 6 channels. Mencoder is just copying the audio without re-encoding, and I don't see how it could copy 6 channel down to 2 without doing some work.

If I chose Passthrough, it was also coming out as 192 kbit/s. I switched to AC3 encoding and it came out as 448 kbit/s but still 2-channel.

Another idea that I didn't try is ripping the AC3 from the VOBs and then muxing it with the XviD video at a later time. I want to avoid this sort of multi-step process.

Final settings for Sling Blade

Codec: XviD [.AVI] mencoder
Video size 624 x 348, ratio 16:9, framerate NTSC FILM
Video bitrate: 1169 kbit/s
Audio: Passthrough (source is 192 kbit/s AC3)
Crop: 716 348 2 66 (crop for 0.0.9s: 66 66 2 2)
Options (mencoder): Two-pass, High Quality, Trellis quantization
Scaling: Bicubic spline
Keyframe interval: 180
Qmin 2, Qmax 15

Commands (one line each of course)

The first command it runs is:

'/Library/Application Support/ffmpegX/mencoder' dvd://1 -dvd-device \
/Volumes/SLING/VIDEO_TS -nosound -ovc copy -o /dev/null 2>&1 | grep 'secs'

which outputs (I guess ffmpegX uses to aid the progress bar display):

Video stream: 3924.849 kbit/s  (490606 bps)  size: -324741081 bytes  8092.493 secs  194022 frames

And then the actual encoding, which is two commands (separated by '&&'):

'/Library/Application Support/ffmpegX/mencoder' dvd://1 \
-dvd-device /Volumes/SLING/VIDEO_TS -dvdangle 1 -oac copy -aid 128 -ovc xvid \
-sws 10 -xvidencopts bitrate=1169:max_key_interval=180:vhq=3:trellis:pass=1 \
-passlogfile sling-outD.XviD.menc.ac3.avi.log \
-ofps 23.976 -vop scale=624:348,crop=716:348:2:66 -noodml \
-o sling-outD.XviD.menc.ac3.avi \
&& \
'/Library/Application Support/ffmpegX/mencoder' dvd://1 \
-dvd-device /Volumes/SLING/VIDEO_TS -dvdangle 1 -oac copy -aid 128 -ovc xvid \
-sws 10 -xvidencopts bitrate=1169:max_key_interval=180:vhq=3:trellis:pass=2 \
-passlogfile sling-outD.XviD.menc.ac3.avi.log \
-ofps 23.976 -vop scale=624:348,crop=716:348:2:66 -noodml \
-o sling-outD.XviD.menc.ac3.avi

Results

Quality

I'm satisfied with the quality of output. The source movie isn't perfect, so that has an impact here. I did pay plenty of attention to this, but of course after watching the source video from the DVD, you are spoiled.

Encoding Speed

I didn't pay attention to the exact time to complete encoding. For one thing, I was doing other activities in the foreground while encoding was happening in the background, which would affect the speed. The source video was on a file server connected via gigabit ethernet. At some times I was encoding two files at the same time. But while doing quick tests, I saw speeds of about 25 fps for basic quality video, and 5 fps for maximum quality settings. Keep in mind that although 25 fps is real-time performance, there are still two passes, for an effective 12.5 fps. With final options, I'd estimate about 8 hours to complete the entire movie.

Final file size was: 1,127,876,068 bytes.


>>Real world example with The Lady From Shanghai (1947)

Codec: XviD [.AVI] mencoder
Video size 704 x 528, ratio 4:3, framerate NTSC FILM
Video bitrate: 1857 kbit/s
Audio: Passthrough (source is 192 kbit/s AC3)
Crop: 0 0 6 0
Options (mencoder): Two-pass, High Quality, Trellis quantization
Scaling: Bicubic spline
Keyframe interval: 180
Qmin 2, Qmax 15

This movie is B&W, and I think a much lower bitrate could be used if the color data could be discarded. Not sure how do this, if it makes sense, or even if it's possible with MPEG. Since the vertical size was scaled up from 480 (DVD source) to 528 I was concerned with quality but it actually came out looking amazing. The source material is very flat and smooth so that helps. I can play this back in full screen mode at 1024 x 768 (the iBook's resolution) and it looks perfect.

Final file size was: 1,102,606,580 bytes.

Changelog

2005-02-26

Added info about Divx and dual CPUs.

2005-02-21

Page started with two examples.