Saving video from frames in with fourcc codec h264 and h265 with opencv
0
I am saving frames from live stream to a video with h264 codec. I tried this with openCV (versions 3.4 and 4.4) in python but I am not able to save it. I can save video in XVID and many other codecs but I am not successful in h264 and h265.
I am using windows opencv 4.4 in Python.
My sample code is as follow
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
ret,frame = cap.read()
if ret == True:
width = int(cap.get(3)) # float
height = int(cap.get(4)) # float
# fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
fourcc = cv2.VideoWriter_fourcc(*'H264')
out = cv2.VideoWriter(filename, fourcc, 30, (width,height))
out.write(frame)
out.release()
Can anyone help me how can I save video in h264 and h265.
I am saving frames from live stream to a video with h264 codec. I tried this with openCV (versions 3.4 and 4.4) in python but I am not able to save it. I can save video in XVID and many other codecs but I am not successful in h264 and h265.
I am using windows opencv 4.4 in Python.
My sample code is as follow
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
ret,frame = cap.read()
if ret == True:
width = int(cap.get(3)) # float
height = int(cap.get(4)) # float
# fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
fourcc = cv2.VideoWriter_fourcc(*'H264')
out = cv2.VideoWriter(filename, fourcc, 30, (width,height))
out.write(frame)
out.release()
Can anyone help me how can I save video in h264 and h265.
What is bloody filename?
Here is tutorial for Getting Started with Videos
afaik, the opencv_ffmpeg.dll does not support h265 codec (gpl)
@berak. Need to install H265. sudo apt-get install ffmpeg x264 libx264-dev and sudo apt-get install ffmpeg x265 libx265-dev.
supra, nope, it's on windows, and all of it is of no use there
H264(2K) for mp4. And H265(4K) for mp5
what happens here https://answers.opencv.org/question/2...
@Imran Hassan, please do NOT duplicate questions here, thank you.
@berak Sorry for duplication of the question. Actually, it was a little misunderstanding. I also tried to install "sudo apt-get install ffmpeg x264 libx264-dev and sudo apt-get install ffmpeg x265 libx265-dev" in Linux but it is also not able to save it.
Can you explain or guide how I can I build openCV and ffmpeg having these two libraries and to install it in python so that I can save video in h264.
@supra56 I tried filemanes with different extension like saveVideo.mkv, saveVideo.avi, saveVideo.mp4
But still it is not working.