Commit 63807aa9a7dc2c765ed51f341daaff88978ea2e7
1 parent
1bb0e8b5
Exists in
master
Trata exceção quando o mesmo usuário requisitar a renderização do sinal duas vezes
Showing
1 changed file
with
28 additions
and
1 deletions
Show diff stats
util.py
@@ -6,8 +6,10 @@ import json | @@ -6,8 +6,10 @@ import json | ||
6 | import math | 6 | import math |
7 | import os | 7 | import os |
8 | import pyutil | 8 | import pyutil |
9 | +import shutil | ||
9 | import sys | 10 | import sys |
10 | import subprocess | 11 | import subprocess |
12 | +import tempfile | ||
11 | from bmesh_collision import bmesh_check_intersect_objects | 13 | from bmesh_collision import bmesh_check_intersect_objects |
12 | 14 | ||
13 | armature = bpy.context.scene.objects.get('Armature.001') | 15 | armature = bpy.context.scene.objects.get('Armature.001') |
@@ -231,6 +233,30 @@ def configure_output(): | @@ -231,6 +233,30 @@ def configure_output(): | ||
231 | return | 233 | return |
232 | 234 | ||
233 | def render_sign(user_id = "", sinal = "", frame_final = bpy.context.scene.frame_end): | 235 | def render_sign(user_id = "", sinal = "", frame_final = bpy.context.scene.frame_end): |
236 | + bpy.context.scene.frame_end = 5 #frame_final | ||
237 | + bpy.context.scene.render.filepath = tempfile.NamedTemporaryFile().name | ||
238 | + pyutil.log("Render Video Frames: %i" % (frame_final)) | ||
239 | + temp_filename = ("%s%0.4i-%0.4i" % (bpy.context.scene.render.filepath, bpy.context.scene.frame_start, bpy.context.scene.frame_end)) | ||
240 | + temp_filename_mp4 = temp_filename + ".mp4" | ||
241 | + temp_filename_webm = temp_filename + ".webm" | ||
242 | + pyutil.log("Temporary File: %s" % (temp_filename_mp4)) | ||
243 | + bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") | ||
244 | + if pyutil.file_exists(temp_filename_mp4): | ||
245 | + getcwd = os.path.dirname(os.path.abspath(__file__)) | ||
246 | + user_directory = os.path.join(getcwd, "users", user_id) | ||
247 | + if (make_dir(user_directory)): | ||
248 | + pyutil.log("user dir created: %s" % (user_directory)) | ||
249 | + subprocess.call(["avconv", "-loglevel", "0", "-y", "-i", temp_filename_mp4, "-r", "24", "-vcodec", "libvpx", temp_filename_webm]) | ||
250 | + subprocess.call(["rm", "-f", temp_filename_mp4]) | ||
251 | + if pyutil.file_exists(temp_filename_webm): | ||
252 | + user_full_path_webm = os.path.join(user_directory, sinal + ".webm") | ||
253 | + try: | ||
254 | + shutil.copy(temp_filename_webm, user_full_path_webm) | ||
255 | + subprocess.call(["rm", "-f", temp_filename_webm]) | ||
256 | + except: | ||
257 | + pyutil.log("error while copy the video '%s' to ''" % (temp_filename_webm, user_full_path_webm)) | ||
258 | + bpy.ops.wm.quit_blender() | ||
259 | + """ | ||
234 | getcwd = os.path.dirname(os.path.abspath(__file__)) | 260 | getcwd = os.path.dirname(os.path.abspath(__file__)) |
235 | base_path = os.path.join(getcwd, "users", user_id, sinal) | 261 | base_path = os.path.join(getcwd, "users", user_id, sinal) |
236 | bpy.context.scene.render.filepath = base_path + "_" | 262 | bpy.context.scene.render.filepath = base_path + "_" |
@@ -239,9 +265,10 @@ def render_sign(user_id = "", sinal = "", frame_final = bpy.context.scene.frame_ | @@ -239,9 +265,10 @@ def render_sign(user_id = "", sinal = "", frame_final = bpy.context.scene.frame_ | ||
239 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") | 265 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") |
240 | renamed_video = pyutil.file_rename("%s%0.4i-%0.4i.mp4" % (bpy.context.scene.render.filepath, bpy.context.scene.frame_start, bpy.context.scene.frame_end)) | 266 | renamed_video = pyutil.file_rename("%s%0.4i-%0.4i.mp4" % (bpy.context.scene.render.filepath, bpy.context.scene.frame_start, bpy.context.scene.frame_end)) |
241 | # Converte arquivo .mp4 para .webm | 267 | # Converte arquivo .mp4 para .webm |
242 | - subprocess.call(["ffmpeg", "-loglevel", "0", "-y", "-i", renamed_video, "-r", "24", "-vcodec", "libvpx", base_path + ".webm"]) | 268 | + subprocess.call(["avconv", "-loglevel", "0", "-y", "-i", renamed_video, "-r", "24", "-vcodec", "libvpx", base_path + ".webm"]) |
243 | subprocess.call(["rm", renamed_video]) | 269 | subprocess.call(["rm", renamed_video]) |
244 | bpy.ops.wm.quit_blender() | 270 | bpy.ops.wm.quit_blender() |
271 | + """ | ||
245 | return | 272 | return |
246 | 273 | ||
247 | def make_dir(directory): | 274 | def make_dir(directory): |