Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate GOP size of a file H264

I have a h264 file that extract from YUV format using SVC software. Now, I want to caculate size of each GOP in the h264 file. We know that size of GOP is the distance between two nearest I frame. here. Could you suggest to me how to cacluate the GOP size of a given h264 file. It is better when we implement it by C/C++.Thank you

like image 503
user3677103 Avatar asked Jun 03 '14 08:06

user3677103


People also ask

How is GOP size calculated?

Simply put, a GOP is the distance between two keyframes, measured in the number of frames, or the amount of time between keyframes. For example, if a keyframe is inserted every 1 second into a video at 30 frames per second, the GOP length is 30 frames, or 1 second.

How many GOP frames should I use?

Recommendation: When using MPEG-2, the recommended GOP size is up to 30. A size of 15 is also common. For H. 264, the recommendation is to make the GOP size as large as possible while still meeting other encoding requirements.

What is GOP for video?

In video coding, a group of pictures, or GOP structure, specifies the order in which intra- and inter-frames are arranged. The GOP is a collection of successive pictures within a coded video stream. Each coded video stream consists of successive GOPs, from which the visible frames are generated.

What is GOP compression?

(long Group Of Pictures compression) The interframe coding of digital video in which a full video frame (the "keyframe") is followed by a number of delta frames ("difference frames") until the next keyframe is reached. See interframe coding.


1 Answers

Well, just parsing the bitstream to find the each I-frame is a bit tricky; among other things the encode order might be (or not) different from the display-order. One solution is to use http://www.ffmpeg.org/ffprobe.html from the ffmpeg-suite.

Example:

ffprobe -show_frames input.bin | grep key_frame
key_frame=1
key_frame=0
key_frame=0
key_frame=0
key_frame=0
key_frame=0
...

from the output you can easily calculate the GOP-length

Another solution is to patch the reference implementation found at http://iphome.hhi.de/suehring/tml/

Let me know if you need help with this part :-)

like image 173
Fredrik Pihl Avatar answered Sep 23 '22 23:09

Fredrik Pihl