如何计算文件H264的GOP大小

时间:2014-06-03 08:51:39

标签: video media h.264 multimedia svc

我有一个使用SVC软件从YUV格式中提取的h264文件。现在,我想计算h264文件中每个GOP的大小。我们知道GOP的大小是两个最接近的I帧之间的距离。 here。你能告诉我如何解决给定h264文件的GOP大小。我们用C / C ++实现它会更好。谢谢

4 个答案:

答案 0 :(得分:9)

我个人更喜欢用pict_type过滤:

ffprobe -show_frames input.h264 | grep pict_type

这将显示帧结构:

pict_type=I
pict_type=P
pict_type=P
pict_type=P
pict_type=P
pict_type=P
...

答案 1 :(得分:6)

好吧,只是解析比特流以找到每个I帧有点棘手;除其他外,编码顺序可能(或不)与显示顺序不同。一种解决方案是使用ffmpeg-suite中的http://www.ffmpeg.org/ffprobe.html

示例:

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

从输出中可以轻松计算GOP长度

另一种解决方案是修补http://iphome.hhi.de/suehring/tml/

处的参考实现

如果您需要有关此部分的帮助,请告诉我们:-)

答案 2 :(得分:3)

#!/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

答案 3 :(得分:0)

使用类似命令:

ffprobe -show_entries frame=pict_type  mp4_sample.mp4  -of flat | grep I

,您将看到如下结果:

frames.frame.0.pict_type="I"
frames.frame.384.pict_type="I"
frames.frame.764.pict_type="I"
frames.frame.1027.pict_type="I"
frames.frame.1164.pict_type="I"
frames.frame.1544.pict_type="I"
frames.frame.1944.pict_type="I"
frames.frame.2183.pict_type="I"
frames.frame.2324.pict_type="I"