Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 3rd June 2021, 12:36   #1  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 6
The first IDR-frame as reference for the first 2 B-frames

H.264 specs says :
Quote:
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"
(thanks to nobody555 from the stackoverflow for find it)

As you can see ,only one I/P frame can be used as reference for B-frames. it means the same reference frame can use for both RefPicList0 and RefPicList1, but the document does not have enough details about it.( or it is difficalt to understand at least to me)


my question:
How to set the first IDR-frame as the only reference for the first B-frames in the open-GOP stream with this pattern:BBIBBPBB...? / How to implement it in the x264/libx264 source code?

Note: I want this to be done for the first two B-frames , not the rest of the stream.

(sorry if my English is bad)

Last edited by Mitra; 6th June 2021 at 18:41.
Mitra is offline   Reply With Quote
Old 3rd June 2021, 20:53   #2  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,923
I'm confused. A B-frame can absolutely have more than one I/P frame it can reference. And a non-reference b-frame can reference more than one I/P/B frame. A B-frame is really defined by referencing both a past and a future frame.

Are you trying to force a single reference for some reason? In a way that --ref 1 wouldn't give you?
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 3rd June 2021, 22:26   #3  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 6
Quote:
Originally Posted by benwaggoner View Post
I'm confused. A B-frame can absolutely have more than one I/P frame it can reference. And a non-reference b-frame can reference more than one I/P/B frame. A B-frame is really defined by referencing both a past and a future frame.

Are you trying to force a single reference for some reason? In a way that --ref 1 wouldn't give you?
Thank you for the reply,

Unfortunately, Common mistakes on the Internet is confusing. . . .

I used to think like you until a while ago, but according to the ITU document, this does not seem to be true.

Also many commercial encoders starts open-GOP stream with this pattern: BBIBBPBB...(stream order) , in this pattern, the first I(DR) is the only reference for both first B-frames.


As you know ref parameter can set the number of previous frames each P-frame can use as references,but ref=1 does not work for B-Frames.

Last edited by Mitra; 28th June 2021 at 08:30.
Mitra is offline   Reply With Quote
Old 4th June 2021, 00:20   #4  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,923
Quote:
Originally Posted by Mitra View Post
TI used to think like you until a while ago, but according to the ITU document, this does not seem to be true.

Also many commercial encoders starts open-GOP stream with this pattern: BBIBBPBB...(stream order) , in this pattern, the first I(DR) is the only reference of both first B-frames.

I implemented it by cutting on the I-frame but due to the loss of a P before 2 first B-frames they are not decodable , So I want to implement it in the standard way for myself.

As you know ref parameter can set the number of previous frames each P-frame can use as references,but ref=1 does not work for B-Frames.
The BBIBB... pattern is either Open GOP (with the leading Bs referencing the prior GOP) or RADL, which references only following frames in playback order, but can reference more than one future frame. Open GOP is generally used with files and on optical disc, while RADL can be used with stream switching.

B-frames have ALWAYS used both forward and backward prediction, and thus at least 2 frames, all the way back to MPEG-1. Older codecs like MPEG-1/2 and VC-1 supported 2 reference frames for B-frames while allowing only 1 reference for P-frames. The resulting improvement in compression efficiency from the bidirectional prediction making B-frames smaller is a key motivation for B-frames in the first place (they also reduced cumulative drift due to different floating point implementations in MPEG-1/2).

The x264/x265 --ref syntax is dumb as it means different things with and without B-frames. It should really follow the bitstream syntax parameter, so the max ref frames is the same with and without B-frames
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 4th June 2021, 06:52   #5  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 6
Quote:
Originally Posted by benwaggoner View Post
The BBIBB... pattern is either Open GOP (with the leading Bs referencing the prior GOP) or RADL, which references only following frames in playback order, but can reference more than one future frame. Open GOP is generally used with files and on optical disc, while RADL can be used with stream switching.

B-frames have ALWAYS used both forward and backward prediction, and thus at least 2 frames, all the way back to MPEG-1. Older codecs like MPEG-1/2 and VC-1 supported 2 reference frames for B-frames while allowing only 1 reference for P-frames. The resulting improvement in compression efficiency from the bidirectional prediction making B-frames smaller is a key motivation for B-frames in the first place (they also reduced cumulative drift due to different floating point implementations in MPEG-1/2).

The x264/x265 --ref syntax is dumb as it means different things with and without B-frames. It should really follow the bitstream syntax parameter, so the max ref frames is the same with and without B-frames

So, please explain the reference of the first two B-frames of this sample and show me how we can do this by x264 , Etc.

StreamEye says the only reference for both is the first IDR.

Note: I'm talking about the first 2 B-frames , not the rest of the stream.

Last edited by Mitra; 4th June 2021 at 07:08.
Mitra is offline   Reply With Quote
Old 4th June 2021, 20:34   #6  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,923
Quote:
Originally Posted by Mitra View Post
So, please explain the reference of the first two B-frames of this sample and show me how we can do this by x264 , Etc.

StreamEye says the only reference for both is the first IDR.

Note: I'm talking about the first 2 B-frames , not the rest of the stream.
OH! Gotcha. Sounds like RADL from x265. In that case, they are B-frames only in the sense that the allow prediction from frames later in temporal order.

I think it is technically possible for one of those to reference a P-frame after the IDR, but for most content the encoder wouldn't find useful references there to use, so they wouldn't be in the list.

x264 doesn't have --radl, of course. You could evaluate this if you used a QPfile to force a "bbIP" start sequence, and make the P a better reference for the bb than the I is.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 4th June 2021, 21:12   #7  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 6
Quote:
Originally Posted by benwaggoner View Post
OH! Gotcha. Sounds like RADL from x265. In that case, they are B-frames only in the sense that the allow prediction from frames later in temporal order.

I think it is technically possible for one of those to reference a P-frame after the IDR, but for most content the encoder wouldn't find useful references there to use, so they wouldn't be in the list.

x264 doesn't have --radl, of course. You could evaluate this if you used a QPfile to force a "bbIP" start sequence, and make the P a better reference for the bb than the I is.

Thanks for your explanation,

but unfortunately not possible with QPfile ,because using QPfile, the first frame in stream order will always be IDR ,not B.

Last edited by Mitra; 4th June 2021 at 22:24.
Mitra is offline   Reply With Quote
Reply

Tags
h.264 encoder, libx264.dll, video codec, x264

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:14.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.