0

In my current directory I have a file.mp4.

Problem:
I want to search the name of that file and then put file.mp4 in the VideoFileClip('file.mp4').

How can I do that? I get an error when I run the code below, because VideoFileClip() accepts only String. How can we put search function inside a function?

My code:

from glob import glob
from moviepy.editor import VideoFileClip

clip = VideoFileClip(glob("*.mp4"))
s = clip.duration
clip.close() 

I also tried replacing:

clip = VideoFileClip( glob("*.mp4") )

with this alternative:

clip = VideoFileClip( str(glob("*.mp4")) )
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • 1
    What is `VideoFileClip`? Is this part of some third-party library/framework? Or is this a custom class..? – Gino Mempin Dec 31 '22 at 08:08
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 31 '22 at 08:08
  • from glob import glob -----> from moviepy.editor import VideoFileClip -----> clip = VideoFileClip(glob("*.mp4")) -------> s=clip.duration -------> clip.close() ---------> I face with error when I run this. because VideoFileClip () accepts only string. – Vahid Hosseini Dec 31 '22 at 10:24
  • I want to search in a current directory. then find the file.mp4. and finally I put the name of file.mp4 in the VideoFileClip (). This is my problem. – Vahid Hosseini Dec 31 '22 at 10:26
  • from glob import glob -----> from moviepy.editor import VideoFileClip -----> clip = VideoFileClip(str(glob("*.mp4"))) -------> s=clip.duration -------> clip.close() ---------> I also tried this one. however, the error is still exist. – Vahid Hosseini Dec 31 '22 at 11:01

1 Answers1

0

"How can we put search function inside a function"

You don't put a "search function inside a function".

  • First you get the result of a search function (put it into a variable).
  • Then you use that same result (the variable) as the input of some other function.

See if a code logic like below is closer to achieving what you want (ps: code is untested):

import glob
from moviepy.editor import VideoFileClip

## Glob gives back an Array (is a list with String for each file's name)
file_list = glob.glob("*.mp4")
print("found MP4 file(s) :", file_list)

## From the Array list, now select the specific String you want to use with some function
## Test by getting the first filename's String (is at position 0 inside the list)
my_file_str = file_list[0]
print("Using this file String :", my_file_str)

clip = VideoFileClip( my_file_str)
sec = clip.duration
print("sec (clip.duration) :", sec, "seconds")
clip.close()
VC.One
  • 14,790
  • 4
  • 25
  • 57