gonzopi

git clone https://git.tarina.org/gonzopi
Log | Files | Refs | README | LICENSE

ytstream.py (914B)


      1 #!/usr/bin/env python3 
      2 import subprocess 
      3 import picamerax
      4 import time 
      5 YOUTUBE="rtmp://a.rtmp.youtube.com/live2/" 
      6 KEY='j1cs-7hac-ygrj-5gaq-3m5b' 
      7 stream_cmd = 'ffmpeg -f h264 -r 25 -i - -itsoffset 5.5 -fflags nobuffer -f alsa -ac 1 -i hw:0 -vcodec copy -acodec libmp3lame -ar 44100 -map 0:0 -map 1:0 -strict experimental -f flv ' + YOUTUBE + KEY 
      8 stream = subprocess.Popen(stream_cmd, shell=True, stdin=subprocess.PIPE) 
      9 camera = picamerax.PiCamera(resolution=(640, 480), framerate=25) 
     10 try: 
     11   now = time.strftime("%Y-%m-%d-%H:%M:%S") 
     12   camera.framerate = 25 
     13   camera.vflip = True 
     14   camera.hflip = True 
     15   camera.start_recording(stream.stdin, format='h264', bitrate = 2000000) 
     16   while True: 
     17      camera.wait_recording(1) 
     18 except KeyboardInterrupt: 
     19      camera.stop_recording() 
     20 finally: 
     21   camera.close() 
     22   stream.stdin.close() 
     23   stream.wait() 
     24   print("Camera safely shut down") 
     25   print("Good bye")