python 进度条在movie中,用于不和谐机器人

pkmbmrz7  于 2024-01-05  发布在  Python
关注(0)|答案(1)|浏览(155)

我试图实现一个不和谐的机器人,发送通过Python导出的视频的进度,Movibooks,不知道如何做到这一点,我使用Cubec def回调来接近它,但它不适合我,因为该函数甚至没有被记录器调用,由于它是Cubec,所以有什么建议吗?

  1. message = None
  2. async def progress_bar(bar, percentage):
  3. print(percentage)
  4. global message
  5. await message.edit(content=f'Loading... {bar} ({percentage}/100)')
  6. class MyBarLogger(ProgressBarLogger):
  7. def __init__(self):
  8. super().__init__()
  9. self.percentage = 0 # Initialize percentage
  10. async def bars_callback(self, bar, attr, value, old_value=None):
  11. # Every time the logger progress is updated, this function is called
  12. self.percentage = (value / self.bars[bar]['total']) * 100
  13. def generate_loading_bar(progress, length=20):
  14. bar_length = int(length * progress)
  15. return '[' + '=' * bar_length + '-' * (length - bar_length) + ']'
  16. total_iterations = 100 # Adjust the total number of iterations as needed
  17. progress = self.percentage / total_iterations
  18. bar = generate_loading_bar(progress)
  19. await progress_bar(bar, self.percentage)
  20. async def run_loading_bar(final_clip, output_path):
  21. logger = MyBarLogger()
  22. with ThreadPoolExecutor() as executor:
  23. loop = asyncio.get_event_loop()
  24. await loop.run_in_executor(executor, lambda: final_clip.write_videofile(output_path, threads=8, codec='libx264', audio_codec='aac', logger=logger))
  25. final_clip.close()
  26. @bot.tree.command(name="generate",
  27. description="",
  28. guild=discord.Object(id=GUILD_ID))
  29. async def generate_motivational_video_command(interaction: discord.Interaction):
  30. global message
  31. message = await interaction.response.send_message('Loading...')
  32. final_clip = VideoFileClip(r'video_path.mp4')
  33. await run_loading_bar(final_clip, 'test.mp4')

字符串

ut6juiuv

ut6juiuv1#

你需要为Logger和nest_logcio的上下文创建一个新的事件循环。对我来说,下面是工作:

  1. nest_asyncio.apply()
  2. async def test():
  3. await aio.sleep(0.1)
  4. logging.info("test")
  5. class MyLogger(ProgressBarLogger):
  6. def __init__(self):
  7. super().__init__()
  8. self.loop = aio.new_event_loop()
  9. def bars_callback(self, bar, attr, value, old_value=None):
  10. self.loop.run_until_complete(test())

字符串
希望有帮助!

展开查看全部

相关问题