jpoet / HauppaugeUSB

MythTV wrapper around the Hauppauge HD-PVR2/Colossus2 driver
GNU General Public License v3.0
16 stars 5 forks source link

MBAFF encoding of interlaced content #14

Closed skunge2000 closed 4 years ago

skunge2000 commented 5 years ago

I noticed that 1080i25 content recorded by hauppauge2 is always in separate field mode (where effectively the h.264 encoder codes each 1920x540/544 field separately) rather than in MBAFF mode where the encoder looks at both fields as an interlaced frame and then at a macro block level analyses each block for static content (where the block will be coded 'frame' progressively) or moving content (where the block will be coded 'field' interlaced) Very early h.264 interlaced encoders were separate fields only - but MBAFF offers significantly quality improvements so is now near-universal in Blu-ray and DVB encoding.

MBAFF encoding almost always delivers significantly improved picture quality for a given bitrate.

Looking at the original Hauppauge source code for references to MBAFF there is reference to a "VideoCodingMode" attribute (which hauppauge2 doesn't expose - unlike the other related attributes like VBR Max/Min, Audio format etc) This "VideoCodingMode" has 4 values - 0 (Frame), 1 (Field - which I take to mean Separated Fields), 2 (MBAFF - usually the best quality choice), 3 (PAFF - which is like MBAFF but decided on at the frame rather than macro block level - and good for handling psf content where there is no motion between two fields in a frame - i.e. p25 content carried in an i25 stream)

I'm not a coding expert - but would there be an option of exposing the "VideoCodingMode" in hauppauge2?

(And thanks so much for your efforts in improving the functionality of the HD PVR2 in Linux - it's hugely appreciated!)

jpoet commented 5 years ago

I can take a look at exposing that as an option. Unfortunately, it will likely be a few weeks as I am busy with other things right now.

skunge2000 commented 5 years ago

OK - I'm not an experienced coder - but by looking at Common.h, hauppauge2.cpp and HauppaugeDev.cpp I've added a new command line option 'videocodingmode,X' that sets _HAPI_CODING_MODE to 0=Frame, 1=Fields, 2=MBAFF, 3=PAFF

It runs and checking with MediaInfo the h.264 video that is output is now encoded in Separated Fields with option 1, and encoded with MBAFF interleaved fields with option 2. MBAFF interleaved fields should be a more efficient encode (assuming the encoder properly implements it).

(MBAFF has replaced Separated Fields encoding for interlaced content in DVB encoders and Blu-ray mastering for around 10 years or more. PAFF is better than separate field for 25/29.97p native content carried interlaced, but MBAFF outperforms it for native interlaced content)

I've never used GitHub to submit code before - I just cloned to a local directory and modified locally.

What's the best way for a total git noob to submit the changes?

Do I need to fork your repo, make the changes to my fork, and then submit my changes to your git master repo somehow?

pal-saugstad commented 5 years ago

Thanks. This new videocodingmode option works fine for me!