I was try this tutorial Stream Webcam Video to PyGame nothing error.. https://www.youtube.com/watch?v=H6ijuSmv5N0
and the script like this..
import pygame, sys
import pygame.camera
from pygame.locals import *
pygame.init()
pygame.camera.init()
screen = pygame.display.set_mode((640, 480))
cam = pygame.camera.Camera("/dev/video0", (640, 480))
cam.start()
while 1:
image = cam.get_image()
screen.blit(image, (0,0))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
#save as video output
sys.exit()
But.. in here I have a problem when I want to save that Stream as video output.. like a mp4, 3gp, avi and other.
In this thread pygame.image.save(img, "image.jpg")
save the output as image.
https://stackoverflow.com/a/20502651/3445802
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.
Pygame can playback video and audio from basic encoded MPEG-1 video files. Movie playback happens in background threads, which makes playback easy to manage. The audio for Movies must have full control over the sound system. This means the pygame.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With