diff --git a/db_schema.sql b/db_schema.sql
index 67227e42d561ea7d4b6b821210f6e833aa2ee801..7086fa1400379d43c491c3868dd56d53ad0c6f3d 100644
--- a/db_schema.sql
+++ b/db_schema.sql
@@ -176,7 +176,8 @@ CREATE TABLE IF NOT EXISTS `streams` (
   `visible` INTEGER NOT NULL,
   `lecture_id` INTEGER NOT NULL,
   `description` text NOT NULL,
-  `poster` text NOT NULL
+  `poster` text NOT NULL,
+  `job_id` INTEGER
 );
 CREATE TABLE IF NOT EXISTS `stream_stats` (
 `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
diff --git a/livestreams.py b/livestreams.py
index 626eea2d6f54f099b371ba1342e4fb64922df8a7..42ebc0d20358e3c8cf2046c062bcf1e46b702fb7 100644
--- a/livestreams.py
+++ b/livestreams.py
@@ -7,7 +7,8 @@ def livestream_thumbnail():
 		schedule_job('thumbnail', {'lectureid': str(v['lecture_id']), 'path': v['path']})
 
 @app.route('/internal/streaming/legacy_auth', methods=['GET', 'POST'])
-def streamauth():
+@app.route('/internal/streaming/legacy_auth/<server>', methods=['GET', 'POST'])
+def streamauth(server=None):
 	internal = False
 	for net in config.get('FSMPI_IP_RANGES', []):
 		if ip_address(request.headers['X-Real-IP']) in ip_network(net):
@@ -33,10 +34,25 @@ def streamauth():
 			modify("INSERT INTO streams (handle, active, visible, lecture_id, description, poster) VALUES (?, 0, 1, -1, "", "")", request.values['name'])
 		except:
 			pass
-		modify("UPDATE streams SET active = 1, lecture_id = ? WHERE handle = ?", match['id'], request.values['name'])
+		if server:
+			data = {'src': 'rtmp://%s/live/%s'%(server, request.values['name']),
+				'destbase': 'rtmp://%s/hls/%s'%(server, request.values['name'])}
+			job_id = schedule_job('simple_live_transcode', data, priority=10)
+			modify("UPDATE streams SET active = 1, lecture_id = ?, job_id = ? WHERE handle = ?",
+					match['id'], job_id, request.values['name'])
+		else:
+			modify("UPDATE streams SET active = 1, lecture_id = ? WHERE handle = ?",
+					match['id'], request.values['name'])
 	elif request.values['call'] == 'publish_done':
+		job_id = query('SELECT job_id FROM streams WHERE handle = ?', request.values['name'])[0]['job_id']
 		modify("UPDATE streams SET active = 0 WHERE handle = ?", request.values['name'])
+		if job_id:
+			cancel_job(job_id)
 	else:
 		return 'Bad request', 400
 	return 'OK', 200
 
+@job_handler('simple_live_transcode', state='failed')
+def restart_failed_live_transcode(id, type, data, state, status):
+	restart_job(id)
+