record API command has this waitForIDR parameter. WaitForIDR is a non-mandatory parameter which has a default value of true which means in your case, record waits for the keyframe first. This may have caused the delay.
So you may replace your record command from this :
record localstreamname=1234 chunklength=900 pathtofile=/home/username/temp/recording.mp4 type=mp4 keepalive=0 overwrite=0
to this:
record localstreamname=1234 chunklength=900 pathtofile=/home/username/temp/recording.mp4 type=mp4 keepalive=0 overwrite=0 waitForIdr=0
Let’s see if this will not cause any delay anymore.