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)
+ Reply to Thread
Results 1 to 15 of 15
Are you trying to write your own video trimmer tool ?
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 ?
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.
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 ?
Last edited by andiandi; 30th Aug 2020 at 12:02.
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.
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...
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.
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).
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 16:58. Reason: added previous thread link
ffprobe. Put this in a batch file and you can drag/drop an A/V file onto it.
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"
[Attachment 54704 - Click to enlarge]
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
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 :
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 10:46.