batch headless export (console only)

Discussion related to the 'LuxBlend' Blender 2.4+ python exporter script.

Moderators: Ratow, SATtva, coordinators

batch headless export (console only)

Postby zukazuka » Sun May 15, 2011 2:49 am

Hi, I'm just now upgrading to blender 2.5 and Lux 0.8

I have a headless (no X or graphics mode) server and want to render a blend file.

Want to render a series of frames (all frames between start frame and end frame defined in blend file) from a console script.

The console command I was using for lux Lux 2.4x was:

"blender -b blendfile.blend -P LuxBlend_0.1.py --batch -s 1 -e 1 --scale=50% --haltspp=30 -o. -t./ -l/usr/local/bin/luxconsole --run=true"

Basically telling blender to execute the luxblend script in batch mode...

trying to figure out how to render a blend file from the command line...

Any ideas how to do with blender and luxblend 2.5? Maybe it's already built into blender 2.5?
zukazuka
 
Posts: 382
Joined: Tue Dec 09, 2008 10:01 am
Location: 西安 China

Re: batch headless export (console only)

Postby zukazuka » Sun May 15, 2011 2:52 am

zukazuka
 
Posts: 382
Joined: Tue Dec 09, 2008 10:01 am
Location: 西安 China

Re: batch headless export (console only)

Postby zukazuka » Sun May 15, 2011 3:34 am

I had to modify the instructions in the above thread slightly.

To get it to work I used:

./blender -b test2.blend -o /home/me/Desktop/ -s 1 -e 1 -j 1 -x 1 -E luxrender-0.8.0.rc3 -a

