0

I am currently working on a project in django where i had to extract frames from some part of the video by cropping the video first. Here is the sample code [crop and frames extraction code][1]

def saveFrame(request):  
    
    clip = VideoFileClip("hello.mp4") 
    clip = clip.subclip(0, 15) 
    clip = clip.cutout(3, 10)
    clip.ipython_display(width = 360) 

    cap= cv2.VideoCapture('__temp__.mp4')
    i=0
    while cap.isOpened():
     ret, frame = cap.read()
     if ret == False:
        break
     cv2.imwrite('media/images/frames/'+str(i)+'.jpg',frame)
     print(i)
     i+=1
 
    cap.release()
    cv2.destroyAllWindows()

My video is located in the same directory but still when i run this code i get this error

MoviePy error: the file hello.mp4 could not be found! Please check that you entered the correct path.

Can anyone help me in solving this error? Thanks.

Trafalino
  • 135
  • 6
  • 1
    welcome to stackoverflow! please never post pictures of your code, especially not just photos of your monitor. copy and paste the relevant sections into code blocks in your question. this will help us answer your question more easily – jemand771 Jun 07 '21 at 09:22
  • Okay edited now – Maria Iftikhar Jun 07 '21 at 09:29

1 Answers1

2

Which same directory, the directory of the view file or BASE_DIR? it is always better to make your path absolute as in Webapps, you can't know for sure what is the current working dir.

if the file in BASE_DIR

from django.conf import settings
clip = VideoFileClip(settings.BASE_DIR + "/hello.mp4") 

if in the same dir as the script

import os
clip = VideoFileClip(os.path.dirname(__file__) + "/hello.mp4") 
Mohamed ElKalioby
  • 1,908
  • 1
  • 12
  • 13