After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 644233 - Set the H.264 level from the caps for encoding
Set the H.264 level from the caps for encoding
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-ugly
git master
Other Linux
: High critical
: 0.10.19
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 651318 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-03-08 19:45 UTC by Olivier Crête
Modified: 2011-07-13 18:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
good: rtph264pay: Implement getcaps (5.52 KB, patch)
2011-03-08 19:45 UTC, Olivier Crête
none Details | Review
base: codec-utils: Add method to convert H.264 text level in a level_idc (3.57 KB, patch)
2011-03-08 19:46 UTC, Olivier Crête
none Details | Review
ugly: x264: Use profile and level from caps (8.54 KB, patch)
2011-03-08 19:47 UTC, Olivier Crête
none Details | Review
ugly: x264: Use profile and level from caps (8.54 KB, patch)
2011-03-09 21:31 UTC, Olivier Crête
none Details | Review
x264: Use profile and level from caps (11.99 KB, patch)
2011-06-01 11:35 UTC, Olivier Crête
none Details | Review
x264: Use profile and level from caps (12.13 KB, patch)
2011-06-01 11:48 UTC, Olivier Crête
none Details | Review
x264: Use profile and level from caps (12.07 KB, patch)
2011-06-10 00:22 UTC, Olivier Crête
none Details | Review
tests: Test x264enc profiles from the caps (4.92 KB, patch)
2011-06-10 00:22 UTC, Olivier Crête
none Details | Review
x264enc: Select stream-format based on caps (3.53 KB, patch)
2011-06-14 02:47 UTC, Thiago Sousa Santos
needs-work Details | Review

Description Olivier Crête 2011-03-08 19:45:58 UTC
Created attachment 182856 [details] [review]
good: rtph264pay: Implement getcaps

Here is a series of patches to negotiate the H.264 level and profile using the caps.
Comment 1 Olivier Crête 2011-03-08 19:46:38 UTC
Created attachment 182857 [details] [review]
base: codec-utils: Add method to convert H.264 text level in a level_idc

Required by all the other patches
Comment 2 Olivier Crête 2011-03-08 19:47:14 UTC
Created attachment 182858 [details] [review]
ugly: x264: Use profile and level from caps
Comment 3 Olivier Crête 2011-03-09 21:31:49 UTC
Created attachment 183025 [details] [review]
ugly: x264: Use profile and level from caps

Updated patch puts high10, high before main in the static caps, so if the downstream element doesnt have a default, it doesn't override the property..
Comment 4 Edward Hervey 2011-03-10 09:48:06 UTC
I'm totally up for having this.

A couple of questions:
* Is profile taken into account ? It would be nice so one doesn't have to touch any encoder setting but only specify profile/level in caps (Thinking about encoding profiles).
* will x264enc properly limit the accepted width/height/framerate/? according to the available downstream caps' level and profile ?
Comment 5 Olivier Crête 2011-03-10 17:18:53 UTC
(In reply to comment #4)
> * Is profile taken into account ? It would be nice so one doesn't have to touch
> any encoder setting but only specify profile/level in caps (Thinking about
> encoding profiles).

Right now it does the "minimum" of the profile in the property and the caps. The property defaults to main. Maybe it should default to High or even None. I didn't change that as it would be an API change..

> * will x264enc properly limit the accepted width/height/framerate/? according
> to the available downstream caps' level and profile ?

It limits the size according to the level in setcaps and reject any incoming stream that does not meet these limits. BUT, I haven't found a good way to express limits in macroblocks/frame and macroblocks/second in video/x-raw-yuv caps, so right now if you try to send something above the level, it will just error out with not-negotiated.
Comment 6 Marco Ballesio 2011-03-15 06:42:05 UTC
Naive comment, I know, but.. shouldn't the h264 parser be modified to set level and profile in the caps as well?
Comment 7 Edward Hervey 2011-03-15 11:42:18 UTC
(In reply to comment #6)
> Naive comment, I know, but.. shouldn't the h264 parser be modified to set level
> and profile in the caps as well?

It could indeed, and that would be a nice addition, but it's orthogonal to the problem this bug covers.
Comment 8 Edward Hervey 2011-03-16 13:34:47 UTC
Before I forget, we also need a "clear" listing of accepted profile/level values for h264 caps. And their type.
Comment 9 Olivier Crête 2011-03-16 13:45:25 UTC
The only "accepted" list I could find is in codec-utils.c in pbutils.. They're all strings.
Comment 10 Olivier Crête 2011-05-28 18:39:07 UTC
*** Bug 651318 has been marked as a duplicate of this bug. ***
Comment 11 Sebastian Dröge (slomo) 2011-05-30 06:06:15 UTC
What's missing now to get this committed? IMHO you should mark the property in x264enc as deprecated and only take the property value if the downstream caps don't specify a profile or level.
Comment 12 Olivier Crête 2011-05-30 06:26:55 UTC
Downstream will always have something since I added it to the template caps. That's why I use the property as a ceiling.
Comment 13 Olivier Crête 2011-06-01 11:35:28 UTC
Created attachment 188986 [details] [review]
x264: Use profile and level from caps

Updated the patch to only set the profile from the caps if it wsa in the peer
caps and ignore the property in thatr case
Comment 14 Olivier Crête 2011-06-01 11:48:35 UTC
Created attachment 188990 [details] [review]
x264: Use profile and level from caps

Arg, had forgotten the high profile from the if/elseif/elseif for some reason
Comment 15 Tim-Philipp Müller 2011-06-01 11:53:50 UTC
Could we please add some minimal unit tests for this?

a) that it does the right thing with profile in downstream caps

b) that it does the right thing with no profile in downstream caps

c) that it still respects the property
Comment 16 David Schleef 2011-06-01 19:10:20 UTC
I'm not in favor of deprecating the property.  Just use the profile that satisfies both the property and caps constraints.

Also, one of the profiles should be "unconstrained".
Comment 17 Christian Fredrik Kalager Schaller 2011-06-01 19:50:55 UTC
David, why are you against deprecating the property? I mean surely for 0.11 we don't want both a property and caps?
Comment 18 Olivier Crête 2011-06-01 22:59:31 UTC
The is already profile=0 which is no profile.. but it's not the default, and we can't change the default in 0.10, hence the ugly kludge.
Comment 19 Olivier Crête 2011-06-10 00:22:02 UTC
Created attachment 189593 [details] [review]
x264: Use profile and level from caps

Enforces the profile and level from the downstream caps, also
sets them on the fixated caps

Actually, x264 doesn't do baseline, it only does constrained-baseline.
So make that explicit in the caps
Comment 20 Olivier Crête 2011-06-10 00:22:14 UTC
Created attachment 189594 [details] [review]
tests: Test x264enc profiles from the caps

Just for you Christian
Comment 21 Thiago Sousa Santos 2011-06-14 02:28:37 UTC
Review of attachment 189593 [details] [review]:

::: ext/x264/gstx264enc.c
@@ +1556,3 @@
+
+    gst_caps_unref (peer_caps);
+  }

shouldn't we have:

else {
  allowed_caps = peer_caps;
}

also, a few more comments on why the above is necessary would be good.
Comment 22 Thiago Sousa Santos 2011-06-14 02:28:41 UTC
Review of attachment 189593 [details] [review]:

::: ext/x264/gstx264enc.c
@@ +1556,3 @@
+
+    gst_caps_unref (peer_caps);
+  }

shouldn't we have:

else {
  allowed_caps = peer_caps;
}

also, a few more comments on why the above is necessary would be good.
Comment 23 Thiago Sousa Santos 2011-06-14 02:47:57 UTC
Created attachment 189865 [details] [review]
x264enc: Select stream-format based on caps

Makes x264 select its stream-format based on what's available
on caps, the user selected option will be chosen as a fallback
when both options are available.
Comment 24 Christian Fredrik Kalager Schaller 2011-06-27 13:23:48 UTC
Olivier any chance you could look at this sometime soon?
Comment 25 Olivier Crête 2011-06-27 15:33:52 UTC
@Thiago: Allowed-caps is NULL if peer-caps is NULL I think. And we never fetch peer_caps directly. Comments on why what is necessary ?

What does _USER mean? To use the property ? If so, wouldn't it been clearer to have it _FROM_PROPERTY
Comment 26 Sebastian Dröge (slomo) 2011-07-13 08:55:01 UTC
Review of attachment 189865 [details] [review]:

Can we get this committed now? I think Thiagos' patch is the correct thing to do but the _USER should really be renamed to _FROM_PROPERTY (it uses the property values if the caps would allow both stream formats). And there's a small bug in his patch

::: ext/x264/gstx264enc.c
@@ +1928,3 @@
     nal_size =
         x264_nal_encode (encoder->buffer + i_size + 4, &i_data, 0, &nal[i]);
+    if (encoder->current_byte_stream)

This is not what you meant, it will be true for _AVC and _BYTESTREAM and not for _USER. Better add a real comparison with _BYTESTREAM here for correctness and clarity and also add an assertion that the value is never _USER at this point.
Comment 27 Olivier Crête 2011-07-13 18:17:08 UTC
Fixed Thiago's patch and committed the whole thing:

BASE:

commit 5f1bfc7e13bbf3329429853fffd90b3b7c96cc1e
Author: Olivier Crête <olivier.crete@collabora.co.uk>
Date:   Mon Mar 7 17:55:48 2011 -0500

    codec-utils: Add method to convert H.264 text level in a level_idc

GOOD:

commit 57a832cbb15cb6bdcd7b90949045ac3b2fcf6c0f
Author: Olivier Crête <olivier.crete@collabora.co.uk>
Date:   Fri Mar 4 15:41:22 2011 -0500

    rtph264pay: Implement getcaps
    
    Convert profile-level-id from RTP caps into video/x-h264 style caps (with profile and level)

UGLY:

commit 48f899257db49b5289f754cbd92fce246854dd0f
Author: Brian Gitonga Marete <marete@toshnix.com>
Date:   Sat Jun 25 06:29:50 2011 +0300

    x264enc: fix subme property annotation - subme maximum is 10, not 6.
    
    Although the element accepts subme values > 6, the annotation which is
    visible through gst-inspect (for example) erroneously indicates 6 as the
    maximum. Fix this by indicating 10 (which is the x264 max) as the maximum.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653473

commit e27dda7c62574d130a2e02edf3825062f3033fcd
Author: Olivier Crête <olivier.crete@collabora.co.uk>
Date:   Mon Mar 7 17:58:34 2011 -0500

    x264: Use profile and level from caps
    
    Enforces the profile and level from the downstream caps, also
    sets them on the fixated caps
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644233

commit e595cdc3112680b3b66c6676f12ee7bc60bd11c7
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Thu Jun 9 20:20:27 2011 -0400

    tests: Test x264enc profiles from the caps
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644233

commit ac47d20faeba32339e8c7b7d45facb287f54abd2
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Mon Jul 4 18:03:49 2011 -0400

    x264: Allow renegotiation but prefer current caps

commit 7aafba6f825d7704dddfb58db180dd02e5bea479
Author: Thiago Santos <thiago.sousa.santos@collabora.co.uk>
Date:   Mon Jun 13 23:24:27 2011 -0300

    x264enc: Select stream-format based on caps
    
    Makes x264 select its stream-format based on what's available
    on caps, the user selected option will be chosen as a fallback
    when both options are available.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644233