(capitol E instead of lowercase, and had to fully qualify luxrender-0.8.0.rc3 instead of luxrender
zukazuka
 
Posts: 382
Joined: Tue Dec 09, 2008 10:01 am
Location: 西安 China

Re: batch headless export (console only)

Postby zukazuka » Sun May 15, 2011 3:38 am

So my next question - is there any way to specify halt SPP or output resolution from the command line?

So I can have one script to render draft versions of all my files and another script to render high resolution versions without having to reopen and resave all the blend files?
zukazuka
 
Posts: 382
Joined: Tue Dec 09, 2008 10:01 am
Location: 西安 China

Re: batch headless export (console only)

Postby dougal2 » Sun May 15, 2011 8:28 am

zukazuka wrote:So my next question - is there any way to specify halt SPP or output resolution from the command line?

So I can have one script to render draft versions of all my files and another script to render high resolution versions without having to reopen and resave all the blend files?


You can do this if you use the -P <script.py> option, and write a python script to change the halt* parameters within the blend file
Code: Select all
import bpy
bpy.context.scene.luxrender_engine.luxrender_sampler.haltspp = 256
bpy.context.scene.luxrender_engine.luxrender_sampler.halttime = 1800

render_result = bpy.ops.render.render()
if 'FINISHED' in render_result:
    print('Rendered OK')

User avatar
dougal2
Developer
 
Posts: 3075
Joined: Mon Jan 14, 2008 7:21 am

Re: batch headless export (console only)

Postby zukazuka » Sun May 15, 2011 6:46 pm

Hi, I can't seem to find the luxrender_sampler object:

Code: Select all
>>> bpy.context.scene.luxrender_engine.luxrender_sampler.haltspp=100
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'luxrender_engine' object has no attribute 'luxrender_sampler'

>>> dir(bpy.context.scene.luxrender_engine)
['__doc__', '__module__', 'allow_file_embed', 'api_output', 'binary_name', 'bl_rna', 'controls', 'ef_attach_to', 'ef_initialised', 'embed_filedata', 'export_type', 'install_path', 'is_saving_lbm2', 'log_verbosity', 'mesh_type', 'monitor_external', 'name', 'opencl_platform_index', 'partial_ply', 'properties', 'render', 'renderer', 'rna_type', 'threads', 'threads_auto', 'visibility', 'write_files', 'write_lxv']

(blender 2.57b, lux 0.8rc3, ubuntu 10.04 32)
zukazuka
 
Posts: 382
Joined: Tue Dec 09, 2008 10:01 am
Location: 西安 China

Re: batch headless export (console only)

Postby dougal2 » Sun May 15, 2011 7:09 pm

zukazuka wrote:Hi, I can't seem to find the luxrender_sampler object:

Code: Select all
>>> bpy.context.scene.luxrender_engine.luxrender_sampler.haltspp=100
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'luxrender_engine' object has no attribute 'luxrender_sampler'

>>> dir(bpy.context.scene.luxrender_engine)
['__doc__', '__module__', 'allow_file_embed', 'api_output', 'binary_name', 'bl_rna', 'controls', 'ef_attach_to', 'ef_initialised', 'embed_filedata', 'export_type', 'install_path', 'is_saving_lbm2', 'log_verbosity', 'mesh_type', 'monitor_external', 'name', 'opencl_platform_index', 'partial_ply', 'properties', 'render', 'renderer', 'rna_type', 'threads', 'threads_auto', 'visibility', 'write_files', 'write_lxv']

(blender 2.57b, lux 0.8rc3, ubuntu 10.04 32)


oh, sorry, my mistake, I added one object too many:
Code: Select all
bpy.context.scene.luxrender_sampler.haltspp = 256
User avatar
dougal2
Developer
 
Posts: 3075
Joined: Mon Jan 14, 2008 7:21 am

Re: batch headless export (console only)

Postby zukazuka » Sun May 15, 2011 9:36 pm

So I came up with this script as a solution to what I wanted...

Hopefully I'm not reinventing the wheel, the reason why I came up with this script is if you set resolution, haltspp or halttime quality and resolution settings from a python script, then the python script is executing the renderer. If calling blender from the command line, blender is setting the start and end frame and iterating through each frame to do the render. It seemed redundant at first to rewrite a loop to iterate through frames but I didn't see any way around it while maintaining a central location to specify render settings from a script. Also the script needed to force luxconsole mode as some of the blend files may have luxrender GUI mode saved in the settings.

So here's what I came up with so far:
Code: Select all
# --------------------------------------------------------------------------
# Blender 2.5 LuxRender Console Headless Renderer Script
# Version: 0.1
# Author: ZukaZuka
#
# Usage: ./blender -b blendfile.blend -P lux_headless_render.py
#
# This script is designed to render frames from blend file with luxconsole from the command
# line. It allows you to alter parameters such as resolution and quality from one
# place so you can iterate through a series of blend files and have the same output
# settings applied to all of them.
#
# This script will write image output file name and render time to a logfile so you can easily
# keep track of render times for each file frame without having to grep through other
# logs to extract info and match render times to blend files.
# --------------------------------------------------------------------------

import bpy
import os.path
import time
import functools

log_file_name = 'lux_render_times.log'

# must have trailing slash on output path
output_path = './'

bpy.context.scene.render.resolution_x=1920
bpy.context.scene.render.resolution_y=1080
bpy.context.scene.render.resolution_percentage=50

# max number of frames to render, zero for all frames defined by start frame and end frame in blend file
max_frames=1

bpy.context.scene.luxrender_sampler.haltspp=5
bpy.context.scene.luxrender_sampler.halttime=0

# Force console mode
bpy.context.scene.luxrender_engine.binary_name='luxconsole'

# If render server has different path for luxconsole binary
#scene.luxrender_engine.install_path=

def logStatus(s):
   print(s)
   logfile.write(s + "\r\n")

def secondsToStr(t):
   rediv = lambda ll,b : list(divmod(ll[0],b)) + ll[1:]
   return "%d:%02d:%02d.%03d" % tuple(functools.reduce(rediv,[[t*1000,],1000,60,60]))

logfile = open(log_file_name, 'a')

logStatus("haltspp: %d halttime: %d" %(bpy.context.scene.luxrender_sampler.haltspp,bpy.context.scene.luxrender_sampler.halttime))

# File format example: JPEG or PNG
image_file_extension = "PNG"
bpy.context.scene.render.file_format=image_file_extension

frame_start = bpy.context.scene.frame_start
frame_end = bpy.context.scene.frame_end

blend_file = os.path.basename(bpy.context.blend_data.filepath)
filename_without_extension = os.path.splitext(blend_file)[0]

frames_rendered=0

for current_frame in range(frame_start,frame_end):

   if max_frames==0 or frames_rendered<max_frames:
      frames_rendered = frames_rendered+1
      output_filename = '%s.%04d.%s' %(filename_without_extension,current_frame,str.lower(image_file_extension))
      render_start = time.time()

      render_result = bpy.ops.render.render(animation=False, write_still=False, layer="", scene="")
      render_end = time.time()

      print('Frame ' + str(current_frame) + ' rendered OK')

      if 'FINISHED' in render_result:
         full_output_image_path = output_path + output_filename
         bpy.data.images['Render Result'].save_render(filepath=full_output_image_path)
         status_text = '%s Time: %s' %(output_filename, secondsToStr(render_end-render_start))
         logStatus(status_text)
         print("Saved to: " + full_output_image_path)

logfile.close()

It works pretty good on blender 2.57b, lux 0.8rc3, ubuntu 10.04 32bit
zukazuka
 
Posts: 382
Joined: Tue Dec 09, 2008 10:01 am
Location: 西安 China

Re: batch headless export (console only)

Postby zukazuka » Sun May 15, 2011 9:40 pm

Another note, the script creates a logfile with summary of render times.
Before I was doing a grep of the luxconsole output and then had to figure out which times were which files and strip out all the extra information. people kept on asking how long did that one take to render and it was a pain to backtrack and dig it up so a summary logfile is something I have been wanting so it's included in this script.
zukazuka
 
Posts: 382
Joined: Tue Dec 09, 2008 10:01 am
Location: 西安 China


Return to LuxBlend (Blender Exporter)

Who is online

Users browsing this forum: Google Feedfetcher and 0 guests

cron