如何从 Matplotlib 图表制作视频
首先,你需要确保你的图表都以包含帧号(从 1 开始)的相同名称模式保存,必须用零填充!例如,你的图表应命名为 myplot_000001.png 或 myplot_0123。这可以使用例如以下命令完成
save_frame.py
fig.savefig(f'myplots/myplot_{timestep:06d}.png')06d 将数字(在 timestep 变量中)填充到总共 6 位数。
现在,像这样使用 ffmpeg 创建视频:
create_video.sh
ffmpeg -f image2 -framerate 25 -i myplots/myplot_%06d.png -vcodec libx264 -crf 22 video.mp4Check out similar posts by category:
Data Science, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow