[x264-devel] [PATCH] take interlaced into account for level checks

Loïc Le Loarer lll+vlc at m4x.org
Fri Jul 25 12:27:55 CEST 2008


Le vendredi 25 juillet 2008 à 03:18:18 -0600, Loren Merritt a écrit:
> On Thu, 24 Jul 2008, Loic wrote:
> 
> > The b_interlaced parameter isn't taken into account in
> > x264_validate_levels, this results in 4.2 or greater streams being
> > encoded in interlaced mode while not allowed.
> 
> I don't object to your patch (anything that discourages interlacing is 
> fine with me), but your description of its effect is misleading.
> Do you mean people put "--level 4.2 --interlaced" on the commandline 
> without knowing it's forbidden? Then you're correct, and the warning may 
> help. Otoh, if you mean that x264 may select L4.2 for interlaced content 
> with unspecified level, then your patch changes the selection to L5.1 
> (since it finds no valid level and just has to pick one).

Yes, I have seen this, I even have "fixed" it, but finally decided to
drop this fix.

If one for example encode a 1080i30 stream with --interlaced, it gets
level 4.1, if he also set "--ref 5" for example without my patch, he
gets level 5.0 and no warning, with my patch he gets level 5.1 and the
warning "x264 [warning]: interlaced (1) > level limit (0)". So he can
fix the problem by removing --interlaced. So this is better than
nothing.

My fix was to enforce the level range in interlaced case, so that the
auto detect level will never be outside 2.1:4.1 range if --interlaced is
selected. With this fix and the upper example, the user will get the
warning: "x264 [warning]: DPB size (5 frames, 15667200 bytes) > level
limit (4 frames, 12582912 bytes)".

I don't know what's the best solution beetwin those 2. The best would be
to propose multiple solutions to the user, saying "you can remove
--interlaced or reduce reference frames number", but this more difficult
to do.

Best regards

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 5b737db..20283b0 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -502,8 +502,12 @@ static int x264_validate_parameters( x264_t *h )
                 h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate * 2;
             h->sps = h->sps_array;
             x264_sps_init( h->sps, h->param.i_sps_id, &h->param );
+            /* If interlaced, start at first level having frame_only = 0 */
+            while (h->param.b_interlaced && l->frame_only) l++;
             do h->param.i_level_idc = l->level_idc;
-                while( l[1].level_idc && x264_validate_levels( h, 0 ) && l++ );
+                while( l[1].level_idc && x264_validate_levels( h, 0 ) && l++
+                    /* If interlaced, give up at first level having frame_only = 1 *
+                    && (!h->param.b_interlaced || !l->frame_only) );
             if( h->param.rc.i_vbv_buffer_size <= 0 )
                 h->param.rc.i_vbv_max_bitrate = 0;
             x264_log( h, X264_LOG_DEBUG, "level_idc: %d\n", h->param.i_level_idc );


-- 
Loïc

"heaven is not a place, it's a feeling"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.videolan.org/pipermail/x264-devel/attachments/20080725/b05b5dd1/attachment.pgp 


More information about the x264-devel mailing list