-
Notifications
You must be signed in to change notification settings - Fork 4
/
GoProStream.py
57 lines (49 loc) · 1.56 KB
/
GoProStream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
## GoPro Instant Streaming v1.0
##
##
##
## Most of this code was written by KonradIT, see https://github.com/KonradIT/goprowifihack for more.
## I simply added all the necessary steps together so you can just fire this script up and be done with it.
##
## Dependencies:
##
## - Python
## - ffmpeg (for ffplay)
## - GoPro Hero 4
##
## 1. Connect your desktop or laptop to your GoPro via WIFI.
## 2. Run this script.
##
## That's all! When done, press CTRL+C to quit this application.
##
import sys
import socket
import urllib2
import subprocess
from time import sleep
def get_command_msg(id):
return "_GPHD_:%u:%u:%d:%1lf\n" % (0, 0, 2, 0)
UDP_IP = "10.5.5.9"
UDP_PORT = 8554
KEEP_ALIVE_PERIOD = 2500
KEEP_ALIVE_CMD = 2
MESSAGE = get_command_msg(KEEP_ALIVE_CMD)
##
## HTTP GETs the URL that tells the GoPro to start streaming.
##
urllib2.urlopen("http://10.5.5.9/gp/gpControl/execute?p1=gpStream&a1=proto_v2&c1=restart").read()
print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_PORT)
print("message:", MESSAGE)
print("Press ctrl+C to quit this application.\n")
##
## Opens the stream over udp in ffplay. This is a known working configuration by Reddit user hoppjerka:
## https://www.reddit.com/r/gopro/comments/2md8hm/how_to_livestream_from_a_gopro_hero4/cr1b193
##
subprocess.Popen("ffplay -fflags nobuffer -f:v mpegts -probesize 8192 udp://:8554", shell=True)
if sys.version_info.major >= 3:
MESSAGE = bytes(MESSAGE, "utf-8")
while True:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sleep(KEEP_ALIVE_PERIOD/1000)