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
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 :-)
ldecod.exe
outputs the frametype to stdout. It would also be quite simple to add a counter in the src-code to count the frame-number difference between IDR (I)-frames. –
Disfranchise I personally prefer filtering by pict_type:
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
...
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 :-)
ldecod.exe
outputs the frametype to stdout. It would also be quite simple to add a counter in the src-code to count the frame-number difference between IDR (I)-frames. –
Disfranchise #!/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
Since every GOP starts with a keyframe you need to count those.
pict_type
can be misleading as all types can occur inside 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"
use command like:
ffprobe -show_entries frame=pict_type mp4_sample.mp4 -of flat | grep I
and you will see the result like:
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"
© 2022 - 2024 — McMap. All rights reserved.