[英]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.