Ask Your Question
0

"stuck" frames being skipped when using VideoWriter?

asked 2019-05-02 12:34:45 -0600

rfm0110 gravatar image

updated 2019-05-02 12:47:06 -0600

I have a video that has "stuck" frames that remain on screen without changing due to lag. I read and write this video wihtout making any changes to it using opencv

cap = cv2.VideoCapture('input.mp4')

size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
fps = cap.get(cv2.CAP_PROP_FPS)

outputVideo = 'output.mp4'
out = cv2.VideoWriter(outputVideo,fourcc, fps, (size))

while (cap.isOpened()):
  ret, frame = cap.read()
  if ret == True:
      out.write(frame)
  else:
      break

out.release()

the video that I get in return has almost the same length as the original (it has 2 less seconds) but lo and behold the stuck frames aren't there anymore. At the start, the new video is ahead of the original, but by the end it's lagging behind. My best guess is that it has to do with the video compression/encoder that I use. I would like make the video so that each frame is presented at the same time as in the original. Any help is appreciated

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-05-04 15:57:49 -0600

rfm0110 gravatar image

I solved it by changing the format of the original video to .mov instead of .mp4. duplicate frames where there afterwards.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-05-02 12:33:15 -0600

Seen: 1,507 times

Last updated: May 04 '19