How to calculate H264 GOP file size

I have a h264 file that is extracted from YUV format using SVC software. Now I want to request the size of each GOP in the h264 file. We know that the size of the GOP is the distance between the two closest frames I. here . Could you suggest me how to hide the GOP size for this h264 file. This is better when we implement it using C / C ++. thank

+4
source share
3 answers

Well, just parsing the bitstream to find each I-frame is a bit complicated; among other things, the encoding order may differ (or not) from the display order. One solution is to use http://www.ffmpeg.org/ffprobe.html from the ffmpeg package.

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
...

the output you can easily calculate the length of the gop

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

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

+4
source

I personally prefer pict_type filtering:

ffprobe -show_frames input.h264 | grep pict_type

This will show you the frame structure:

pict_type=I
pict_type=P
pict_type=P
pict_type=P
pict_type=P
pict_type=P
...
+5
source
#!/bin/sh

ffprobe -show_frames $1 > output.txt

GOP=0;

while read p; do
  if [ "$p" = "key_frame=0" ]
  then
    GOP=$((GOP+1))
  fi

if [ "$p" = "key_frame=1" ]
then
  echo $GOP
  GOP=0;
fi

done < output.txt
+2

Source: https://habr.com/ru/post/1543033/


All Articles