I am using cv2.VideoWriter() to record from a single camera and writing the video to a .mp4 file with a HEVC codec. I had this script previously working on a (Windows) laptop with the following code:
video = cv2.VideoCapture(0)
frame_width = int(video.get(3))
frame_height = int(video.get(4))
# create output file
out1 = cv2.VideoWriter(videoFileName, cv2.VideoWriter_fourcc(str('H'), str('E'), str('V'), str('C')), 30.0,
(frame_width, frame_height))
I am setting up the script on a new laptop and the above code no longer records and throws the following error:
OpenCV: FFMPEG: tag 0x43564548/'HEVC' is not supported with codec id 173 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x31766568/'hev1'
[hevc_mf @ 0000028eed319d00] COM must not be in STA mode
[ERROR:0] global /build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp (2794) open Could not open codec hevc_mf, error: Unspecified error
[ERROR:0] global /build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp (2811) open VIDEOIO/FFMPEG: Failed to initialize VideoWriter
I have read through many forums who suggest that this is not possible with cv2 because it does not support the HEVC codec. I have also read the .mp4 and HEVC are possibly not compatible. However, it was previously functioning on the other laptop. Therefore, I know it works in some manner. Note: I did not set it up initially on the other laptop.
I have also tried
# fourcc = cv2.VideoWriter_fourcc(*'mp4v')
# fourcc = cv2.VideoWriter_fourcc(*'h264')
# out1 = cv2.VideoWriter(videoFileName, fourcc, 30.0, (frame_width, frame_height))
with mp4v working but not the codec I initially had and h264 throwing an error similar to above.
Has anyone encountered a solution to this problem?
Additional info: Windows 10, Python 3.8.10 through Pycharm, cv2 installed via opencv-python and imported with ´from cv2 import cv2`