Working:
import ffmpeg
import os
path = "K://Delete//"
dir_list = os.listdir(path)
for i in dir_list:
ffmpeg.input(path+i).output("K://t//new%d.png", vf='fps=1/10').run()
os.remove(path+i)
Not working:
import ffmpeg
import os
from datetime import datetime
path = "K://Delete//"
dir_list = os.listdir(path)
for i in dir_list:
dt_string=datetime.now().strftime("%d%m%Y%H%M%S%f")
ffmpeg.input(path+i).output("K://t//"+i+"%s.png"%dt_string, vf='fps=1/10').run()
*#%d or %s both not working.*
os.remove(path+i)
I tried to avoid same name files to be generated. Because that will raise error in future.
I tried to give all the files unique names that is appending datetime as a String to the file.
But ffmpeg is showing error that "Conversion Failed!"
Why is this happening and how can I fix it?
I think you want to append a unique timestamp to each frame extracted from the video files. I see that using
%sand%dcan be problematic when constructing file names with FFmpeg because FFmpeg uses%das a placeholder for sequence numbers when generating output files.To avoid this issue, you can construct the filename in Python first and then pass it to FFmpeg without using any
%formatting:This way, the filename is already determined before it's passed to FFmpeg, and FFmpeg doesn't have to handle any formatting or placeholders in the filename itself.