# Reading mp4 video returns false after only 45 frames

**URL:** <https://forum.opencv.org/t/reading-mp4-video-returns-false-after-only-45-frames/7663>\
**Category:** Python\
**Tags:** videoio\
**Created:** [February 20, 2022, 11:29pm UTC](https://forum.opencv.org/t/reading-mp4-video-returns-false-after-only-45-frames/7663 "2022-02-20T23:29:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![erickulcyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/erickulcyk/32/11863_2.png) [@erickulcyk](https://forum.opencv.org/u/erickulcyk)\
**Post date:** [February 20, 2022, 11:29pm UTC](https://forum.opencv.org/t/reading-mp4-video-returns-false-after-only-45-frames/7663/1 "2022-02-20T23:29:16Z")

</div>

I am using tutorial code I found, and I can open and view about the first second of my mp4 video, but after that, cap.read() returns false and the video exits. Any idea why that might be? The number of frames is reported as 9494.

Update: so after I covert it to avi using: “ffmpeg.exe” -i “GH010032.MP4” -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 GH010032.avi

Opencv can display the avi just fine. Any ideas? Is this a 264 codec issue or something?

```auto
import cv2 as cv
import numpy as np

# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
cap = cv.VideoCapture('C:\\Users\\kulcy\\Videos\\GoPro\\GH010032.MP4')
print (int(cap.get(cv.CAP_PROP_FRAME_COUNT)))
# Check if camera opened successfully
if (cap.isOpened()== False): 
  print("Error opening video stream or file")

# Read until video is completed
i=0
while(cap.isOpened()):
  print (i)
  i+=1
  if i==45:
      print ("here")

  # Capture frame-by-frame
  ret, frame = cap.read()
  if ret == True:

    # Display the resulting frame
    cv.imshow('Frame',frame)

    # Press Q on keyboard to exit
    if cv.waitKey(1) & 0xFF == ord('q'):
      break

  # Break the loop
  else:
    print ("is open: ", cap.isOpened()) 
    break

# When everything done, release the video capture object
cap.release()

# Closes all the frames
cv.destroyAllWindows()

```

Using python 3.10.2 and opencv\_python-4.5.5.62

Thanks!
