作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下 Python 代码制作动画并希望通过 FFmpeg 将其保存为视频(在 PyCharm 中):
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import FFMpegWriter
def func():
for j in range(1, len(t)):
time = j * 0.01
print('time:{:2}'.format(time))
yield time
def animate(data):
time = data
ax2.plot(time, time, **{'marker':'o'})
ax2.set_title('t = {:.2}'.format(time))
return ax2
def init():
ax2.plot(0, 0)
return ax2
dt = 0.01
t = np.arange(0, 50, dt)
fig2 = plt.figure()
ax2 = fig2.add_subplot(111, autoscale_on=True)
ax2.grid()
ani = animation.FuncAnimation(fig2, animate, func, interval=dt*1000, blit=False, init_func=init, repeat=False)
plt.rcParams['animation.ffmpeg_path'] = 'C:\Program Files\\ffmpeg\\bin\\ffmpeg.exe'
writer = FFMpegWriter(fps=15, metadata=dict(artist='Me'), bitrate=1800)
ani.save("movie.mp4", writer=writer)
#plt.show()
time
达到
1.0
,进程停止但它应该在
time
时停止达到
50.0
.下图显示了进程停止时的情况。
The PyCharm Run console
movie.mp4
发现视频在
time
时结束达到 1.0。
.mp4
文件,所以我很困惑其余的帧去哪儿了?
#plt.show()
发现进程在
time
时停止达到 50.0,动画可以正常显示,但仍然只转换了前 100 帧。
最佳答案
我看起来像 FuncAnimation
目前没有记录:
在 animation.py
, 在类(class) FuncAnimation(TimedAnimation):
...
有一行代码:
if self.save_count is None:
# If we're passed in and using the default, set save_count to 100.
self.save_count = 100
100
帧来自。
save_count
是要缓存的帧数:
save_count : int, optional The number of values from frames to cache.
animation.py
中的实现错误。 .
save_count
至
5000
记录 5000 帧:
ani = animation.FuncAnimation(fig2, animate, func, save_count=5000, interval=dt*1000, blit=False, init_func=init, repeat=False)
\
在您的代码中:'C:\\Program Files\\ffmpeg\\bin\\ffmpeg.exe'
关于python - 为什么ffmpeg只能录制动画的前100帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60127671/
有一条(相对)众所周知的 Perl 公理:“只有 Perl 可以解析 Perl”。我想知道 Perl 6 是否仍然如此? 扩大讨论...考虑到 PyPy 最近的更新,我想到了这个问题。 Perl 独特
这是设置。在上一个问题中,我发现我可以通过子组件中的状态传递对象属性,然后使用 componentDidUpdate 获取该对象属性。在这种情况下,状态和属性都称为到达。 这是基本代码... expo
我运行的是 10.5.2 社区版。我已经标记了 源/主要/资源 作为源目录。我可以右键单击并“编译”某些文件,据我所知,这意味着 IDE 将文件复制到与发送类文件的“com.mydomain.pack
我是一名优秀的程序员,十分优秀!