Jump to content

best flipbook tool from Shelf


tagosaku

Recommended Posts

Hi, I am a senior Houdini artist, but a intermediate about python script.

I am looking for flipbook tool because original one is so inconvenient that every time we need to type file name and saving path. Thus, I wonder if we have the following tool:

1 click a shelf tool.
2 pop up a custom UI.
3 type rez, frame range, and automatically create a default image file name and its path in the UI, based on hip file.   
4 click a button and start playblast and save the image seq.
5 Ideally it has option to save mp4 with ffmpeg. (I have no idea how to plugin this external software!! )

I cannot make such a tool from full scratch, but am capable to customize it.
So far, I found useful article, and can read it but don't know, for instance, I can create a custom UI but don't know how to link those values to actual flipbook parameters.

I really appreciate if you have python shelf scripts for 5 steps, or more hints to create the tool.

 

 

Link to comment
Share on other sites

I can give you hints on how to start this :

import roptoolutils, os, hou, subprocess

# Getting default start and end frame
start_frame, end_frame = hou.playbar.frameRange()

# Gathering values input from the user
button_idx, values = hou.ui.readMultiInput(
    "Set the flipbook options", ("Start Frame", "End Frame", "Width", "Height", "Convert To Video"),
    initial_contents=(str(int(start_frame)), str(int(end_frame)), "1920", "1080", "Yes"),
    title="Flipbook Options",
    buttons=("OK", "Cancel"),
    default_choice=0, close_choice=1,
)

# If the user clicks ok
if button_idx != 1:
  new_start_frame = int(values[0])
  new_end_frame = int(values[1])
  new_width = int(values[2])
  new_height = int(values[3])
  convert_to_video = True if (values[4] == "Yes") else False
  
  # Creating an opengl rop
  ogl_rop = roptoolutils.createRenderNode("opengl")
  
  # optional, if a camera node is selected, set the output camera to be the selected one
  selected_nodes = hou.selectedNodes()
  
  if len(selected_nodes) > 0:
     n = selected_nodes[0]
      
     if n.type().name() == "cam":
      ogl_rop.parm("camera").set(n.path())
  
  # Setting a bunch of parms
  ogl_rop.parm("trange").set(1)
  ogl_rop.parm("f1").set(new_start_frame)
  ogl_rop.parm("f2").set(new_end_frame)
  ogl_rop.parm("tres").set(1)
  ogl_rop.parm("res1").set(new_width)
  ogl_rop.parm("res2").set(new_height)
  
  # Creating the output directory, increments if it already exists
  version = 1
  output_dir = "{}/flipbook/{}".format(hou.getenv("HIP"), "{}".format(version).zfill(3))
  
  while os.path.exists(output_dir):
    version += 1
    output_dir = "{}/flipbook/{}".format(hou.getenv("HIP"), "{}".format(version).zfill(3))
    
  os.makedirs(output_dir)
  
  # Setting the output path of the images
  output_path = "{}/flipbook_img.$F.png".format(output_dir)
  ogl_rop.parm("picture").set(output_path)
  
  # Launch the ogl rop render
  print("Launching opengl render...")
  ogl_rop.parm("execute").pressButton()
  
  # Conversion to video with ffmpeg, assuming ffmpeg is in the PATH
  if convert_to_video:
    print("Converting to video using ffmpeg...")
    subprocess.check_output(["ffmpeg", "-i", output_path.replace("$F", "%d"), "{}/flipbook_video.mp4".format(output_dir)])
else:
  print("Flipbook cancelled...")

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...