2
$\begingroup$

I have a script that inserts three images (Image1, Image2, Image3) into a blend and then renders the video. It works great. The images show up exactly when and where they are supposed to.

The problem is that I want to be able to run the script as loop, picking up a different set of images each time through the loop. I have that part working just fine except...

The new images (Image1.001 - Image1.00n, Image2.001 - Image2.00n, Image3.001 - Image3.00n) simply overlay each other. Since I am using .png images with transparencies, this is a real problem. To be clear, these are foreground images, not a texture or anything similar.

I have tried everything I can find to delete, remove or replace the original images with the new ones via my script. Nothing I have found and tried has worked. I have to believe there is a way to do this.

Help??? Please.

Here is the relevant part of the code:

import bpy
import csv
import sys

csv_path = sys.argv[5]
file = open(csv_path, 'rU')
reader = csv.reader(file)

fnt = bpy.data.fonts.load('../fonts/Helvetica-Bold.ttf')

s = bpy.context.scene
sed = s.sequence_editor
sequences = sed.sequences

header = next(reader) # 1st line is header`

data = [ ]
for row in reader:
    name0 = row[0]
    pic2 = 'gfx/'+ row[2] # car(s)
    pathout = 'renders/proj003/' + row[4] + '.m4v'
    f = s.objects['Text']
    f.data.body = name0

    frame_start2 = 202
    frame_end2 = 266
    image_strip2 = sequences.new_image("Image2", pic2, 5, frame_start2)  
    image_strip2.frame_final_end = frame_end2
    image_strip2.blend_type = 'ALPHA_OVER'

    bpy.context.scene.render.filepath = pathout
    bpy.ops.render.render(animation=True)

bpy.ops.wm.quit_blender()

Here is what I get with Image1

Here is what I get with Image1.001

Here is what I get with Image1.002

Image1 Image1.001 Image1.002

Note that 'Text' is replaced properly.

$\endgroup$
6
  • 1
    $\begingroup$ This question would benefit from some more information. Could you post a screenshot of the resulting "overlaying"? Does overlay mean, they are at the same position? If yes, how are you setting the position? Could you post your code (or a condensed version of it), which creates/places the images? $\endgroup$
    – Leander
    Dec 28 '18 at 11:06
  • $\begingroup$ Here is a condensed version of the code: $\endgroup$
    – mcgeo52
    Dec 30 '18 at 4:19
  • $\begingroup$ Let's try this again. Here is the first part of the code: $\endgroup$
    – mcgeo52
    Dec 30 '18 at 4:28
  • $\begingroup$ The editor for responding is being a royal PITA. $\endgroup$
    – mcgeo52
    Dec 30 '18 at 4:29
  • $\begingroup$ How the hell do I include code in a comment??? How do I attach screenshots??? $\endgroup$
    – mcgeo52
    Dec 30 '18 at 4:31
1
$\begingroup$

Some options

Result with image strips are overlapping would indicate you are setting start and end frames incorrectly in loop. If the idea is to make an animation of all the added strips, not sure then why the render operator is inside the loop.

If that is how you want it, will need to remove the image strip, replace the image strip, change the image strip data, or batch render one make at a time

Remove the image sequence Not sure if this will work, could be dodgy removing parts of a scene before it is fully rendered. Add code after render op.

 sequences.remove(image_strip2)

Secondly create the strip once, and change image settings, rather than creating new strip each time. This is equivalent of how you are resetting font body. (py console example) added strip with some dummy image, changed directory and element (image) name to a real one.

>>> im = sequences.new_image("Dummy", filepath="/tmp/xxx.png", channel=2, frame_start=3)
>>> im.directory
'/tmp/'

>>> im.directory = '/home/batfinger/Desktop/'
>>> len(im.elements)
1

>>> im.elements[0].filename
'xxx.png'

>>> im.elements[0].filename = "images.jpeg"
>>> im.update() # required???

Thirdly, rather than loop the csv inside the script, could set up a blend file to render a single car make, pass the make string and images to it and run from some shell script.

How to pass command line arguments to a Blender Python script?

For batch scripts there is no need to call the exit operator, as this is default behaviour.

$\endgroup$
2
  • $\begingroup$ For the record, sequences.remove(image_strip2) is exactly what I needed. Thanks. $\endgroup$
    – mcgeo52
    Dec 31 '18 at 7:45
  • $\begingroup$ Good to know. Was my first instinct ... and without bothering to make a test to check.. added the caveat. Would have to choose the Acura for roads around here. $\endgroup$
    – batFINGER
    Dec 31 '18 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.