如何在不增加 OpenCV 大小的情况下将视频分成帧
How to break video into Frames without Increase in Size in OpenCV
我有一个 478Mb 大的视频,我想拆分成 png 格式,但是当我尝试时,每帧变成大约 2Mb(有 39.5k 帧),结果大小超过 60Gb。
有没有办法在不大幅增加尺寸的情况下做到这一点?我的代码如下。
vidcap = cv2.VideoCapture(filename)
success = True
frame = 0
while success:
success, img = vidcap.read()
png_name = videoname + '_frame_' + str(frame) + '.png'
cv2.imwrite(FRAMES_FOLDER + '/' + png_name, img)
frame += 1
vidcap.release()
只是复制@barny 的答案。似乎最好的办法就是改用 JPEG。
Video compression works by sending a full frame then a number (20, 50, 60?) of ‘difference’ frames before the next full frame - this is (as you are discovering) much more efficient than encoding each full frame. Saving to lossy jpeg format files is likely to be a lot smaller than lossless png and as the source is m/jpeg video there’s not much quality to be compromised by using jpeg compared to png.
我有一个 478Mb 大的视频,我想拆分成 png 格式,但是当我尝试时,每帧变成大约 2Mb(有 39.5k 帧),结果大小超过 60Gb。 有没有办法在不大幅增加尺寸的情况下做到这一点?我的代码如下。
vidcap = cv2.VideoCapture(filename)
success = True
frame = 0
while success:
success, img = vidcap.read()
png_name = videoname + '_frame_' + str(frame) + '.png'
cv2.imwrite(FRAMES_FOLDER + '/' + png_name, img)
frame += 1
vidcap.release()
只是复制@barny 的答案。似乎最好的办法就是改用 JPEG。
Video compression works by sending a full frame then a number (20, 50, 60?) of ‘difference’ frames before the next full frame - this is (as you are discovering) much more efficient than encoding each full frame. Saving to lossy jpeg format files is likely to be a lot smaller than lossless png and as the source is m/jpeg video there’s not much quality to be compromised by using jpeg compared to png.