VideoHelp Forum

Try DVDFab and copy Ultra HD Blu-rays and DVDs! Or rip iTunes movies and music! Download free trial !
+ Reply to Thread
Results 1 to 15 of 15
Thread
  1. Hi,


    I got some questions related to cutting Open-GOP H264 videos :


    1) For an Open-GOP video without bframes, do I just have to cut an IDR frame at the beginning and end with a p-frame or i-frame (whether it's IDR or not) ?


    2) For an Open-GOP video with bframes, is it possible to end the cut to a p-frame that is preceded by a bframe ? And also to a p-frame followed by an i-frame ? (whether it's IDR or not), or at least to an non-IDR i-frame ?


    3) For a Closed-GOP video, can I always end the cut with a p-frame (it might sound off-topic but I guess that if it's not always possible on Closed-GOP, then it might be the same with Open-GOP)

    Thank you
    Quote Quote  
  2. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Are you trying to write your own video trimmer tool ?
    Quote Quote  
  3. Originally Posted by andiandi View Post
    Hi,


    I got some questions related to cutting Open-GOP H264 videos :


    1) For an Open-GOP video without bframes, do I just have to cut an IDR frame at the beginning and end with a p-frame or i-frame (whether it's IDR or not) ?


    2) For an Open-GOP video with bframes, is it possible to end the cut to a p-frame that is preceded by a bframe ? And also to a p-frame followed by an i-frame ? (whether it's IDR or not), or at least to an non-IDR i-frame ?


    3) For a Closed-GOP video, can I always end the cut with a p-frame (it might sound off-topic but I guess that if it's not always possible on Closed-GOP, then it might be the same with Open-GOP)

    Thank you
    Open-GOP doesn't have IDR frames, it has I-frames with recovery point SEI to use as a random access point. It's not refreshing decoder. Some streams can have IDR's on scene changes but that GOP is closed and decoder refreshed (started from zero) and is safe to cut there.

    So to try to answer your question,

    1. Open-GOP stream without b-frames is unusual, don't know.

    2. Assuming your cut is like this: IbbPbbP-cut-IbbPbbP, it depends from case to case, sometimes it can work without corruption, a lot of times it can't.
    Don't cut like Ibb-cut-IbbP or Ibb-cut-PbbP or Ibb-cut-bbP. For that kind of operation you need commercial editor with smart-render capability like VideReDo or TMPGEnc Smart Renderer.

    3. Closed GOP is way easier, just cut after P frame and continue the stream with future IDR. If for example you can't cut precisely on that future IDR but a few frames after, you need to re-encode the frames of that whole GOP and merge it with next GOP.
    Quote Quote  
  4. Originally Posted by davexnet View Post
    Are you trying to write your own video trimmer tool ?
    No.


    Originally Posted by badyu17 View Post
    Originally Posted by andiandi View Post
    Hi,


    I got some questions related to cutting Open-GOP H264 videos :


    1) For an Open-GOP video without bframes, do I just have to cut an IDR frame at the beginning and end with a p-frame or i-frame (whether it's IDR or not) ?


    2) For an Open-GOP video with bframes, is it possible to end the cut to a p-frame that is preceded by a bframe ? And also to a p-frame followed by an i-frame ? (whether it's IDR or not), or at least to an non-IDR i-frame ?


    3) For a Closed-GOP video, can I always end the cut with a p-frame (it might sound off-topic but I guess that if it's not always possible on Closed-GOP, then it might be the same with Open-GOP)

    Thank you
    Open-GOP doesn't have IDR frames, it has I-frames with recovery point SEI to use as a random access point. It's not refreshing decoder. Some streams can have IDR's on scene changes but that GOP is closed and decoder refreshed (started from zero) and is safe to cut there.

    So to try to answer your question,

    1. Open-GOP stream without b-frames is unusual, don't know.

    2. Assuming your cut is like this: IbbPbbP-cut-IbbPbbP, it depends from case to case, sometimes it can work without corruption, a lot of times it can't.
    Don't cut like Ibb-cut-IbbP or Ibb-cut-PbbP or Ibb-cut-bbP. For that kind of operation you need commercial editor with smart-render capability like VideReDo or TMPGEnc Smart Renderer.

    3. Closed GOP is way easier, just cut after P frame and continue the stream with future IDR. If for example you can't cut precisely on that future IDR but a few frames after, you need to re-encode the frames of that whole GOP and merge it with next GOP.

    Thanks for your answer.

    1. I see. Can we still state something about that ? For instance that we can end the cut on a P-frame or I-frame for sure since it can't refer to any frames afterwards given that there's no bframes.

    2. I think I understood what you meant, and I always wondered something about that : if the cut is wrong, will the stream be corrupted for sure (I mean visually) or no ?

    3. I don't understand quite well when you say "after p-frame" and "future IDR". AFAIK and in my experience, for Closed-GOP we have to start every cut from an IDR frame and end it to a P or an IDR frame, right ?
    Quote Quote  
  5. 1. Probably. Don't know.

    2. The cut is not "wrong", it's just it's not supposed to be cut in the first place. You can have situation where non-IDR I frame is a scenecut and logically there aren't any frames from before that can be used for future reference but it can still visually corrupt that cut. Not in all cases but it can still happen. It depends on both encoder and decoder in use.

    3. Yes that is correct. Maybe it was a poor choice of words. Anyway, Closed-GOP is flexible and cut friendly.
    Quote Quote  
  6. Originally Posted by badyu17 View Post
    1. Probably. Don't know.

    2. The cut is not "wrong", it's just it's not supposed to be cut in the first place. You can have situation where non-IDR I frame is a scenecut and logically there aren't any frames from before that can be used for future reference but it can still visually corrupt that cut. Not in all cases but it can still happen. It depends on both encoder and decoder in use.

    3. Yes that is correct. Maybe it was a poor choice of words. Anyway, Closed-GOP is flexible and cut friendly.
    1. Alright. Then I just got one question about IDR frames : if Open-GOP doesn't have IDR frames (I guess only the first frame of the whole video is an IDR) then it means that if there's multiple IDR frames, it implies that it's Closed-GOP ? (I'm using FrameCounter to look at IDR frames, idk if it's reliable but I hope so).

    2. If I got it right, there's no general rule to cut open-GOP, and it rather requires an accurate analysis to ensure that no frame is referring to another frame before or after the spots we want to cut, or it requires to use smart reencoding ?

    3. OK.
    Last edited by andiandi; 30th Aug 2020 at 11:02.
    Quote Quote  
  7. 1. Yes, if you have IDR frames than that specific GOP is closed. You can have hybrid situation with mainly open-GOP stream that has IDR frames only for scenecuts.

    2. It's not that easy, there's also stuff like frame_num and pic order count and SPS header that smart rendering engine needs to imitate or make it close enough for the whole thing to work without hiccups. In fact, VideoReDo in v5 smart rendering mode uses JM reference software to encode frames and sps header which is then spliced between original parts in a specific way. But you are right, there needs to be analysis of source bitstream.
    Quote Quote  
  8. Originally Posted by badyu17 View Post
    1. Yes, if you have IDR frames than that specific GOP is closed. You can have hybrid situation with mainly open-GOP stream that has IDR frames only for scenecuts.

    2. It's not that easy, there's also stuff like frame_num and pic order count and SPS header that smart rendering engine needs to imitate or make it close enough for the whole thing to work without hiccups. In fact, VideoReDo in v5 smart rendering mode uses JM reference software to encode frames and sps header which is then spliced between original parts in a specific way. But you are right, there needs to be analysis of source bitstream.
    1. I see, I just hope that FrameCounter is reliable to analyse IDR frames. If anybody here could confirm that it'd be great.

    2. Alright, as I thought it's rather complicated. I think that in my case the best thing would be to be able to detect if a video without bframes is open-GOP or not (if you know any way to do that, since for videos with bframes I already read that a reliable way to do it exist). I have plenty of videos that I want to cut and I prefer to focus on the Closed-GOP first...
    Quote Quote  
  9. 1. I'm sorry, what's FrameCounter? I'm unfamiliar with that.

    2. Well, edit your video and see how it plays. If there's no glitches than who cares what gop it uses.
    Quote Quote  
  10. Originally Posted by badyu17 View Post
    1. I'm sorry, what's FrameCounter? I'm unfamiliar with that.

    2. Well, edit your video and see how it plays. If there's no glitches than who cares what gop it uses.
    1. FrameCounter is a tool (by Selur) which analyzes the total number of frames and their types.

    2. If the fact that there's no glitches implies that there's no corruption in any way, and also that there won't be any issue with other softwares, then I'm alright with that (it's crucial that I know for sure, because I plan to delete sources after editing).
    Quote Quote  
  11. How to detect if a video is closed gop ?

    According to: https://streaminglearningcenter.com/articles/open-and-closed-gops-all-you-need-to-know.html
    With x264, Closed Gop is the default unlike x265,
    if Encoding settings are available: open_gop=0 (check with mediainfo)

    More info in: https://forum.videohelp.com/threads/396068-Determining-GOP-structure-open-or-closed
    Last edited by butterw; 30th Aug 2020 at 15:58. Reason: added previous thread link
    Quote Quote  
  12. Originally Posted by butterw View Post
    How to detect if a video is closed gop ?

    According to: https://streaminglearningcenter.com/articles/open-and-closed-gops-all-you-need-to-know.html
    With x264, Closed Gop is the default unlike x265,
    if Encoding settings are available: open_gop=0 (check with mediainfo)
    I know that but on my videos encoding settings are not available.
    Thanks anyway.
    Quote Quote  
  13. Originally Posted by butterw View Post
    How to detect if a video is closed gop ?
    I believe you can use ffprobe. Put this in a batch file and you can drag/drop an A/V file onto it.

    Code:
    echo entry,pkt_pts_time,pict_type,coded_picture_number > "%~n1.csv"
    ffprobe.exe -v 32 -stats -y -hide_banner -i %1 -select_streams v -print_format csv -of csv  -show_entries "frame=pkt_pts_time,pict_type,coded_picture_number" >> "%~n1.csv"
    It will produce a csv file you can import as spreadsheet or view as plain text. It will show the frames in presentation order with the display time, picture type, and the coded picture number.

    Image
    [Attachment 54704 - Click to enlarge]


    Code:
    entry,pkt_pts_time,pict_type,coded_picture_number 
    frame,0.000000,I,0
    frame,0.041667,B,3
    frame,0.083333,B,2
    frame,0.125000,B,4
    frame,0.166667,P,1
    frame,0.208333,B,7
    frame,0.250000,B,6
    frame,0.291667,B,8
    frame,0.333333,P,5
    frame,0.375000,B,11
    frame,0.416667,B,10
    frame,0.458333,B,12
    frame,0.500000,P,9
    frame,0.541667,B,15
    frame,0.583333,B,14
    frame,0.625000,B,16
    frame,0.666667,P,13
    frame,0.708333,B,18
    frame,0.750000,I,17
    frame,0.791667,B,21
    frame,0.833333,B,20
    frame,0.875000,B,22
    frame,0.916667,P,19
    frame,0.958333,B,25
    You can see that the last frame of the first GOP is a B frame -- so that's an open GOP. Also, the coded picture number is higher than that of the I frame after it -- indicating that the I frame had to be decoded before the B frame, another indication of an open GOP.

    ffprobe is pretty slow so it will take a while. But you can always abort it part way through (Ctrl+C or Ctrl+Break) and just use the partial result.
    Quote Quote  
  14. Originally Posted by jagabo View Post
    Originally Posted by butterw View Post
    How to detect if a video is closed gop ?
    I believe you can use ffprobe. Put this in a batch file and you can drag/drop an A/V file onto it.

    Code:
    echo entry,pkt_pts_time,pict_type,coded_picture_number > "%~n1.csv"
    ffprobe.exe -v 32 -stats -y -hide_banner -i %1 -select_streams v -print_format csv -of csv  -show_entries "frame=pkt_pts_time,pict_type,coded_picture_number" >> "%~n1.csv"
    It will produce a csv file you can import as spreadsheet or view as plain text. It will show the frames in presentation order with the display time, picture type, and the coded picture number.

    Image
    [Attachment 54704 - Click to enlarge]


    Code:
    entry,pkt_pts_time,pict_type,coded_picture_number 
    frame,0.000000,I,0
    frame,0.041667,B,3
    frame,0.083333,B,2
    frame,0.125000,B,4
    frame,0.166667,P,1
    frame,0.208333,B,7
    frame,0.250000,B,6
    frame,0.291667,B,8
    frame,0.333333,P,5
    frame,0.375000,B,11
    frame,0.416667,B,10
    frame,0.458333,B,12
    frame,0.500000,P,9
    frame,0.541667,B,15
    frame,0.583333,B,14
    frame,0.625000,B,16
    frame,0.666667,P,13
    frame,0.708333,B,18
    frame,0.750000,I,17
    frame,0.791667,B,21
    frame,0.833333,B,20
    frame,0.875000,B,22
    frame,0.916667,P,19
    frame,0.958333,B,25
    You can see that the last frame of the first GOP is a B frame -- so that's an open GOP. Also, the coded picture number is higher than that of the I frame after it -- indicating that the I frame had to be decoded before the B frame, another indication of an open GOP.

    ffprobe is pretty slow so it will take a while. But you can always abort it part way through (Ctrl+C or Ctrl+Break) and just use the partial result.

    Thanks for that.

    I used your command line, and edited it to change the output to txt instead of csv. Then, I created a regex line (That I use in notepad++) to search for bframes which are located just before i-frames to determine if it's Open-GOP (and I make sure that coded picture number of the bframe is just after that of the i-frame).

    Here is the regex line :

    B,[0-9]+\r\nframe,[0-9]+.[0-9]+,I


    If that method is flawless, then the only remaining thing are videos without bframes (if there's any way to know if they are actually Open-GOP).
    Last edited by andiandi; 7th Sep 2020 at 09:46.
    Quote Quote  



Similar Threads