Friday, December 26, 2008

120Hz Importance to a consumer

This is an email I wrote to a group at the office explaining 120Hz with respect to HD TV sets. (Keep in mind this is written for an American audience, so I used the NTSC standard 30fps (60 fields/second). European countries have a different electrical system which operates at 50Hz thus there television standards (SECAM, PAL) were defined as 25fps (50 fields/second)
-----
There is a lot of incorrect information out there about 120Hz. There are two separate technologies and problems being solved, however, most sales people cannot separate them.

So first let us define the problems
1. Judder - This is when the image appears to stutter on sweeping camera moves or similar. Judder occurs because of a difference between the refresh rate of the display device and the frame rate of the source.

2. Motion Blur - This is an artifact of the fact that all video/film is moving pictures (e.g. sampled). The blur occurs because our eyes bridge the gap between frames.

Below we will define the two technologies which are unfortunately both referred to as 120Hz by most people

1. 120Hz - this is the refresh rate of the monitor, so how many full frames/fields per second which can be displayed. (Most devices have historically had 60Hz refresh)

2. Auto-Motion Plus (Samsung's TM, Sony named theirs MotionFlow) - This is an interpolation technique which attempts to create intermediate frames to increase the clarity and decrease the bridging your eyes need to do.

Now we know the two technologies and problems we are trying to solve.

The 120Hz (refresh rate alone) is designed to solve judder. To explain why this is we need to learn a little about video/film. As you may know film is recorded at 24 fps (frames per second), TV programing is filmed in 30 fps (60 Hz interlaced). So with a 60 Hz display we get a none equal pattern to display film (24 fps) with 60 Hz we get a 3:2 pattern so the first frame is displayed 3 times, then the second twice and that continues to fill out 24 fps into 60 fields/second, this is where the judder comes in as there is a caddence mismatch between the original film and the display. To correct this we look to 120Hz and the display rate becomes 5:5 each frame is displayed 5 times thus creating a standard cadence (however, the 3:2 cadence is hard coded into standard DVD video so you need to rely on a good de-interlacer to restore the original 24fps and then pass them at that rate to the TV so that we get 5:5 output.

The Auto-Motion (interpolation) changes the original quality of the video because it is adding frames that didn't originally exist. Some people like the extreme crispness of the image it produces. I prefer to see the directors intent and very much dislike the video which is produced by this interpolation.

So for me 120Hz would be a big buying point today, however, I would need to be able to ensure that the interpolation is off. For a normal consumer I would say it isn't a make or break feature.

Whew that was a lot of typing to let you know that I doubt it would matter to you or your family, however, hopefully it has educated and my assist others in deciding.

Friday, October 03, 2008

Video Encoding with mencoder is a nightmare

I have been spending a lot of time recently working on defining exactly how to accomplish taking my HD feed of television programing, and automatically encoding it to remove commercials and use x264 as the H264 encoding engine. To this end I have found some lacking in the original mencoder documentation. I will try to document each of the filters that I am using in my attempt to complete my task and hopefully help others to not have the same issue(s).

Conventions:
Text which requires replacement will be marked like a variable with a dollar sign ($).
definitions will be preceded by a double hyphen (--)


Part 1. In this section I will provide an automated method to crop a video to remove all of the black bar area. The remaining video area will be the correct aspect ratio...etc. as mencoder corrects this for us.

Step 1 is to get the crop value. The easiest method is to use mencoders brother mplayer and the cropdetect filter

mplayer -vf cropdetect $videofile

cropdetect -- outputs to console the current crop values to remove the black area around an image as mplayer plays. output will be similar to [CROP] Crop area: X: 0..1738 Y: 0..1079 (-vf crop=1728:1072:6:4). (units pixel)

Now you can just copy paste the -vf crop line and run mencoder with the crop filter.

crop=w:h:x:y -- crops a video frame to w by h and offsets the frame by x:y from the top left corner. Keep in mind you must be re-encoding the video otherwise crop is meaningless. (units pixel) Crop can be used in both mencoder and mplayer...so you can test the crop values by doing

mplayer -vf crop=$cropvalues and see how the frame will look.
and of course to encode
mencoder $infile -vf crop=$cropvalues -ovc $video_codec -oac $audio_codec -of $output_formatdefaultavi -o $outfile

Step 2 Now how do we string these two items together? cropdetect and crop?
Answer: Scripting, woo.

As I am using windows and my HTPC is windows I am writing my scripts in batch but, you should easily be able to convert to perl/bash...etc.

1. Let's get the crop detected values into a text file that we can find within (this is far easier with GNU tools such as grep than Windows find. But here is the line I use

mplayer -vf cropdetect -ao null -vo null -frames 5 $infile | find "-vf crop=" > crop

This parses 5 lines of the video, and find selects only the lines with crop them to print to the text file 'crop'. Next we need to extract the crop parameter

2. Extract the detected values

FOR /F "tokens=3 delims=(=)" %%G IN ('type "crop"') DO SET crop=%%G

What this line does is, for each line in the crop file extract separate items based upon the delims ((=)) and take the third item (tokens=3) then I set that item to crop

[CROP] Crop area: X: 0..1738 Y: 0..1079 (-vf crop=1728:1072:6:4). is broken into
1=[CROP] Crop area: X: 0..1738 Y: 0..1079
2=-vf crop=
3=1728:1072:6:4

3. use the crop values in your mencoder filter string

mencoder $infile -vf crop=$cropvalues -ovc $video_codec -oac $audio_codec -of $output_formatdefaultavi -o $outfile

Let's put it together

-----
mplayer -vf cropdetect -ao null -vo null -frames 5 $infile | find "-vf crop=" > crop
FOR /F "tokens=3 delims=(=)" %%G IN ('type "crop"') DO SET crop=%%G
--mplayer is a little weird and will sometimes take over the stdout redirection. Here is my replacement way to do this
FOR /F "tokens=3 delims=(=)" %%G IN ('mplayer -vf cropdetect -ao null -vo null -frames 5 $infile') DO SET crop=%%G

mencoder $infile -vf crop=%crop% -ovc $video_codec -oac $audio_codec -of $output_formatdefaultavi -o $outfile
-----

Sunday, June 22, 2008

Best HTPC Front-end

I have been having a lot of fun lately with building my new HTPC. It is based upon my old Gaming Rig, ASUS M2N-SLI Deluxe w/ AMD Athlon XP 3500+ (64-bit) w/ 2GB RAM and a EVGA Geforce 7900. I added a Hauppauge HVR-1800 for TV tuning, it supports NTSC, ATSC, and clearQAM tuning. I put all of this into a new case, a Coolermaster CM-282 which has a built on front panel LCD and Remote Control by SoundGraph.

With the Soundgraph LCD and Remote you get the Soundgraph iMon/iMedian software, iMon provides controls for the Front Panel and Remote, iMedian is Soundgraph's HTPC front-end, and it isn't horrible...but it isn't complete and the performance is not what you would really want. My biggest issue with the iMedian software is that as I delete/add files to my Hard Drive I would need to rescan to update the database. And the scanning is beyond slow for iMedian. So I began looking for alternatives, SageTV, BeyondTV, Meedio (now Yahoo Media Center or something like that)...etc. I found a lot of these did some things better than iMedian, however, overall they were not what I wanted.

Finally I came upon a free HTPC Front End software by a guy from New Zealand, the software is named GBPVR. It not only does everything as well/better than iMedian, it also has a built in TV Tuner that is very feature rich, with built in Electronic Programming Guide (EPG). Now GBPVR still has its issues, however, the developer of the product is extremely willing to help and fix issues. I filed (well opened a support thread on) a bug with DVD Special Features and he had a test fix for me within a few weeks. The issue was that some Special Features are in 4:3 frames and the software was not getting that data and rebuilding the frame, so the video was being stretched. Anways, he fixed that very quickly and he seemed eager to improve his product. For this I gave him $10 USD. As a retail product I would have to pay far more for this but, it is just a donation. Also, remember my main complaint from iMedian, having to rescan all the time, well GBPVR seems to not use a static db but, rather reads the current directory structure. So no phantom files or missing files.

If you, like me, are looking for a good HTPC front-end, I would highly recommend you look at GBPVR.