PDA

View Full Version : An mpeg-related question


jeanl
29th March 2007, 01:12
Hi guys,
I have a question:
Suppose a B-frame in GOP 1 references the last P-frame in GOP 0. Does the B frame reference the decoded P-frame, or does it somehow reference the encoded P-frame.
In other words: If I re-encode the P frame, same image, but possibly a different encoder, so perhaps encoded slightly differently, will the B-frame be decoded accurately, or does the fact that the P-frame no longer is encoded in the same way change / invalidate the decoding of the B-frame?

Jeanl

mpucoder
29th March 2007, 02:10
Either way (encoded or decoded) the result is the same. If the encoding has different errors the B picture will decode differently as it is based on the two reference pictures. Change the basis and the result changes.

But to answer the question, the last 2 decoded reference pictures are kept in memory for decoding the B pictures. During encoding encoded and then decoded reference pictures are suppossed to be used to reduce the errors in B pictures.

So the decoding of B pictures depends on the decoded content and is not dependant on any binary arrangement of bits, which may have been what you were asking.

jeanl
29th March 2007, 02:15
Yes, that's what I was asking... Thanks for your answer mpucoder!!!
Jeanl

jsoto
29th March 2007, 22:45
The question comes because I'm trying to replace an open GOP by a re-encoded version of the same GOP, but closed, in order to do some VOB editing afterwards
Say
IBBPBBPBBPBB---> Original (open) GOP
Is going to be changed by
IPBPBBPBBPBB---> Re-encoded (closed) GOP

The problem could appear if the next GOP if it is also open so it needs the last "P" reference of the replaced one.

BTW, Seems I've done the replacement correctly in terms of MPEG, but I have some problems with PTS/DTSs... Need to work more on it.

jsoto

mpucoder
30th March 2007, 04:18
In the case where the first 2 encoded pictures are reference pictures (I and P) the closed GOP flag is irrelevant.

However an open GOP can be converted to closed without changing the picture types, all that is needed is to encode the first B pictures so that they reference only the I picture, but are still temporally the first two. This is the true meaning of closed GOP, that the B pictures that temporally preceed the first I picture reference only the I picture (despite the fact that the "B" means bidirectional)

The problem you are probably having is with the temporal order. Your first sequence IBBPBB displays in the order 2 0 1 5 3 4, your re-encoded sequence IPBPBB displays in the order 0 2 1 5 3 4. So two things happen, first if the P picture you made is from the first B the order of the first two pictures gets swapped. The second is the pts value of a GOP is for the first encoded picture, which originally was displayed as picture 2, but is now picture 0. Assuming no pulldown this means the new pts value should be 2 frames earlier than before, or (regardless of pulldown) 1 frame later than dts.

You can avoid that mess by leaving the picture types as is and encoding the B pictures to reference only the I picture.

jeanl
30th March 2007, 05:56
mpucoder, I didn't know that the GOP pts value is for the first encoded frame, not the first frame displayed!!!! That's amazing! Why that choice?
jeanl

bigotti5
30th March 2007, 11:19
@jeanl
You must not mix up GOP time stamp and PTS.
Only the first encoded frame has a PTS value (always I frame).
But GOP time stamp in GOP header refers to the picture that has a temporal_reference of zero (=the first frame displayed).

mpucoder
30th March 2007, 15:30
Why that choice?
jeanl

Don't know, but it is one of the better "gotcha's" of mpeg

Also, the field "temporal_sequence_number" is for information only, it does not control the order of presentation. The order of presentation is determined by the picture types. If the picture type following a reference picture (I or P) is another reference picture the first reference picture is displayed (ie I followed by P displays the I picture). If a reference picture is followed by a B picture the B picture is displayed, and this continues for all B pictures in the stream until a reference picture is encountered (I followed by B displays B).

If jsoto is re-encoding a B picture as a P the order of presentation will change, regardless of "temporal_sequence_number"

jeanl
30th March 2007, 17:51
@bigotti5, yes, that's my mistake. I confused GOP PTS and VOBU PTS!
@mpucoder, thanks for clarifying this once more!
Jeanl

jsoto
30th March 2007, 23:50
In the case where the first 2 encoded pictures are reference pictures (I and P) the closed GOP flag is irrelevant.

However an open GOP can be converted to closed without changing the picture types, all that is needed is to encode the first B pictures so that they reference only the I picture, but are still temporally the first two. This is the true meaning of closed GOP, that the B pictures that temporally preceed the first I picture reference only the I picture (despite the fact that the "B" means bidirectional).You're right (of course) . My mistake, I meant a "self-contained" GOP. In fact my replacing GOP is not flagged as "closed"...


The problem you are probably having is with the temporal order. Your first sequence IBBPBB displays in the order 2 0 1 5 3 4, your re-encoded sequence IPBPBB displays in the order 0 2 1 5 3 4. So two things happen, first if the P picture you made is from the first B the order of the first two pictures gets swapped. The second is the pts value of a GOP is for the first encoded picture, which originally was displayed as picture 2, but is now picture 0. Assuming no pulldown this means the new pts value should be 2 frames earlier than before, or (regardless of pulldown) 1 frame later than dts.
You're right again.
This is may case

Replacing GOP
I P B P B B P B B P B B
0 2 1 5 3 4 8 6 7 11 9 10

Replaced GOP
I B B P B B P B B P B B
2 0 1 5 3 4 8 6 7 11 9 10

During the replacing process, I'm changing the GOP PTS substracting two frames, (DTS remains unchanged), but I was keeping the GOP timestamp as it was originally. Also, The VOBU PTS remains unchanged.

So, although seems I'm doing everything OK, I'm having some problems in the PTS/DTSs (I have a warning in my SW player) in the transition between the replaced GOP and the next one, which I didn't touch. The transition between the replaced and the previous one is fully OK. I do not have any warning in my SW player and it plays smoothly.


You can avoid that mess by leaving the picture types as is and encoding the B pictures to reference only the I picture.
I'll try that too...

jsoto

bigotti5
30th March 2007, 23:58
I'm changing the GOP PTS and DTS substracting two frames

Imho DTS should be the same, only PTS changes

jsoto
31st March 2007, 00:04
Imho DTS should be the same, only PTS changes
You're right, I've edited my post, because I'm keeping the DTS as it was...
It makes sense, the difference between PTS and DTS is 3 frames in the open GOP and only one in the replacing (self-contained) one, so substracting 2 frames to the original PTS, the difference of one frame is achieved.


jsoto

bigotti5
31st March 2007, 00:15
Can you make available a small piece of such an mpeg (with replaced GOP)?

jsoto
31st March 2007, 00:34
Here it is (8 Mbytes)
http://download.videohelp.com/jsoto/temp/sample_repGOP.zip

The reencoded GOP has been created with CCE and muxed with an ac3 track using MuxMan, just to have the VOB format.

EDIT: The replaced GOP is the one starting in the NAV LBA=915

jsoto

bigotti5
31st March 2007, 01:20
There is a sequence end code (00 00 01 B7) in your replaced GOP

jeanl
31st March 2007, 01:21
That's not good! :)
Jeanl

jsoto
31st March 2007, 09:33
There is a sequence end code (00 00 01 B7) in your replaced GOP
You got it!!!. I forgot to delete it.

I was focused in PTS/DTSs due the warning I was having in my SW player....
It now plays perfectly!

Many thanks.

jeanl
31st March 2007, 20:26
Awesome!
Jeanl