Commit 3cee1828cf22bb210e23b8a2f914588081b95d3a

Authored by Wesnydy Ribeiro
1 parent c488eb8c
Exists in release

Mixer worker release

Showing 2 changed files with 16 additions and 12 deletions   Show diff stats
core/extractor.py
1 -#!/usr/bin/python 1 +#!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 """ 4 """
@@ -44,9 +44,6 @@ logger.addHandler(ch) @@ -44,9 +44,6 @@ logger.addHandler(ch)
44 44
45 manager = PikaManager.PikaManager("150.165.205.10", "test", "test") 45 manager = PikaManager.PikaManager("150.165.205.10", "test", "test")
46 46
47 -#conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))  
48 -#conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))  
49 -  
50 def run(ch, method, properties, body): 47 def run(ch, method, properties, body):
51 """ 48 """
52 Execute the worker. 49 Execute the worker.
@@ -91,7 +88,7 @@ def run(ch, method, properties, body): @@ -91,7 +88,7 @@ def run(ch, method, properties, body):
91 body['pts'] = -1 88 body['pts'] = -1
92 body['index'] = index 89 body['index'] = index
93 #Number of subtitle extracted 90 #Number of subtitle extracted
94 - logger.info(str(index-1) + " Legendas extraídas") 91 + logger.info(str(index-1) + " Legendas extraídas com sucesso")
95 # Clean temporary file 92 # Clean temporary file
96 logger.info("Removendo arquivo temporário") 93 logger.info("Removendo arquivo temporário")
97 os.remove(filename) 94 os.remove(filename)
@@ -26,7 +26,7 @@ from thread import start_new_thread @@ -26,7 +26,7 @@ from thread import start_new_thread
26 from time import sleep 26 from time import sleep
27 from urllib import urlretrieve 27 from urllib import urlretrieve
28 28
29 -PATH_VIDEO="/home/caiomcg/videos/" 29 +PATH_MIXED_VIDEO = os.getenv("VLIBRAS_VIDEO_MIXED")
30 30
31 logger = logging.getLogger('mixer') 31 logger = logging.getLogger('mixer')
32 logger.setLevel(logging.DEBUG) 32 logger.setLevel(logging.DEBUG)
@@ -44,9 +44,6 @@ ch.setFormatter(formatter) @@ -44,9 +44,6 @@ ch.setFormatter(formatter)
44 logger.addHandler(fh) 44 logger.addHandler(fh)
45 logger.addHandler(ch) 45 logger.addHandler(ch)
46 46
47 -#conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))  
48 -#conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))  
49 -  
50 manager = PikaManager.PikaManager("150.165.205.10", "test", "test") 47 manager = PikaManager.PikaManager("150.165.205.10", "test", "test")
51 48
52 def main_video_height(main_video): 49 def main_video_height(main_video):
@@ -180,16 +177,15 @@ def run(ch, method, properties, body): @@ -180,16 +177,15 @@ def run(ch, method, properties, body):
180 # -Vf param 177 # -Vf param
181 filter_graph = ','.join([movie, scale, 'setpts=PTS-STARTPTS', overlay]) 178 filter_graph = ','.join([movie, scale, 'setpts=PTS-STARTPTS', overlay])
182 # Generates the output file path 179 # Generates the output file path
183 - mixed_video = os.path.join(PATH_VIDEO, properties.correlation_id.encode("utf-8")+".mp4") 180 + mixed_video = os.path.join(PATH_MIXED_VIDEO, properties.correlation_id.encode("utf-8")+".mp4")
184 # Mix videos using ffmpeg 181 # Mix videos using ffmpeg
185 - print ("Mixing videos...",) 182 + print ("Mixing videos...")
186 logger.info("Mixando o vídeo original com a janela de libras") 183 logger.info("Mixando o vídeo original com a janela de libras")
187 try: 184 try:
188 call( 185 call(
189 ['ffmpeg', '-v', 'error', '-i', main_video, '-y', '-vf', filter_graph, 186 ['ffmpeg', '-v', 'error', '-i', main_video, '-y', '-vf', filter_graph,
190 '-qscale', '0', '-strict', 'experimental', '-vcodec', 'libx264', 187 '-qscale', '0', '-strict', 'experimental', '-vcodec', 'libx264',
191 '-preset', 'fast', '-r', '30', '-threads', '8', mixed_video], shell=False) 188 '-preset', 'fast', '-r', '30', '-threads', '8', mixed_video], shell=False)
192 - print ("Sucess")  
193 logger.info("Mixagem bem sucedida") 189 logger.info("Mixagem bem sucedida")
194 except OSError as ex: 190 except OSError as ex:
195 logger.error("Mixagem mal sucedida") 191 logger.error("Mixagem mal sucedida")
@@ -205,6 +201,17 @@ def run(ch, method, properties, body): @@ -205,6 +201,17 @@ def run(ch, method, properties, body):
205 manager.send_to_queue("videos", body, properties) 201 manager.send_to_queue("videos", body, properties)
206 print ("Success") 202 print ("Success")
207 203
  204 +def keep_alive(conn_send, conn_receive):
  205 + while True:
  206 + sleep(30)
  207 + try:
  208 + conn_send.process_data_events()
  209 + conn_receive.process_data_events()
  210 + except:
  211 + continue
  212 +
  213 +start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive()))
  214 +
208 # Starts listening 215 # Starts listening
209 print("Mixer listening...") 216 print("Mixer listening...")
210 while True: 217 while True: