即使将 verbose 设置为 False 后,Moviepy 仍会打印进度条

Moviepy still prints a progress bar even after setting `verbose` to `False`

我试图在调用 "write_videofile" 方法时抑制从 moviepy 产生的控制台输出。 我将详细参数传递为 False 无济于事。 它仍然输出类似:

0%| | 0/1624 [00:00<?, ?it/s]
0%| | 8/1624 [00:00<00:20, 77.64it/s]
1%| | 16/1624 [00:00<00:20, 78.31it/s]
2%|1 | 25/1624 [00:00<00:20, 77.90it/s]
2%|2 | 34/1624 [00:00<00:19, 80.80it/s]
3%|2 | 42/1624 [00:00<00:20, 75.91it/s]
3%|3 | 51/1624 [00:00<00:20, 76.07it/s]
4%|3 | 58/1624 [00:00<00:25, 62.44it/s]
4%|4 | 65/1624 [00:00<00:28, 54.77it/s]
4%|4 | 71/1624 [00:01<00:28, 53.63it/s]
5%|4 | 77/1624 [00:01<00:29, 52.69it/s]
5%|5 | 83/1624 [00:01<00:28, 54.06it/s]
5%|5 | 89/1624 [00:01<00:29, 52.80it/s]
6%|5 | 96/1624 [00:01<00:26, 56.95it/s]
6%|6 | 102/1624 [00:01<00:29, 52.38it/s]
7%|6 | 108/1624 [00:01<00:29, 51.74it/s]
...
...
...
100%|#########9| 1621/1624 [00:28<00:00, 51.43it/s]
100%|##########| 1624/1624 [00:28<00:00, 57.75it/s]

有没有办法完全抑制输出?

更新 - 这个答案现在已经过时了。使用 logger=None,或将 logger 设置为 Proglog logger 的自定义子类以获得更细粒度的控制。


是的。

write_vidiofilewrite_audiofile 中有一个名为 progress_bar 的参数。传递 progress_bar=False 以删除进度条。通常你也想传递 verbose=False,就像你已经传递的那样。

为了获得此功能,您可能需要 运行 pip install moviepy --upgrade(如果使用 Python 3,请将 pip 换成 pip3) ,因为这只是刚刚添加(在 moviepy 版本 0.2.3.1 中添加)。

完整用法是这样的:

clip = VideoFileClip("video.mp4")  # Generate a clip
clip.write_videofile("output.mp4")  # Prints progress bar and info
clip.write_videofile("output.mp4", verbose=False)  # Just prints progress bar
clip.write_videofile("output.mp4", verbose=False, progress_bar=False)  # Prints nothing

progress_bar 参数也应该会出现在 write_images_sequence 中,我们目前的目标是版本 0.2.3.2。

现在 2019 年你必须使用 clip.write_videofile("output.mp4", verbose=False, logger=None) 来隐藏进度条,使用 progress_bar=True 会出现如下错误:TypeError: write_audiofile() got an unexpected keyword argument 'progress_bar'

调用 help(clip.write_videofile) 表明:

verbose (deprecated, kept for compatibility) Formerly used for toggling messages on/off. Use logger=None now.

所以你必须设置参数logger=None

对于moviepy==1.0.3

使用

logger=None

现在Moviepy 1.0.3版本如下:

video.audio.write_audiofile(audio_file_path.wav, verbose= False, logger= None)

progress_bar 改为记录器。 如果您不想要进度条,只需将其设置为 None。