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 7th April 2021, 15:22   #1  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11
Is it possible to change pattern of I,P,B frames?

Hello all,

I have a file with this frames pattern :
stream order:
0 1 2 3 4 5 6 ....
I B B P B B P ....

display order:
1 2 0 4 5 3 7 ....
B B I B B P B ....





Can we force encoder to have a pattern like above frame pattern?

Last edited by Mitra; Yesterday at 13:49.
Mitra is online now   Reply With Quote
Old 7th April 2021, 17:10   #2  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,551
One way is with a qp file when using x264 - you can force frame types for any/all frames
poisondeathray is offline   Reply With Quote
Old 7th April 2021, 17:36   #3  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11
I tried qp file before , it cannot do it. cannot change display order , also cannot change the first P-frame to B-frame ,but I .

Also I changed Libx264 (FFmpeg source code) , and can change all frames except the first 3 frames and display/stream order.
Mitra is online now   Reply With Quote
Old 7th April 2021, 18:26   #4  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,596
Can you share what your goal is here?

In encode/decode order, the first non-IDR frame generally has to be a P-frame if you're using B-frames.
The exception would be if you were using an encoder that uses "generalized B-frames" where reference Bs are used instead of P frames. This generally goes with a multi-layer B-frame reference hierarchy, which I've seen in some commercial broadcast encoders. x264 doesn't support those, unless it was a recent addition.

QPfiles can get confusing, because they (IIRC) are in display order, not encode order. Not a problem if using them to set IDR frames, but it's easy to get a few frames off if going off encode order. It's quite possible that x264 may simply not allow this configuration due how it handles reference hierarchy.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 7th April 2021, 18:44   #5  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11
benwaggoner , Thanks for your explanation.

Last edited by Mitra; Yesterday at 16:01.
Mitra is online now   Reply With Quote
Old 7th April 2021, 18:58   #6  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11

Last edited by Mitra; Today at 08:43.
Mitra is online now   Reply With Quote
Old 7th April 2021, 20:28   #7  |  Link
MasterNobody
Registered User
 
Join Date: Jul 2007
Posts: 537
It looks like open-gop pattern in the middle of stream (not the start, may be start was cut out) where I-frame is not IDR. In such stream if you start decoding from this I-frame than 2 first B-frames will not be decoded and should be discarded by decoder (there probaby should be recovery-point SEI at this I-frame).

Last edited by MasterNobody; 7th April 2021 at 20:36.
MasterNobody is offline   Reply With Quote
Old 7th April 2021, 21:26   #8  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,596
Quote:
Originally Posted by MasterNobody View Post
It looks like open-gop pattern in the middle of stream (not the start, may be start was cut out) where I-frame is not IDR. In such stream if you start decoding from this I-frame than 2 first B-frames will not be decoded and should be discarded by decoder (there probaby should be recovery-point SEI at this I-frame).
And if that's the issue --no-open-gop would be your friend.

Are you having a decoder issue or something with the x264 output?
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 8th April 2021, 09:20   #9  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11
Yes it is open-gop pattern.

Please forget display order and rest of stream for now ,only tell me how can force the first p-frame to be B.

Please look at this image :


Last edited by Mitra; Yesterday at 13:55.
Mitra is online now   Reply With Quote
Old 8th April 2021, 20:21   #10  |  Link
MasterNobody
Registered User
 
Join Date: Jul 2007
Posts: 537
Quote:
Originally Posted by Mitra View Post
Yes it is open-gop pattern.

Please forget display order and rest of stream for now ,only tell me how can force the first p-frame to be B.

Please look at this image :

  1. Optional. Add 24 frames at the start of your video (copy of the first frame)
  2. Encode your video with x264 options:
    Code:
    --open-gop --no-scenecut --b-adapt 0 --bframes 2 --keyint 24
    Example: foreman_extened.h264
  3. Remove first GOP from encoded video (first 22 frames)
    Example: foreman_cut.h264
MasterNobody is offline   Reply With Quote
Old 8th April 2021, 21:40   #11  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11
@MasterNobody , Thanks a lot ,It's a good idea. I tried it with FFmpeg before, but didn't work for me because after cutting encoder puts a P-frame again, Can you please share your x264 command to cut those first 22 frames?
Mitra is online now   Reply With Quote
Old 8th April 2021, 22:06   #12  |  Link
MasterNobody
Registered User
 
Join Date: Jul 2007
Posts: 537
I simply found next SPS in raw Annex B stream (00 00 00 01 67) and removed all before (17249 bytes) in HEX editor.

P.S. I still don't understand why you need such pattern. I doubt this AVC-Long-GOP format mandates to have this redundant 2 B-frames at start of stream.
MasterNobody is offline   Reply With Quote
Old 8th April 2021, 22:49   #13  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,596
Quote:
Originally Posted by MasterNobody View Post
I simply found next SPS in raw Annex B stream (00 00 00 01 67) and removed all before (17249 bytes) in HEX editor.

P.S. I still don't understand why you need such pattern. I doubt this AVC-Long-GOP format mandates to have this redundant 2 B-frames at start of stream.
I'm somewhat surprised it would support Open GOP at all, as it makes lossless editing a lot more challenging. I concur it is very unlikely to be mandated.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 9th April 2021, 08:18   #14  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11
Quote:
Originally Posted by MasterNobody View Post
I simply found next SPS in raw Annex B stream (00 00 00 01 67) and removed all before (17249 bytes) in HEX editor.

P.S. I still don't understand why you need such pattern. I doubt this AVC-Long-GOP format mandates to have this redundant 2 B-frames at start of stream.
your foreman_cut.h264 file can decode/play with all players/decoders , but it's weird to me because it means we can edit bitstream directly without any problem /error occur?!

Last edited by Mitra; Yesterday at 13:56.
Mitra is online now   Reply With Quote
Old 9th April 2021, 08:29   #15  |  Link
Mitra
Registered User
 
Join Date: Mar 2021
Posts: 11
Quote:
Originally Posted by benwaggoner View Post
I'm somewhat surprised it would support Open GOP at all, as it makes lossless editing a lot more challenging. I concur it is very unlikely to be mandated.
Edited:

I tested MasterNobody's file , it can decode/play with all players/decoders.

Do you think is it safe if I remove bytes of stream directly ? (like he did but programmatically)

Last edited by Mitra; 9th April 2021 at 09:24.
Mitra is online now   Reply With Quote
Old Yesterday, 19:36   #16  |  Link
Serestio
Registered User
 
Join Date: Apr 2021
Posts: 3
I thought about that
Serestio is offline   Reply With Quote
Reply

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 09:11.


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