I want to find a fast way to determine a video file's GOP structure when no such information is present in MediaInfo.
I managed to find the answer for files opened by VGS (Visual GOP Struct) feature of GSpot:
For example, here is how an open GOP file looks like:
And here is how a closed GOP looks like:
For formats not recognized by GSpot, one can simply inspect the frame structure in AviDemux for example and base conclusions on the following:
But there would still remain cases where this won't be enough and alternative tool of GSpot would be needed. Is there such or some other way to acquire that information?
+ Reply to Thread
Results 1 to 21 of 21
Last edited by Sotee; 22nd Feb 2020 at 08:48.
Elecard software? Any guide on it for what is asked in OP?
Yes, elecard streameye , or codecvisa. But they are commercial ware
Freeware h264_parse (for AVC) or ffprobe
ffprobe -i "input.ext" -select_streams v:0 -show_frames 1>ffprobe.txt
Look for pict_type=I, but key_frame=0 . The presence of this indicates open GOP
An IDR frame will have pict_type=I, but key_frame=1
It's not user friendly method, but use your text editor and search for string " pict_type=I" and check out the key_frame value, you need to check a few at least.
For example, this frame indicates open GOP
Mediainfo is unreliable. It just tells you the encoding settings used. The metadata. Not what the actual stream is
If you enable Open gop for an encoder, it does not necessarily mean you have open gops. They are only placed when the encoder thinks it's beneficial to do so and you have not surpassed the max keyframe interval setting . You would need to verify with a stream analyzer
But ffprobe used to be unreliable for AVC too ; but I'll check it with h265
For HEVC , it seems to detect some, but it is classifying in them only under I,P,B. Technically not entirely correct
One problem is there are several additional frame types of frames in HEVC, not just "I" vs "i" and P, B for AVC
The equivalent for an AVC IDR frame is an "IRAP" in HEVC . But there are several other subtypes of "I" frames for HEVC.
ffprobe is classifying in them only under I,P,B, it doesn't exactly distinguish the subtype of "I". But it identified a RADL as an I non key . So it does not label them "all" as key
A free hevc analyzer would be hevcesbrowser , this matches the results of commercial analyzers
[Attachment 52070 - Click to enlarge]
For MPEG-2 files, the left text info panel will state whether the file is open or closed GOP.
[Attachment 52071 - Click to enlarge]
For MPEG-4 files, i don't see any info panel that states this.
Instead, I have to scroll through the IPB frames to verify (notice when I click on a P/B frame, it'll indicate which other frames it refers to).
CloseGOP means the PB frames only refer to the frames between surrounding I frames.
OpenGOP means the PB frames can refer to frames outside the surrounding I frames, AFIK.
I asked in Avidemux forums and the solution turned out to be pretty easy:
You could open the shell in Avidemux ("Tools" --> "Scripting Shell") and run the command:
for frame in range(0,300): Editor().printTiming(frame)
On Windows, the output is directed to the Avidemux log file admlog.txt in %localappdata%\avidemux\ directory.
If you see a line with "B" (like "B-frame") directly following a line with "I" (like "intra" or "IDR", Avidemux doesn't communicate the difference between the both, unfortunately), the stream is encoded in open GOP mode.
A B preceding an I in not specific for open GOP. You can have a B preceding an I with a closed GOP too (in that case for AVC it's actually an IDR)
Did you test it? That avidemux script method is not accurate for AVC. It misidentifies some "i" frames as P and lists some true IDR frames with preceding B's (but that is a valid configuration for a closed GOP) . ie. It does not match stream analyzers
For HEVC, it's more complicated. You can have open GOP's with leading b-frames and still cut before a CRA . That's still a valid bitstream . You don't need an IDR(IRAP) type "I" to cut. What you need to know (in the context of "is it safe to cut here or not") is if there are references and their relationships
Avidemux method - it's universal method using Avidemux to determine the frame types. If you inspect the stream with another program you can still deduce the GOP type following the rule B after I in stream/coded order, which is essentially what I quoted you in the other thread before starting this one:
For each I-frame in the sequence, search packets after it and note AVPacket.pos and AVPacket.pts. If B(pos) > I(pos) but B(pts) < I(pts), you have open GOP, else closed GOP.
Yes, that last quote is correct and is the universal definition. B comes after the I in coded order, but precedes the I in display order
I said "avidemux script method is not accurate". ie. it does not necessarily correctly identify frames .
For AVC, it might not be significant in the context of cutting, unless it misidentifies an "i" frame as an "IDR" frame. So far that method is misidentifying "i" frames as "P" frames, but you wouldn't cut there normally anyways if you were "cutting on keyframes"
I'm looking at some AVC blu-rays, and because avidemux does not correctly identify the "i" frames or positions , you would incorrectly deduce that it was closed GOP . When in fact, there are open GOP's scattered around with closed GOP's, it just doesn't see the open ones because it can't identify the "i" correctly
But in the cutting context, it seems to get the IDR frames correct so far, at least with the most recent beta build . In the past, many softwares would mixup "i" and "IDR", and of course that is a disaster in the cutting context
You can also have sequences like I1_P1_I2_P2 where P2 references P1. Imagine a horror movie that flashes some scary picture for exactly 1 frame only for the horror effect. But AFAIK this is not allowed on Blu-Ray so you should be safe with such sources at least.