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.

2
  • 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 Commented Jun 7, 2021 at 9:22
  • Okay edited now Commented Jun 7, 2021 at 9:29

1 Answer 1

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") 
Sign up to request clarification or add additional context in comments.

1 Comment

Solved my issue. Thanks you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.