Whilst I have not tried this myself the documentation
Where
fourcc
can be one ofMPG2
,H264
,X264
,AVC
,H265
orHEVC
would imply this, which is why it doesn’t make sense for the output file to have a .mp4 extension. I am supprised that you had to change the output file name to “.h264” instead of simply changing the extension from “.mp4” to “.h264” once the file was written. I guess internally OpenCV is adding something to the file when you specify a “.mp4” extension.