2

As you know ref parameter can set the number of previous frames each P-frame can use as references.

I need the same thing for B-Frames, but ref=1 does not work for B-Frames.

I mean an I/P frame to be used as reference for B-frames only.

is it possible with a command line? , or by change the following function in the source code ?

static inline int reference_update( x264_t *h )
{
if( !h->fdec->b_kept_as_ref )
{
    if( h->i_thread_frames > 1 )
    {
        x264_frame_push_unused( h, h->fdec );
        h->fdec = x264_frame_pop_unused( h, 1 );
        if( !h->fdec )
            return -1;
    }
    return 0;
}

/* apply mmco from previous frame. */
for( int i = 0; i < h->sh.i_mmco_command_count; i++ )
    for( int j = 0; h->frames.reference[j]; j++ )
        if( h->frames.reference[j]->i_poc == h->sh.mmco[i].i_poc )
            x264_frame_push_unused( h, x264_frame_shift( &h->frames.reference[j] ) );

/* move frame in the buffer */
x264_frame_push( h->frames.reference, h->fdec );
if( h->frames.reference[h->sps->i_num_ref_frames] )
    x264_frame_push_unused( h, x264_frame_shift( h->frames.reference ) );
h->fdec = x264_frame_pop_unused( h, 1 );
if( !h->fdec )
    return -1;
return 0;
}
Maria
  • 344
  • 8
  • 30

1 Answers1

1

No. B-frame is by definition bidirectional i.e. it must have at least 2 reference frames (one before and one after in presentation order), otherwise it does not make sense at all and it will not differ from the P-frame.

nobody555
  • 2,239
  • 18
  • 18
  • In open-GOP stream after cut at I-frame (not IDR) you can get IBBPBB in decoder order and BBIBBP in presentation order but in such case if decoding starts from it first 2 B-frames should be discarded. – nobody555 May 29 '21 at 10:23
  • One more time such stream can be after cut but this B-frames are not decodable (without artifacts and error concealing). x264 can also encode open-GOP with `--open-gop` option. Show me any commercial encoder that can encode it other way and stream sample where this B-frames would be correctly decodable. – nobody555 May 29 '21 at 11:45
  • They can't, it was you who said that it is possible. At most they can do is like I said encode open-gop and cut first GOP i.e. like this sample encoded with x264: [test.zip](https://wetransfer.com/downloads/369c4d4e2b498cfe8fd4dea1e5b1fc0920210529230715/c7687d) or [mirror](http://www.filedropper.com/test_64) – nobody555 May 29 '21 at 23:19
  • Yes. I looked at it. It really use I(DR)BBPBBP pattern. After that I reread H.264 specs and find out that it says in `8.2.4.2.3 Initialization process for reference picture lists for B slices in frames`: `When this process is invoked, there shall be at least one reference entry that is currently marked as "used for reference" (i.e., as "used for short-term reference" or "used for long-term reference") and is not marked as "non-existing".` So looks like it really possible to use same reference frame for both RefPicList0 and RefPicList1. – nobody555 May 31 '21 at 18:02
  • But I don't understand the point of such B-frames from compression efficiency stand point. Only use for it imho is to keep same non-adaptive open-gop frame pattern in the first GOP as in next GOPs. – nobody555 May 31 '21 at 18:09