I'm trying to insert subtitles in Blender the "oldschool" way, because I want to have a precise control over the text properties, such as the font, an evolving location, etc. I tried to follow this workaround:

Can I (easily) add text to a movie?

and wrote a Python script out of it. But for some reason it doesn't work as expected when I then add a clip and try to render. Any idea why?

Many thanks,

import bpy
import math
import random

str_text = "Waiting for the sun"

for i in range(0, len(bpy.data.objects)):
    bpy.data.objects[i].select = True

bpy.ops.object.camera_add(location = (0, 0, 10))
bpy.ops.object.text_add(location=(0, 0, 0))
text_obj = bpy.context.object
text_obj.data.align = 'CENTER'
text_obj.data.body = "I'm awesome"
mat = bpy.data.materials.new('MAT')
mat.use_shadeless = True
text_obj.active_material = mat

bpy.context.scene.game_settings.material_mode = 'GLSL'
bpy.context.scene.render.alpha_mode = 'TRANSPARENT'

old_type = bpy.context.area.type
bpy.context.area.type = 'SEQUENCE_EDITOR'
bpy.ops.sequencer.scene_strip_add(scene = "Scene")
bpy.context.scene.sequence_editor.sequences_all["Scene"].blend_type = 'ALPHA_OVER'
bpy.context.scene.render.sequencer_gl_preview = 'TEXTURED'
bpy.context.area.type = old_type

EDIT: There's something wrong when I do the script approach. When I use the manual approach everything goes well, I can see the text over my video clip in the VSE, but it doesn't appear at all in the script case. Something strange happens to my text and my scene options, see screenshots. What could explain this?

Manual: Manual:

Script: Script:

  • $\begingroup$ One pic is in solid mode 3D View. One pic is in wireframe. See the icon to the [right] of the word [Object Mode]. Showing the font settings would be helpful. $\endgroup$ Jan 12 '16 at 16:46
  • 1
    $\begingroup$ Feel free to check this : github.com/Nikos-Prinios/blender-sub It might help. Good luck! $\endgroup$
    – Nikos_VSE
    Jan 23 '16 at 11:52

Simply create your required text objects by hand. Use Python to change the text data of the object and its location.

Simpler would be better. Create objects manually in your case today. When objects are placed in a group it is convenient. Group copying can easily be done in logarithmic steps. Double. Double. 2,4,8,16,32. In Python one can interate over the members of the group.

I assume you are not trying to create some [ornate] user interface.

I suggest you create no new text objects via Python or cameras via Python at all. Text objects set to empty string == "" will not be rendered. I suggest you do not interact with the VSE editor by Python at all.

At least [copy] a finished text object, or its properties. It has the visual properties appearing in Blender 3D View. Creating a new one from scratch, without huge overhead, gives you no visualization. Since the render state of any object can be animated, visibility of the text need not determine its lifetime.

Thus you keep the Blender interface for attribute assignment. Render out your text sequence as transparent .PNG file types. Then import your .PNG sequence as a normal strip in the VSE manually. You stated [old school]. I know you will have more flexibility using the Blender 3D View [text] interface and [VSE] interface already present.

Know there are probably ten scripts or nodes that will change your text. Here at BSE or elsewhere with no monetary cost. So you may need to write no Python. Of course some Python is fun. Of course if you are particular, none will achieve your most exotic cases. Of course in the lastest version of Blender the VSE has simple subtitling.

At a Blender Python level many users who need to change something with a frame change use

frame_change = bpy.app.handlers.frame_change_post

The only part of the Python I would keep are a few lines. Below is your software edited as a new starting point. Pseudo Code. No evaluation performed.

import bpy
import math
import random

str_text = ["Some Text","More Text"]
font_ob.data.body = str_text[0]
font_ob.location = (1.0, 2.0, 0.0)
  • 1
    $\begingroup$ I want to do this kind of operation on a lot of different text objects, so I need to script it, I don't want to go through creating each by hand... $\endgroup$
    – G Viaud
    Jan 12 '16 at 14:59
  • $\begingroup$ [This kind of operation] is the part I do not understand. What is the maximum number of text objects on visible render at any time? 32 or 3200? What determines text location and content? Artistry or measurements? If you describe that, other people can think about what will help. $\endgroup$ Jan 12 '16 at 16:17
  • $\begingroup$ Maybe I wasn't clear enough, sorry. My aim is to add a sentence of several words (5-10) every, say, 3 seconds, over 5 minutes for instance. That means approximately 100 occurrences of such texts for which I want to be able to: (i) use a specific font, dynamically (ii) make the size of the text grow and (iii) change its location. $\endgroup$
    – G Viaud
    Jan 12 '16 at 16:28
  • $\begingroup$ Are the sentences growing or being replaced?. Please know if we have lots of comments that the system will suggest we have some discussion in some chat window. $\endgroup$ Jan 12 '16 at 16:33
  • $\begingroup$ Being replaced. $\endgroup$
    – G Viaud
    Jan 12 '16 at 16:38

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.