簡體   English   中英

嘗試保存 animation 會出現錯誤:OSError: Error save animation to file(原因:[Errno 22] Invalid argument)

[英]Trying to save an animation gives error: OSError: Error saving animation to file (cause: [Errno 22] Invalid argument)

我正在嘗試保存 animation,但出現錯誤:

OSError:將 animation 保存到文件時出錯(原因:[Errno 22] 無效參數)標准輸出:b''標准錯誤:b''。 將日志記錄級別設置為 DEBUG 可能有助於重新運行。

我已經安裝了 ffmpeg 並且還在我的代碼中添加了它的路徑。 如果我添加print(animation.writers.list()) ,它也會在列表中給出“ffmpeg”,所以我確信我的計算機可以找到正確的文件。

在我的代碼頂部,我有:

import matplotlib.pyplot as plt
plt.rcParams['animation.ffmpeg_path'] = 'C:/FFmpeg/bin/ffmpeg.exe'

在保存 animation 時,我有:

SubplotAnimation_1 = SubplotAnimation(F_vector, eta_atm, Pkid, Tb_sky)
Writer = animation.FFMpegWriter(fps=20, metadata=dict(artist='Me'), extra_args=['--verbose-debug'])
file_string = r'C:/Users/Esmee/Documents/Animations/animation_tryout.mp4'
print(file_string)
SubplotAnimation_1.save(file_string, writer=Writer)

我在字符串前面添加了r ,所以file_string中的/a沒有問題。 文件夾 C:/Users/Esmee/Documents/Animations/ 肯定存在,所以這也不成問題。 我也試過

Writer = animation.writers['ffmpeg']
mywriter = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)

但它也不起作用。

我查看了animation 保存錯誤如何克服這個關鍵字錯誤沒有可用的 Moviewriters ,但它們都沒有解決我的問題。

有誰知道是什么問題? 提前致謝!

最后,下面的代碼起作用了:

Writer = animation.FFMpegWriter(fps=20, metadata=dict(artist='Me'))
file_string = r'C:/Users/Esmee/Documents/Animations/animation_tryout.mp4'
SubplotAnimation_1.save(file_string, writer=Writer)

我認為animation.FFMpegWriter命令中的參數extra_args=['--verbose-debug'] (我從另一個解決方案中得到)導致程序崩潰。 我沒有更改程序頂部的導入語句中的任何內容。

我希望這篇文章可以幫助任何有類似問題的人!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM