[英]How to calculate GOP size of a file H264
我有一个使用 SVC 软件从 YUV 格式中提取的 h264 文件。 现在,我想计算 h264 文件中每个 GOP 的大小。 我们知道 GOP 的大小是两个最近的 I 帧之间的距离。 在这里。 您能否向我建议如何计算给定 h264 文件的 GOP 大小。 最好用C/C++实现。谢谢
我个人更喜欢按 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
...
好吧,仅仅解析比特流以找到每个 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/ 上的参考实现
如果您需要这部分的帮助,请告诉我:-)
#!/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
使用命令如:
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"
由于每个 GOP 都以关键帧开始,因此您需要计算这些关键帧。
pict_type
可能会产生误导,因为所有类型都可能出现在 GOP 内部。
ffprobe -show_frames video_file.h264 | grep -A 3 "type=video" | grep "key_frame=1" | wc -l
ffprobe -i video_file.h264 -show_frames -of flat |grep I
frames.frame.1.pict_type="I"
frames.frame.308.pict_type="I"
frames.frame.805.pict_type="I"
frames.frame.1282.pict_type="I"
frames.frame.1750.pict_type="I"
frames.frame.2221.pict_type="I"
frames.frame.2620.pict_type="I"
frames.frame.3178.pict_type="I"
frames.frame.3693.pict_type="I"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.