提问人:drhode 提问时间:11/17/2023 更新时间:11/17/2023 访问量:8
IPython.display 视频在尝试运行先前绘图的动画时给出无法播放的“空”视频(使用 ffmpeg)
IPython.display Video giving an unplayable "empty" video when trying to run an animation from previous plots (Using ffmpeg)
问:
我正在为一个班级做一个陨石坑模拟项目,在制作视频时遇到了问题。一般项目是让我们模拟一个被陨石坑撞击的表面,直到它变得饱和。但是,代码可以工作,如果我打印出模拟中的每个图形,它将是数千个图形,直到到达 sat,然后我必须手动将它们全部剪辑在一起。为了规避这个问题,我想把所有的图表都放到动画中。然而,我甚至不知道从哪里开始。
作为参考,这里是主代码块:
import matplotlib.pyplot as plt
import numpy as np
import math
import os
import matplotlib.animation as ani
#I have removed the definitions and class implementation for sake of simplicity and space
ani.writers.list()
FFMpegWriter = ani.writers['ffmpeg']
writer = FFMpegWriter(fps = 10)
fig = plt.gcf()
figure = plt.figure()
fig.patch.set_alpha(1.0)
with writer.saving(figure, "sine.mp4", 150):
while sat_counter !=1:#while loop that will introduce new crater each iteration
new_crater = generate_crater()
new_crater.age = sat_counter
random_crater_list.append(new_crater)
i =0
while i < len(random_crater_list):#looping through the crater list and comparing new crater to all others
old_crater = random_crater_list[i]
overlap = square_overlap(old_crater, new_crater)#checks if old crater should be covered/removed by new crater
if overlap == True:
random_crater_list.remove(old_crater)
i=i-1
else:
pass
i=i+1
sat = Saturation(random_crater_list)# checks the saturation of the graph and returns a a number between 0 and 100
if sat > 90:
sat_counter = 1#base condition used to break the while loop
writer.grab_frame()
plot_craters(random_crater_list)
这是最终图形的饱和表面的样子
我尝试使用 IPython.display 视频:
Video("sine.mp4", embed = True, width = 320, height = 320)
但是,这会加载一个无法播放的空视频。空视频
答: 暂无答案
评论