0
$\begingroup$

Working strictly from a Python script (i.e., no GUI) I need to render four .png files with a voiceover (.wav) for each of them. I know the .png files are loaded; I have been able to render thumbnail .png files from the script. I also know the .wav files are there.

I have done similar projects in the past and am using code which has previously worked.

I have the .blend settings the same as have worked before:

File format set as FFMPEG Video

Color set as RGB

Container set as MPEG4

Video Codec set as H.264

Audio Codec set as AAC

Code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import audioread
import bpy
import os
import sys
#import wave

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

event_ID = sys.argv[8]
event = str(event_ID)
print("event_ID = " + event_ID)

pathout = "/var/www/html/data/event"
    
#Declare arrays#
fileOut =[] * 5
fileOut.append("")
screen = [] * 5
screen.append("/var/www/html/py-scripts/frame1-play.png")
    
#Read in voiceovers#
fileOut.append("/var/www/html/data/event1/event1-1.wav")
fileOut.append("/var/www/html/data/event1/event1-2.wav")
fileOut.append("/var/www/html/data/event1/event1-3.wav")
fileOut.append("/var/www/html/data/event1/event1-4.wav")

#Include frames per voiceover# 
vLen1 = 187
print(fileOut[1] + ' length in frames = ' + str(vLen1))

vLen2 = 254
print(fileOut[2] + ' length in frames = ' + str(vLen2))

vLen3 = 333
print(fileOut[3] + ' length in frames = ' + str(vLen3))

vLen4 = 367
print(fileOut[4] + ' length in frames = ' + str(vLen4))

#change voice overs
s1 = fileOut[1]
frame_start1 = 1
frame_end1 = frame_start1+vLen1+9
sound_strip1 = sequences.new_sound("Sound1", s1, 2, frame_start1)
sound_strip1.frame_final_end = frame_end1
print("frame_start1 = " + str(frame_start1))
print("frame_end1 = " + str(frame_end1))

s2 = fileOut[2]
frame_start2 = frame_end1+1
frame_end2 = frame_start2+vLen2+9
sound_strip2 = sequences.new_sound("Sound2", s2, 2, frame_start2)
sound_strip2.frame_final_end = frame_end2
print("frame_start2 = " + str(frame_start2))
print("frame_end2 = " + str(frame_end2))

s3 = fileOut[3]
frame_start3 = frame_end2+1
frame_end3 = frame_start3+vLen3+9
sound_strip3 = sequences.new_sound("Sound3", s3, 2, frame_start3)
sound_strip3.frame_final_end = frame_end3
print("frame_start3 = " + str(frame_start3))
print("frame_end3 = " + str(frame_end3))

s4 = fileOut[4]
frame_start4 = frame_end3+1
frame_end4 = frame_start4+vLen4+9
sound_strip4 = sequences.new_sound("Sound4", s4, 2, frame_start4)
sound_strip4.frame_final_end = frame_end4
print("frame_start4 = " + str(frame_start4))
print("frame_end4 = " + str(frame_end4))

#Define screens#
for v in range(1, 5):
    scrn = pathout + event + '/event' + event + '-screen' + str(v) + '.png'
    print('screen = ' + scrn)
    screen.append(scrn)

#Change screens#
frame_starti0 = 1
frame_endi0 = 2
image_strip0 = sequences.new_image("Image0", screen[0], 10, frame_starti0)
image_strip0.frame_final_end = frame_endi0
image_strip0.blend_type = 'ALPHA_OVER'

frame_starti1 = frame_start1
frame_endi1 = frame_end1
image_strip1 = sequences.new_image("Image1", screen[1], 6, frame_starti1)
image_strip1.frame_final_end = frame_endi1
image_strip1.blend_type = 'ALPHA_OVER'

frame_starti2 = frame_start2
frame_endi2 = frame_end2
image_strip2 = sequences.new_image("Image2", screen[2], 7, frame_starti2)
image_strip2.frame_final_end = frame_endi2
image_strip2.blend_type = 'ALPHA_OVER'

frame_starti3 = frame_start3
frame_endi3 = frame_end3
image_strip3 = sequences.new_image("Image3", screen[3], 8, frame_starti3)
image_strip3.frame_final_end = frame_endi3
image_strip3.blend_type = 'ALPHA_OVER'

frame_starti4 = frame_start4
frame_endi4 = frame_end4
image_strip4 = sequences.new_image("Image4", screen[4], 9, frame_starti4)
image_strip4.frame_final_end = frame_endi4
image_strip4.blend_type = 'ALPHA_OVER'

renderout = pathout + event + "/vid" + "-" + event + ".m4v"
print("renderout = " + renderout)
thumbout = pathout + event + "/vid" + "-" + event + ".png"
print("thumbout = " + thumbout)

#if not os.path.isfile(thumbout):
bpy.context.scene.frame_current = 1
bpy.context.scene.frame_end = frame_end4-1

bpy.context.scene.render.resolution_x = 350
bpy.context.scene.render.resolution_y = 200
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.context.scene.render.filepath = thumbout
cont1 = bpy.context.area
print("cont1 = " + str(cont1))
bpy.ops.render.render(use_viewport = True, write_still=True)
sequences.remove(image_strip0)
#SEQUENCE_EDITOR
bpy.context.scene.render.resolution_x = 700
bpy.context.scene.render.resolution_y = 400
bpy.context.scene.render.image_settings.file_format = 'FFMPEG'
bpy.context.scene.render.filepath = renderout
cont2 = bpy.context.area
print("cont2 = " + str(cont2))
bpy.ops.render.render(use_viewport = True, animation=True)

sequences.remove(sound_strip1)
sequences.remove(sound_strip2)
sequences.remove(sound_strip3)
sequences.remove(sound_strip4)
sequences.remove(image_strip1)
sequences.remove(image_strip2)
sequences.remove(image_strip3)
sequences.remove(image_strip4)

Error message:

Error: Error initializing video stream
Error: Error initializing video stream
Traceback (most recent call last):
  File "/var/www/html/py-scripts/render-sound.py", line 139, in <module>
    bpy.ops.render.render(use_viewport = True, animation=True)
  File "/usr/share/blender/2.83/scripts/modules/bpy/ops.py", line 201, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Error initializing video stream

The context for rendering the .png is NONE. The context for rendering the .m4v is also NONE.

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.