Created
June 2, 2017 13:50
-
-
Save malefs/41dcdcaaf95c5a9f5b97f9a0741d2a7a to your computer and use it in GitHub Desktop.
Raspberry cameraviewer vlc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
#Howto simple stream Camera | |
#https://picamera.readthedocs.io/en/release-1.13/recipes1.html?highlight=server_socket.accept()%5B0%5D.makefile(%27wb%27) | |
#vlc tcp/h264://my_pi_address:8000/ | |
## on the client | |
#raspivid -w 640 -h 480 -t 60000 -o - | nc my_server 8000 | |
## on the server | |
#$ nc -l 8000 | vlc --demux h264 - | |
import socket | |
import time | |
import picamera | |
camera = picamera.PiCamera() | |
camera.resolution = (640, 480) | |
camera.framerate = 24 | |
camera.vflip=True | |
camera.start_preview() | |
server_socket = socket.socket() | |
server_socket.bind(('0.0.0.0', 8000)) | |
server_socket.listen(0) | |
# Accept a single connection and make a file-like object out of it | |
connection = server_socket.accept()[0].makefile('wb') | |
try: | |
camera.start_recording(connection, format='h264') | |
camera.wait_recording(60) | |
camera.stop_recording() | |
finally: | |
connection.close() | |
server_socket.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment