Video Output fail

I use the normal code to read video and output video

when i use fourCC = cv2.VideoWriter_fourcc(*‘h264’), it show
OpenCV: FFMPEG: tag 0x34363268/‘h264’ is not supported with codec id 27 and format ‘mp4 / MP4 (MPEG-4 Part 14)’
OpenCV: FFMPEG: fallback to use tag 0x31637661/‘avc1’
[ERROR:0@670.249] global cap_ffmpeg_impl.hpp:2991 open Could not find encoder for codec_id=27, error: Encoder not found
[ERROR:0@670.249] global cap_ffmpeg_impl.hpp:3066 open VIDEOIO/FFMPEG: Failed to initialize VideoWriter
QObject::moveToThread: Current thread (0x56281fe72f10) is not the object’s thread (0x56281fc61690).

And the output file didn’t appear.

And when i use fourCC = cv2.VideoWriter_fourcc(*‘mp4v’)
the output video is only 258kb. why is it

i do need the video encodec is h264, how can i achieve it

[ERROR:0@112.957] global cap_ffmpeg_impl.hpp:2991 open Could not find encoder for codec_id=27, error: Encoder not found
[ERROR:0@112.957] global cap_ffmpeg_impl.hpp:3066 open VIDEOIO/FFMPEG: Failed to initialize VideoWriter