gpt4 book ai didi

ffmpeg - 如何精确地达到每秒 25 张图像。游戏

转载 作者:行者123 更新时间:2023-12-04 23:01:24 28 4
gpt4 key购买 nike

我拍摄的每一帧音频都会读取它们并将它们转换为视觉方式。然后我拍照。
我的问题是以下方法每秒拍摄不同数量的图像。因此,当我将图像转换为视频时,它会比作为输入播放的音频短(短约 5-10 秒)。

FPS = 25
clock = pygame.time.Clock()

pygame.mixer.music.load(filename)
pygame.mixer.music.play(0)

running = True
while running and pygame.mixer.music.get_busy():

print(clock.get_fps()) #output 21 - 25 FPS

t = pygame.time.get_ticks()
deltaTime = (t - getTicksLastFrame) / 1000.0
getTicksLastFrame = t

for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

screen.fill((0, 0, 0))

for b in bars:
b.update(deltaTime, get_decibel(pygame.mixer.music.get_pos() / 1000.0, b.freq))
b.render(screen)

pygame.display.flip()

pygame.display.update()
video.make_png(screen)
clock.tick(FPS)
我正在考虑放慢音频速度,所以我只会拍摄(每秒 12 张以上的图像),但这种方法也行不通,因为 FPS 上限不稳定。
我正在考虑的另一种方法是使用 FFmpeg 以某种方式将视频拉伸(stretch)到音频的长度......但是,我相信应该有一个更优雅的解决方案。
非常感谢任何建议!

最佳答案

使用 tick_busy_loop() 而不是 tick() .clock.tick(FPS)

clock.tick_busy_loop(FPS)
tick() :

[...] this function uses SDL_Delay function which is not accurate on every platform, but does not use much CPU.


tick_busy_loop() :

[...] this function uses pygame.time.delay() which uses lots of CPU in a busy loop to make sure that timing is more accurate.

关于ffmpeg - 如何精确地达到每秒 25 张图像。游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69183005/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com