gstaff commited on
Commit
b998328
1 Parent(s): 4e019ea

Add demo files.

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ file_example_MP4_480_1_5MG.mp4 filter=lfs diff=lfs merge=lfs -text
2023-10-16-daily-demo-screenshot.png ADDED
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: Mp4 Converter
3
- emoji: 🏢
4
- colorFrom: pink
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.48.0
@@ -10,4 +10,14 @@ pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Mp4 Converter
3
+ emoji: 🎥
4
+ colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.48.0
 
10
  license: apache-2.0
11
  ---
12
 
13
+ # 2023-10-16 Daily Demo - MP4 Converter
14
+
15
+ A daily demo space created by [@gstaff](https://huggingface.co/gstaff).
16
+
17
+ ## Description
18
+ A utility to convert mp4 files to animated gifs.
19
+
20
+ ![screenshot](2023-10-16-daily-demo-screenshot.png "Screenshot")
21
+
22
+ ## Credits
23
+ Example video from gradio docs.
file_example_MP4_480_1_5MG.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71944d7430c461f0cd6e7fd10cee7eb72786352a3678fc7bc0ae3d410f72aece
3
+ size 1570024
mp4_converter.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tempfile
2
+ import gradio as gr
3
+
4
+ from moviepy.editor import VideoFileClip
5
+ import moviepy.video.io.ffmpeg_tools as ffmpeg_tools
6
+
7
+ # TODO: Finalize result gif size with pygifscicle? https://github.com/LucaCappelletti94/pygifsicle Maybe optimize option
8
+ # TODO: Extra delay frames?
9
+ # git lfs track --filename file_example_MP4_480_1_5MG.mp4
10
+ def convert_mp4_to_gif(input_video_path, fps):
11
+ if input_video_path is None:
12
+ return None
13
+ # Save the reversed frames as a new GIF
14
+ with tempfile.NamedTemporaryFile(suffix=".gif", delete=False) as temp_file:
15
+ temp_filename = temp_file.name
16
+
17
+ # Load the video clip
18
+ video_clip = VideoFileClip(input_video_path)
19
+
20
+ # Set the desired frame rate (frames per second) for the GIF
21
+ video_clip = video_clip.set_duration(video_clip.duration)
22
+ video_clip = video_clip.set_fps(fps)
23
+
24
+ # Export the video as a GIF
25
+ video_clip.write_gif(temp_filename, program='ffmpeg')
26
+
27
+ # Close the video clip
28
+ video_clip.close()
29
+
30
+ return [temp_filename]
31
+
32
+
33
+ with gr.Blocks() as demo:
34
+ gr.Markdown(value='# MP4 Converter')
35
+ with gr.Row():
36
+ with gr.Column(scale=1):
37
+ gr.Markdown('## Load mp4 video to convert to an animated gif')
38
+ in_video = gr.Video(label="Input mp4", format='mp4')
39
+ frame_rate = gr.Slider(label="Frames per Second", value=10, minimum=1,
40
+ maximum=360, step=1, interactive=True)
41
+ run_button = gr.Button(variant='primary')
42
+ with gr.Column(scale=1):
43
+ gr.Markdown('## View the animated gif')
44
+ image_out = gr.Gallery(label="Animated Gif Image")
45
+ clear_button = gr.ClearButton(components=[image_out])
46
+
47
+ in_video.change(convert_mp4_to_gif, [in_video, frame_rate], [image_out])
48
+ run_button.click(convert_mp4_to_gif, [in_video, frame_rate], [image_out])
49
+ gr.Examples(
50
+ examples=[['file_example_MP4_480_1_5MG.mp4', 60]],
51
+ inputs=[in_video, frame_rate], outputs=[image_out], fn=convert_mp4_to_gif, cache_examples=True)
52
+
53
+ if __name__ == '__main__':
54
+ demo.launch()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ moviepy