Skip to content

Commit

Permalink
save the video
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCutestCat committed Aug 26, 2024
1 parent 4e68e9b commit 2866717
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ This demo draws inspiration from:
- [Matrices](https://matrices.app/)
- [Guru](https://www.getguru.ai/)

<video controls>
<source src="./video/superexcel_example.mp4" type="video/mp4">
</video>
![SuperExcel Example](./video/superexcel_example.gif)
26 changes: 26 additions & 0 deletions video/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from moviepy.editor import VideoFileClip

def video_to_gif(video_path, output_gif_path, start_time=None, end_time=None, fps=10):
"""
Converts a video file into a GIF.
:param video_path: The path to the video file.
:param output_gif_path: The path where the output GIF will be saved.
:param start_time: Optional; starting time in the video from where GIF will be made.
:param end_time: Optional; end time in the video until where GIF will be made.
:param fps: Frames per second for the GIF. Lower value means smaller GIF file size.
"""
try:
with VideoFileClip(video_path) as video_clip:
# If start_time and end_time are defined, cut the video
if start_time is not None or end_time is not None:
video_clip = video_clip.subclip(start_time, end_time)

# Write the video clip to a GIF file
video_clip.write_gif(output_gif_path, fps=fps)
print(f"GIF saved successfully at {output_gif_path}")
except Exception as e:
print(f"An error occurred: {e}")

# Example usage:
# video_to_gif("path/to/video.mp4", "output.gif", start_time=5, end_time=15)
Binary file added video/superexcel_example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed video/superexcel_example.mp4
Binary file not shown.

0 comments on commit 2866717

Please sign in to comment.