Created
March 28, 2019 20:28
-
-
Save whitead/45159ede77b3477796c4c7cbc74f4b51 to your computer and use it in GitHub Desktop.
Moviepy and FFMPEG Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import matplotlib | |
| import numpy as np | |
| import moviepy | |
| from moviepy.editor import VideoClip | |
| from moviepy.video.io.bindings import mplfig_to_npimage | |
| x = np.linspace(-5,5,100) | |
| fig, ax = plt.subplots(figsize=(12,8)) | |
| line = ax.plot(x, x**2 + np.cos(5 * x))[0] | |
| N = 180 | |
| duration = 3 | |
| fps = N // duration | |
| def make_frame(t): | |
| i = int(t * fps) | |
| line.set_ydata(x**2 + np.cos(5 * (x + 2 * np.pi * t / duration / 5))) | |
| return mplfig_to_npimage(fig) | |
| animation = VideoClip(make_frame, duration=duration) | |
| animation.write_videofile('video.mp4', fps=fps, codec='libx264') | |
| #ffmpeg -i input.mp4 -c:v libx264 -movflags +faststart -vf scale=-2:1080,format=yuv420p -crf 28 -ss 00:01:27 -t 00:01:00 output.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment