Maria Iftikhar
Maria Iftikhar

Reputation: 3

Movie.py Error file not found on given path

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.

Upvotes: 0

Views: 1166

Answers (1)

Mohamed ElKalioby
Mohamed ElKalioby

Reputation: 2334

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") 

Upvotes: 2

Related Questions