pygame save that Stream as video output.


python - how to save pygame camera as video output - Stack Overflow https://stackoverflow.com/questions/28410565/how-to-save-pygame-camera-as-video-output

1down vote

Pygame's multimedia output capabilities are severily limited: It can only save uncompressed BMP images, and there is no way it can save a video format.

You have to make use of another library which to feed image frames, to render the video - or save frame by frame in a folder, numbering the file names in crescent order, and convert the result to a video with an utility later.

This project seens to feature a class to call libffmpeg to encode videos, passing frame by frame in a Python call:https://github.com/kanryu/pipeffmpeg- you will just need a way to convert the pygame Surface object to the expected "frameraw" attribute of ffmpeg.

https://github.com/kanryu/pipeffmpeg/blob/master/pipeffmpeg.py

i´m not at home now but my workarround is take the pygame surface and convert to numpy array and write with opencv to mp4 movie.
python - How to capture pygame screen? - Stack Overflow https://stackoverflow.com/questions/6087484/how-to-capture-pygame-screen
background_image_filename = 'sushiplate.jpg'
sprite_image_filename = 'fugu.png'

import pygame
from pygame.locals import *
from sys import exit

pygame.init()

screen = pygame.display.set_mode((640, 480), 0, 32)

background = pygame.image.load(background_image_filename).convert()
sprite = pygame.image.load(sprite_image_filename).convert_alpha()

clock = pygame.time.Clock()

x, y = 100., 100.
speed_x, speed_y = 133., 170.

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

screen.blit(background, (0, 0))
screen.blit(sprite, (x, y))

time_passed = clock.tick(30)
time_passed_seconds = time_passed / 1000.0

x += speed_x * time_passed_seconds
y += speed_y * time_passed_seconds

# 到达边界则把速度反向
if x > 640 - sprite.get_width():
    speed_x = -speed_x
    x = 640 - sprite.get_width()
elif x < 0:
    speed_x = -speed_x
    x = 0.

if y > 480 - sprite.get_height():
    speed_y = -speed_y
    y = 480 - sprite.get_height()
elif y < 0:
    speed_y = -speed_y
    y = 0

pygame.image.save(screen, "screenshot.png")

pygame.display.update()

  

优质内容筛选与推荐>>
1、Chromimu与JS交互的测试 好东西 谷歌浏览器 学习 研究
2、Dubbo源码分析(1):Spring集成Dubbo
3、Android Fragment 完全解析#
4、Qt4.0.1安装编译好,竟然花了5到6个小时!
5、Linux内核内存管理


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn