iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 26
0
自我挑戰組

軟體開發隨筆雜記--試著解決問題系列 第 25

[Python] 把 mp4 轉換成 gif

  • 分享至 

  • xImage
  •  

https://www.programmersought.com/article/97253978617/

pip3 install MoviePy
Collecting MoviePy
  Downloading https://files.pythonhosted.org/packages/18/54/01a8c4e35c75ca9724d19a7e4de9dc23f0ceb8769102c7de056113af61c3/moviepy-1.0.3.tar.gz (388kB)
     |████████████████████████████████| 389kB 344kB/s
Requirement already satisfied: decorator<5.0,>=4.0.2 in c:\python37\lib\site-packages (from MoviePy) (4.4.1)
Requirement already satisfied: tqdm<5.0,>=4.11.2 in c:\python37\lib\site-packages (from MoviePy) (4.46.1)
Requirement already satisfied: requests<3.0,>=2.8.1 in c:\python37\lib\site-packages (from MoviePy) (2.22.0)
Collecting proglog<=1.0.0
  Downloading https://files.pythonhosted.org/packages/fe/ab/4cb19b578e1364c0b2d6efd6521a8b4b4e5c4ae6528041d31a2a951dd991/proglog-0.1.9.tar.gz
Requirement already satisfied: numpy>=1.17.3 in c:\python37\lib\site-packages (from MoviePy) (1.17.4)
Requirement already satisfied: imageio<3.0,>=2.5 in c:\python37\lib\site-packages (from MoviePy) (2.6.1)
Collecting imageio_ffmpeg>=0.2.0
  Downloading https://files.pythonhosted.org/packages/ec/5e/58ed5dcf183d4121664b147cab768b74bc5cdc4ea2765905cd2f86e1fde9/imageio_ffmpeg-0.4.2-py3-none-win_amd64.whl (22.6MB)
     |████████████████████████████████| 22.6MB 3.3MB/s
Requirement already satisfied: certifi>=2017.4.17 in c:\python37\lib\site-packages (from requests<3.0,>=2.8.1->MoviePy) (2019.11.28)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\python37\lib\site-packages (from requests<3.0,>=2.8.1->MoviePy) (1.25.7)
Requirement already satisfied: idna<2.9,>=2.5 in c:\python37\lib\site-packages (from requests<3.0,>=2.8.1->MoviePy) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\python37\lib\site-packages (from requests<3.0,>=2.8.1->MoviePy) (3.0.4)
Requirement already satisfied: pillow in c:\python37\lib\site-packages (from imageio<3.0,>=2.5->MoviePy) (6.2.1)
Building wheels for collected packages: MoviePy, proglog
  Building wheel for MoviePy (setup.py) ... done
  Created wheel for MoviePy: filename=moviepy-1.0.3-cp37-none-any.whl size=110732 sha256=5c2273636e2fd4baf7c289c101b98dfcf7c9d937f57728764f3bbb8d0414229f
  Stored in directory: C:\Users\USER\AppData\Local\pip\Cache\wheels\e0\fe\1c\f4e6dca9e828d4b979c04e461d7fcc5b8e7bd35f947e665b65
  Building wheel for proglog (setup.py) ... done
  Created wheel for proglog: filename=proglog-0.1.9-cp37-none-any.whl size=6152 sha256=235be3498a9509ebdc06206a8f95d8ba3eeff0c80374c84b767a6768e60f9264
  Stored in directory: C:\Users\USER\AppData\Local\pip\Cache\wheels\65\56\60\1d0306a8d90b188af393c1812ddb502a8821b70917f82dcc00
Successfully built MoviePy proglog
Installing collected packages: proglog, imageio-ffmpeg, MoviePy
Successfully installed MoviePy-1.0.3 imageio-ffmpeg-0.4.2 proglog-0.1.9

https://ithelp.ithome.com.tw/upload/images/20201011/20119608L6JtEYbXOI.png
https://ithelp.ithome.com.tw/upload/images/20201011/20119608E0pcjTVqDf.jpg
test.py

from moviepy.editor import *
clip=(VideoFileClip("110721267_293181645343523_2047352631094375347_n.mp4"))
clip.write_gif("output.gif")
print("Conversion completed")

執行

t:   0%|          | 0/450 [00:00<?, ?it/s, now=None]
t:   1%|          | 3/450 [00:00<00:18, 23.68it/s, now=None]
t:   1%|          | 5/450 [00:00<00:21, 20.41it/s, now=None]
t:   2%|▏         | 7/450 [00:00<00:23, 18.66it/s, now=None]
.
.
.
t:  99%|█████████▉| 447/450 [05:24<00:06,  2.18s/it, now=None]
t: 100%|█████████▉| 448/450 [05:26<00:04,  2.14s/it, now=None]
t: 100%|█████████▉| 449/450 [05:29<00:02,  2.30s/it, now=None]
t: 100%|██████████| 450/450 [05:31<00:00,  2.25s/it, now=None]
                                                              
Conversion completed

https://ithelp.ithome.com.tw/upload/images/20201011/201196083TkfXq99vJ.jpg
https://ithelp.ithome.com.tw/upload/images/20201011/201196087hSPLucwlk.jpg


上一篇
[Python][OpenCV]如何利用Tesserect OCR做翻譯器
下一篇
[Python]如何Text to Speech: pyttsx3, gTTS
系列文
軟體開發隨筆雜記--試著解決問題33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言