Closed NiKiTjAOFF closed 4 months ago
Please always include your specs like we ask for in our issue templates – MoviePy version, platform used etc. – to help pinpoint what causes your problem, thanks.
Please always include your specs like we ask for in our issue templates – MoviePy version, platform used etc. – to help pinpoint what causes your problem, thanks.
They're already in there
After I ran the following code on collab:
from moviepy.editor import *
clip =VideoFileClip("2024-02-25 23-53-31.mp4")
clip.write_gif("2024-02-25 23-53-31.gif")
It gave me this warn:
MoviePy - Building file 2024-02-25 23-53-31.gif with imageio.
t: 100%|█████████▉| 2322/2324 [00:09<00:00, 277.26it/s, now=None]WARNING:py.warnings:/usr/local/lib/python3.10/dist-packages/moviepy/video/io/ffmpeg_reader.py:123: UserWarning: Warning: in file 2024-02-25 23-53-31.mp4, 691200 bytes wanted but 0 bytes read,at frame 2323/2324, at time 38.72/38.72 sec. Using the last valid frame instead.
warnings.warn("Warning: in file %s, "%(self.filename)+
Problem solved. Make sure ffmpeg.exe is in PATH, so that the following code could work. This code not only converts all the mp4 videos inside of a folder, but also changes the speed of a video, it's fps and res without loosing any quality. Also you can turn on lantzoc filtering.
from moviepy.editor import *
from typing import List
import os
def list_image_files(directory: str) -> List[str]:
image_extensions = [".mp4"]
image_files = [f for f in os.listdir(directory) if os.path.splitext(f)[1].lower() in image_extensions]
return image_files
SOURCE_DIRECTORY_PATH = r"videos"
list = list_image_files(SOURCE_DIRECTORY_PATH)
print(list)
height = "640"
speedX = 0.5
duration = 2
lanczos_is_off = False
for video_name_with_extension in list:
video_name = video_name_with_extension.split('.')[0]
video_path = SOURCE_DIRECTORY_PATH + "\\" + video_name_with_extension
gif_path = SOURCE_DIRECTORY_PATH + "\\" + video_name + ".gif"
print(video_path)
print(gif_path)
video = VideoFileClip(video_path)
fps = video.duration / duration
if lanczos_is_off:
command = f'ffmpeg -i "{video_path}" -vf "fps={fps},setpts={speedX}*PTS,scale={height}:-1" -c:v gif "{gif_path}" -y'
else :
command = f'ffmpeg -i "{video_path}" -vf "fps={fps},setpts={speedX}*PTS,scale={height}:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=none" -c:v gif "{gif_path}" -y'
os.system(command)
They're already in there
Thanks, I didn't see that because I scan for them at the bottom of an issue when I tag it.
Problem solved.
If this means this issue is solved, please don't forget to close it. Thank you.
After I use these lines of code:
It proceeds the mp4 video, saves gif with 0 bytes and continueing to save something somewhere, so that after 30s my disk space is shortened for 1gb. After I restart my pc the space's restored to as it was before.
VideoFileClip actually contains video.
After I interrupt execution I get:
My setup: Windows 10, python 3.9, venv, modeules of moviepy:
pls help, I followed tutorial how to convert mp4 to gif: https://www.youtube.com/watch?v=mheEk_XyAv8 and this happened