ffmpeg-python doesn't work in Github codespace
ffmpeg in python script - Stack Overflow
Help with writing FFMPEG Python Code
How to import ffmpeg into Python?
Videos
» pip install ffmpeg-python
import ffmpeg
import os
cwd = os.getcwd()
ffmpeg.output(ffmpeg.input(
cwd + "/videos/Kandima Signature Video - 20 seconds.mp4"), 'hi.mp4', codec='copy').run()This works in my wsl but due to some problem i have to use Github codespace where this doesn't work and throws an error about file not being found
From a brief look at FFMPY, you could do this using ffmpy.FFmpeg, as that allows any and all FFMPEG command line options, including -f. -- Click the link for documentation.
You could do the FFMPEG command with os.system. You'll need to import OS anyway to iterate through the files.
You would need to iterate through all the files in a directory though. This would be the more challenging bit, it's quite easy with a for loop though.
for filename in os.listdir(path):
if (filename.endswith(".mp4")): #or .avi, .mpeg, whatever.
os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
else:
continue
The above code iterates through the directory at path, and uses command prompt to execute your given FFMPEG command, using the filename (if it's a video file) in place of mymovie.avi
Dont have reputation to comment, hence adding another response.
Another version of ocelot's answer with the more readable f-string syntax of python -
for filename in os.listdir(path):
if (filename.endswith(".mp4")): #or .avi, .mpeg, whatever.
os.system(f'ffmpeg -i {filename} -f image2 -vf fps=fps=1 output%d.png')
else:
continue