Faster ffprobe-based detection of open GOP h264 ?
I was looking at videohelp forum https://web.archive.org/web/20201125203546/https://forum.videohelp.com/threa... (web archive link because it hopefully will stay active for some time even if forum software will be upgraded and ruin old links in the future) It provides this ffprobe-based method of seeing if given h264 video stream is Open GOP or not : echo entry,pkt_pts_time,pict_type,coded_picture_number > "%~n1.csv" ffprobe -v 32 -stats -y -hide_banner -i %1 -select_streams v -print_format csv -of csv -show_entries "frame=pkt_pts_time,pict_type,coded_picture_number" >> "%~n1.csv" === quote ==== You can see that the last frame of the first GOP is a B frame -- so that's an open GOP. Also, the coded picture number is higher than that of the I frame after it -- indicating that the I frame had to be decoded before the B frame, another indication of an open GOP. === quote ends === I checked one of my videos: ffprobe -v 32 -stats -y -hide_banner -i ~/Sea_of_life_plus_Mikura_dolphins_test.mp4 -select_streams v -print_format csv -of csv -show_entries "frame=pkt_pts_time,pict_type,coded_picture_number" >> "Sea_of_life-n1.csv" and it seems resulting cvs file show it as open GOP consistently with mediainfo: frame,8.308300,B,250 frame,8.341667,I,249 frame,8.375033,B,253 mediainfo (v23.11) snip: === snip === Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4.1 Format settings : 4 Ref Frames Format settings, CABAC : No Format settings, Reference frames : 4 frames Codec ID : avc1 Codec ID/Info : Advanced Video Coding Duration : 5 min 4 s Bit rate : 16.0 Mb/s Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 29.970 (30000/1001) FPS Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.257 Stream size : 575 MiB (99%) Writing library : x264 core 148 Encoding settings : cabac=0 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=0 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=3 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=0 / b_bias=0 / direct=1 / weightb=1 / open_gop=1 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=0 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=16000 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / ip_ratio=1.41 / aq=1:1.00 Codec configuration box : avcC ==== snip ends === So, at least I may try to cut this video at various intervals and see if cutting breaks on specifically open-gop h264 stream. But as it was said in forum post above - ffprobe a bit slow, few minutes for whole video, eating one cpu core completely. Is there faster way to get this info ?
чт, 11 янв. 2024 г., 03:13 Andrew Randrianasulu <randrianasulu@gmail.com>:
I was looking at videohelp forum
https://web.archive.org/web/20201125203546/https://forum.videohelp.com/threa...
(web archive link because it hopefully will stay active for some time even if forum software will be upgraded and ruin old links in the future)
It provides this ffprobe-based method of seeing if given h264 video stream is Open GOP or not :
echo entry,pkt_pts_time,pict_type,coded_picture_number > "%~n1.csv"
ffprobe -v 32 -stats -y -hide_banner -i %1 -select_streams v -print_format csv -of csv -show_entries "frame=pkt_pts_time,pict_type,coded_picture_number" >> "%~n1.csv"
=== quote ====
You can see that the last frame of the first GOP is a B frame -- so that's an open GOP. Also, the coded picture number is higher than that of the I frame after it -- indicating that the I frame had to be decoded before the B frame, another indication of an open GOP.
=== quote ends ===
I checked one of my videos:
ffprobe -v 32 -stats -y -hide_banner -i ~/Sea_of_life_plus_Mikura_dolphins_test.mp4 -select_streams v -print_format csv -of csv -show_entries "frame=pkt_pts_time,pict_type,coded_picture_number" >> "Sea_of_life-n1.csv"
and it seems resulting cvs file show it as open GOP consistently with mediainfo:
frame,8.308300,B,250 frame,8.341667,I,249 frame,8.375033,B,253
mediainfo (v23.11) snip:
=== snip ===
Video
ID : 1
Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4.1 Format settings : 4 Ref Frames
Format settings, CABAC : No Format settings, Reference frames : 4 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 5 min 4 s Bit rate : 16.0 Mb/s Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.257 Stream size : 575 MiB (99%)
Writing library : x264 core 148
Encoding settings : cabac=0 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=0 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=3 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=0 / b_bias=0 / direct=1 / weightb=1 / open_gop=1 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=0 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=16000 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / ip_ratio=1.41 / aq=1:1.00
Codec configuration box : avcC
==== snip ends ===
So, at least I may try to cut this video at various intervals and see if cutting breaks on specifically open-gop h264 stream.
But as it was said in forum post above - ffprobe a bit slow, few minutes for whole video, eating one cpu core completely.
Is there faster way to get this info ?
Additionally, I tried to add another variable key_frame to see difference between IDR frames (I type , key_frame=1) and just I type frames: ffprobe -v 32 -stats -y -hide_banner -i ~/Sea_of_life_plus_Mikura_dolphins_test.mp4 -select_streams v -print_format csv -of csv -show_entries "frame=pkt_pts_time,pict_type,key_frame,coded_picture_number" >> "Sea_of_life-n1-v1.csv" but resulting csv file grouped them like frame,1,8.341667,I,249 like key_frame come before pkt_pts_time. May be this is bug due to ffprobe being from v. 4.4.4 and not latest. Not sure. But interesting. I also see few picture types in libavutil/avutil.h enum AVPictureType { AV_PICTURE_TYPE_NONE = 0, ///< Undefined AV_PICTURE_TYPE_I, ///< Intra AV_PICTURE_TYPE_P, ///< Predicted AV_PICTURE_TYPE_B, ///< Bi-dir predicted AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG-4 AV_PICTURE_TYPE_SI, ///< Switching Intra AV_PICTURE_TYPE_SP, ///< Switching Predicted AV_PICTURE_TYPE_BI, ///< BI type }; Is this list complete when it comes to codecs like HEVC ?
De : ffmpeg-user <ffmpeg-user-bounces@ffmpeg.org> De la part de Andrew Randrianasulu
But as it was said in forum post above - ffprobe a bit slow, few minutes for whole video, eating one cpu core completely.
Is there faster way to get this info ? Closed vs open gop is usually a local "keyframe" matter. It is not clear to me what is your intent : do you want to make sure 100% of the keyframes are closed gop ? If so, you have to parse the stream, so indeed, it takes a long time. I don't think there is another option. MP4 muxer only has the global "keyframe" info. With quicktime/mpeg2 you would have gotten stss/stps = closed/open gop distinction, but it is not your use case. Only one thing: as you noticed using MediaInfo, when encoding with libx264, there is an SEI describing the encoding parameters and you can get the "open_gop" field. If you get a very fresh (less than 2 weeks) ffmpeg build, there is an option to display this with the showinfo filter: ffmpeg -i xxx.mp4 -vf showinfo=udu_sei_as_ascii=1 -frames 1 -f null null
Nicolas
чт, 11 янв. 2024 г., 17:42 Nicolas Gaullier <nicolas.gaullier@cji.paris>:
De : ffmpeg-user <ffmpeg-user-bounces@ffmpeg.org> De la part de Andrew Randrianasulu
But as it was said in forum post above - ffprobe a bit slow, few minutes for whole video, eating one cpu core completely.
Is there faster way to get this info ? Closed vs open gop is usually a local "keyframe" matter. It is not clear to me what is your intent : do you want to make sure 100% of the keyframes are closed gop ?
yes, I want to check my pre-existing videos for this, partially for testing how various tools (avidemux, vidcut, ffmpeg) can cut them, partially because I suspect this may play some role in how badly mesa's vdpau driver on vp5 based nvidia hw decoder reacts to seeks (if majority of internet streams today are closed-gop, then I might trigger some less-common codepath with my home-encoded videos ). If so, you have to parse the stream, so indeed, it takes a long time. I
don't think there is another option. MP4 muxer only has the global "keyframe" info. With quicktime/mpeg2 you would have gotten stss/stps = closed/open gop distinction, but it is not your use case. Only one thing: as you noticed using MediaInfo, when encoding with libx264, there is an SEI describing the encoding parameters and you can get the "open_gop" field. If you get a very fresh (less than 2 weeks) ffmpeg build, there is an option to display this with the showinfo filter: ffmpeg -i xxx.mp4 -vf showinfo=udu_sei_as_ascii=1 -frames 1 -f null null
thanks, I have ffmpeg git as part of mplayer, but also can compile it separately.
Nicolas _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
participants (2)
-
Andrew Randrianasulu -
Nicolas Gaullier