From 9bb0f00970848b97d4f688162819069329433b07 Mon Sep 17 00:00:00 2001 From: Wesnydy Ribeiro Date: Fri, 3 Mar 2017 16:14:19 -0300 Subject: [PATCH] Create watemark function on renderer --- core/renderer.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/core/renderer.py b/core/renderer.py index 8c8f174..326320b 100755 --- a/core/renderer.py +++ b/core/renderer.py @@ -12,6 +12,7 @@ Author: Wesnydy Lima Ribeiro E-Mail: wesnydy@lavid.ufpb.br """ +import ffmpy import json import os import pika @@ -68,7 +69,7 @@ def start_video_creator(id): [ VIDEO_CREATOR, id, - "0", + "1", "30", "20", "25", @@ -92,8 +93,8 @@ def start_ffmpeg(id): Identification of request. """ global ffmpeg, display, libras_video - # logger.info("Starting ffmpeg") - libras_video = os.path.join(PATH_LIBRAS, id + ".mp4") + # 'vl.mp4' sufix to distinguish from video with watermark + libras_video = os.path.join(PATH_LIBRAS, id + "vl.mp4") ffmpeg = subprocess.Popen( [ "ffmpeg", @@ -162,11 +163,14 @@ def run(ch, method, properties, body): """ global worker_available + print ("Rendering...") if worker_available: worker_available = False start_new_thread(send_to_video_creator, (properties.correlation_id, body)) start_video_creator(properties.correlation_id) + final_video = os.path.join(PATH_LIBRAS, properties.correlation_id+".mp4") + watermark(libras_video, final_video, "Vídeo gerado automaticamente pelo usuário") try: filesize = os.path.getsize(libras_video) except: @@ -179,12 +183,45 @@ def run(ch, method, properties, body): clean(properties.correlation_id) worker_available = True + print ("Ok") else: ch.basic_reject(delivery_tag=method.delivery_tag, requeue=True) +# Post processor functions +def watermark(input_video, output_video, text): + fontfile = "/usr/share/fonts/truetype/freefont/FreeSans.ttf" + + filter_graph = ','.join( + [ + "mpdecimate", + "setpts=N/FRAME_RATE/TB", + "drawbox=y=ih-208:color=black@0.4:width=iw:height=48:t=max", + "drawtext=fontfile="+fontfile+":text="+text+":fontcolor=white@0.8:fontsize=36:y=h-200:x=w/10*mod(t\,10)" + ] + ) + + ffmpeg = ffmpy.FFmpeg( + inputs = { input_video: None }, + outputs = { + output_video: [ + "-loglevel", "error", + "-vf", filter_graph, + "-ss", "0.03", + "-c:v", "libx264", + "-movflags", "+faststart", + "-y" + ] + } + ) + try: + ffmpeg.run() + except: + print "FFmpeg retuned with a non-zero exit code. Watermark error." + #Temporary def clean(id): # logger.info("Cleaning screens files") + os.remove(libras_video) path = os.path.join(PATH_FRAMES, id) rmtree(path, ignore_errors=True) -- libgit2 0.21.2