[x264-devel] Re: Change reference frame

Loren Merritt lorenm at u.washington.edu
Sat Mar 24 08:53:32 CET 2007


On Fri, 23 Mar 2007, Jirka Klaue wrote:

>>> - x264 is used for live encoding from a camera and RTP sending
>>> - when the sender needs to drop a frame for some reason, I want
>>> to tell the encoder not to use the dropped frame as a reference
>>> for following frames (encoding an I-frame is not an option due
>>> to bit-rate constraints)
>>> 
>>> Is it possible to tell x264 to use the previous (not dropped) frame
>>> as reference for further frames?
>> 
>> x264 does not currently have such a feature.
>
> Well, could you point me to the right place in the code?

Before starting the encode, set sps->b_gaps_in_frame_num_value_allowed=1. 
This tells the decoder that any dropped frames have been accounted for, 
and the decoder shouldn't interpolate the missing references.

If you drop one reference frame, you must also drop all other frames that 
have already been encoded that depend on it, and (in the multithreaded 
case) also any frames currently being encoded. If the DPB size is 
sufficiently small, there might not be any frames left to predict from, in 
which case forcing an I-frame is the only option. But if there are some 
valid frames left in the DPB, then:

Remove the dropped frames from the DPB.

   x264_frame_t **f = h->frames.reference;
   while(*f)
     if(is_dropped(*f))
       x264_frame_push_unused(h, x264_frame_shift(f));
     else
       f++;

At this point, the output of x264 is an invalid stream, but the output of 
your server after dropping the frames is valid.

Optional, affects quality but not compliance: There's no point in encoding 
B-frames across such a gap, so force the next frame type to P.

   if(h->frames.current[0] && !IS_X264_TYPE_I(h->frames.current[0].i_type))
     h->frames.current[0].i_type = X264_TYPE_P;
   else if(h->frames.next[0])
     h->frames.next[0].i_type = X264_TYPE_P;

Optional, to make both versions of the stream valid: Implement adaptive 
reference marking. It's section 7.4.3.3 in the standard, and the stub in 
x264 is at encoder.c line 302. Since adaptive reference marking only 
takes effect after the current frame, also enable reference list 
reordering for this frame (h->b_ref_reorder[0]=1).

--Loren Merritt

-- 
This is the x264-devel mailing-list
To unsubscribe, go to: http://developers.videolan.org/lists.html



More information about the x264-devel mailing list