Commit 9bb0f00970848b97d4f688162819069329433b07

Authored by Wesnydy Ribeiro
1 parent af9913c2

Create watemark function on renderer

Showing 1 changed file with 40 additions and 3 deletions   Show diff stats
core/renderer.py
... ... @@ -12,6 +12,7 @@ Author: Wesnydy Lima Ribeiro
12 12 E-Mail: wesnydy@lavid.ufpb.br
13 13 """
14 14  
  15 +import ffmpy
15 16 import json
16 17 import os
17 18 import pika
... ... @@ -68,7 +69,7 @@ def start_video_creator(id):
68 69 [
69 70 VIDEO_CREATOR,
70 71 id,
71   - "0",
  72 + "1",
72 73 "30",
73 74 "20",
74 75 "25",
... ... @@ -92,8 +93,8 @@ def start_ffmpeg(id):
92 93 Identification of request.
93 94 """
94 95 global ffmpeg, display, libras_video
95   - # logger.info("Starting ffmpeg")
96   - libras_video = os.path.join(PATH_LIBRAS, id + ".mp4")
  96 + # 'vl.mp4' sufix to distinguish from video with watermark
  97 + libras_video = os.path.join(PATH_LIBRAS, id + "vl.mp4")
97 98 ffmpeg = subprocess.Popen(
98 99 [
99 100 "ffmpeg",
... ... @@ -162,11 +163,14 @@ def run(ch, method, properties, body):
162 163 """
163 164 global worker_available
164 165  
  166 + print ("Rendering...")
165 167 if worker_available:
166 168 worker_available = False
167 169 start_new_thread(send_to_video_creator, (properties.correlation_id, body))
168 170 start_video_creator(properties.correlation_id)
169 171  
  172 + final_video = os.path.join(PATH_LIBRAS, properties.correlation_id+".mp4")
  173 + watermark(libras_video, final_video, "Vídeo gerado automaticamente pelo usuário")
170 174 try:
171 175 filesize = os.path.getsize(libras_video)
172 176 except:
... ... @@ -179,12 +183,45 @@ def run(ch, method, properties, body):
179 183  
180 184 clean(properties.correlation_id)
181 185 worker_available = True
  186 + print ("Ok")
182 187 else:
183 188 ch.basic_reject(delivery_tag=method.delivery_tag, requeue=True)
184 189  
  190 +# Post processor functions
  191 +def watermark(input_video, output_video, text):
  192 + fontfile = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
  193 +
  194 + filter_graph = ','.join(
  195 + [
  196 + "mpdecimate",
  197 + "setpts=N/FRAME_RATE/TB",
  198 + "drawbox=y=ih-208:color=black@0.4:width=iw:height=48:t=max",
  199 + "drawtext=fontfile="+fontfile+":text="+text+":fontcolor=white@0.8:fontsize=36:y=h-200:x=w/10*mod(t\,10)"
  200 + ]
  201 + )
  202 +
  203 + ffmpeg = ffmpy.FFmpeg(
  204 + inputs = { input_video: None },
  205 + outputs = {
  206 + output_video: [
  207 + "-loglevel", "error",
  208 + "-vf", filter_graph,
  209 + "-ss", "0.03",
  210 + "-c:v", "libx264",
  211 + "-movflags", "+faststart",
  212 + "-y"
  213 + ]
  214 + }
  215 + )
  216 + try:
  217 + ffmpeg.run()
  218 + except:
  219 + print "FFmpeg retuned with a non-zero exit code. Watermark error."
  220 +
185 221 #Temporary
186 222 def clean(id):
187 223 # logger.info("Cleaning screens files")
  224 + os.remove(libras_video)
188 225 path = os.path.join(PATH_FRAMES, id)
189 226 rmtree(path, ignore_errors=True)
190 227  
... ...