Can you losslessly ediit H264 at the GOP level?
This is possible to do, in theory. The key is to match all relevant source bitstream properties when encoding.

#1 Segment source video

ffmpeg -i source.mp4 -c copy -an -f segment -segment_time 0.01 seg%d.ts


Since the segment muxer by default only splits at keyframes, by providing a very low segment time, each produced segment will be one GOP long.

(I suggest using the whole audio from the source, we don't extract it here)

#2 Re-encode first segment

ffmpeg -i seg1.ts {-encoding args} -copyts -x264opts stitchable{+any-other-args} new1.ts


It's important here to match source settings.

#3 Rejoin segments

ffmpeg -i "concat:new1.ts|seg2.ts|..." -i source.mp4 -c copy -map 0 -map 1:a new.mp4