Re: H.264 Profile and Level

Mike Pelley <[email protected]>
Newsgroups gmane.comp.video.freevo.devel
Message-ID <[email protected]>
Hey Jason,

On Wed, Sep 15, 2010 at 11:42 AM, Jason Tackaberry <[email protected]> wrote:
> Although, is parsing the output of mkvinfo an option for your use-case?
> I didn't know mkvinfo would dump codec private data.

Not exactly ;o)  mkvinfo gave me most of what I needed by default.
For the codec private data, however, I had to run mkvinfo -v -v -v,
which reports offsets for fields.  I was able to combine a few offsets
to locate the private data, after which I could do a simple read of
the relevant bytes in python.  It felt messy enough that I started to
look for an alternative and found kaa.metadata.

On another note, I wrote to the author of mkvinfo when I was working
on that approach, and he added the level (and maybe the profile) to
the codec private line of the output.  I haven't tried it yet, as I
had switched to kaa before he added the feature.  I use mkvinfo a lot
though, and will download the new version to try it out shortly.

> I could imagine other scenarios where having access to the profile and
> level would be useful.  I might want to expose these as video track
> attributes.  Would you mind sharing the code you're using to parse this
> out?

It's pretty minimal, but seems to work correctly:

    meta = kaa.metadata.parse(source)
    [stuff]

    # i is the video track number
    (h264_profile, h264_level) = struct.unpack_from('>HB',
meta.video[i].codec_private_id[1:4])

The profile is encoded as follows:
    0x42E0 - Baseline Profile
    0x4D40 - Main Profile
    0x58A0 - Extended Profile
    0x6400 - High Profile

And to get the level you just divide by 10 (e.g. 0x1f = 31, 31/10 = level 3.1).

> Yes, I've meanwhile added 'codec_private' as core attributes for video
> and audio tracks, which is initialized to None when not present, or a
> string of bytes when it is.
>
> Thanks for the submission!

Excellent - thanks very much!

Mike.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.