To find the closest I-frame after a given timestamp, you should narrow down the output of ffprobe to only list I-frames, and only read from a particular interval. This will make the output faster than searching for the entire file. Since we can assume there to be a keyframe around every 10 seconds, we can limit the search to a few seconds after the desired timestamp.
You can get a list of I-frames from seconds 150 to 160 with:
ffprobe \
-select_streams v \
-read_intervals 150%+10 \
-show_packets \
-show_entries packet=pts_time,flags \
-of compact=p=0 \
-v quiet \
input.mp4 | \
grep flags=K
Here, the -read_intervals option specifies the interval to read from. The format is start_time%+duration, where start_time is the start time in seconds, and duration is the duration in seconds. The %+ is a separator between the start time and duration. The + is used to indicate that the duration is relative to the start time. We use grep flags=K to only show keyframes.
To see which frame is closest (comes after) a certain timestamp, you can use awk to print the first line greater than or equal to the timestamp. For example, to find the closest I-frame after 150 seconds, you can use:
ffprobe \
-select_streams v \
-read_intervals 150%+10 \
-show_packets \
-show_entries packet=pts_time,flags \
-of compact=p=0 \
-v quiet \
input.mp4 | \
awk -F'[=|]' '$4 ~ /K/ && $2 >= 150 {print $2; exit}'
For example, this would return the pts_time of the first keyframe at or after 150 seconds. We filter out possible I-frames occurring before the start time.
Note that when using -ss before -i, FFmpeg will locate the keyframe previous to the seek point, then assign negative PTS values to all following packets up until it reaches the seek point. A player should decode but not display packets with negative PTS, and the video should start accurately.
Some players do not properly respect this and will display black video or garbage. In this case, the above script can be used to find the PTS of the keyframe after your seek point, and use that to start seeking from the keyframe. This, however, will not be accurate.
Note that if you want to be super accurate while seeking—and retain compatibility with many players—you should probably convert the video to any lossless, intra-only format, where you could cut at any point, and then re-encode it. But this will not be fast.