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

pkmbmrz7  于 4个月前  发布在  Python
关注(0)|答案(1)|浏览(68)

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

message = None

async def progress_bar(bar, percentage):
    print(percentage)
    global message
    await message.edit(content=f'Loading... {bar} ({percentage}/100)')

class MyBarLogger(ProgressBarLogger):
    def __init__(self):
        super().__init__()
        self.percentage = 0  # Initialize percentage

    async def bars_callback(self, bar, attr, value, old_value=None):
        # Every time the logger progress is updated, this function is called
        self.percentage = (value / self.bars[bar]['total']) * 100

        def generate_loading_bar(progress, length=20):
            bar_length = int(length * progress)
            return '[' + '=' * bar_length + '-' * (length - bar_length) + ']'

        total_iterations = 100  # Adjust the total number of iterations as needed
        progress = self.percentage / total_iterations

        bar = generate_loading_bar(progress)

        await progress_bar(bar, self.percentage)

async def run_loading_bar(final_clip, output_path):
    logger = MyBarLogger()

    with ThreadPoolExecutor() as executor:
        loop = asyncio.get_event_loop()
        await loop.run_in_executor(executor, lambda: final_clip.write_videofile(output_path, threads=8, codec='libx264', audio_codec='aac', logger=logger))

    final_clip.close()

@bot.tree.command(name="generate",
                  description="",
                  guild=discord.Object(id=GUILD_ID))
async def generate_motivational_video_command(interaction: discord.Interaction):
    global message

    message = await interaction.response.send_message('Loading...')
    final_clip = VideoFileClip(r'video_path.mp4')
    await run_loading_bar(final_clip, 'test.mp4')

字符串

ut6juiuv

ut6juiuv1#

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

nest_asyncio.apply()

async def test():
    await aio.sleep(0.1)
    logging.info("test")

class MyLogger(ProgressBarLogger):

    def __init__(self):
        super().__init__()
        self.loop = aio.new_event_loop()
    
    def bars_callback(self, bar, attr, value, old_value=None):
        self.loop.run_until_complete(test())

字符串
希望有帮助!

相关问题