In the code below I am adding an image sequence(multiple images) and then render it as a video.
Scenario 1 - script in Blender text editor: When I run this code in the text editor in Blender it works fine. The video is good. When I open the saved blend file I can see in the sequencer in the N-panel under "Source" I can see that it changes the image frame number when I scroll through the timeline.
Scenario 2 - script in commandline: When I use the same script via commandline - it will create the video but it only shows the first frame of the image sequence. When I check the sequencer "source" again in this case it just shows the same first frame and does not update when scrubbing through the timeline.
Why is this happening? Why does the commandline not properly update the frames when it renders the video? And how can I fix this?
import bpy
from pathlib import Path
dir_path = "D:/test/frames"
img_dir = Path(dir_path)
glob = "*.png"
frame_duration = 24
files = sorted(list(img_dir.glob(glob)))
scene = bpy.context.scene
sed = scene.sequence_editor_create()
seq = sed.sequences
duration = len(files)
fp = files.pop(0)
imstrip = seq.new_image(
name=fp.name,
filepath=str(fp),
frame_start=1,
channel=1,
)
while files:
imstrip.elements.append(files.pop(0).name)
imstrip.frame_final_duration = duration
original_file_path = 'D:/test/'
original_file_name = "test123.blend"
original_full_path = original_file_path + original_file_name
new_file_name = "new_test1234.blend"
new_full_path = original_file_path + new_file_name
bpy.ops.wm.save_as_mainfile(filepath=new_full_path)
render_output_path = "D:/test/output"
render_output_filename = "animation_output"
render_output_format = 'FFMPEG' # Use FFMPEG for mp4 output
bpy.context.scene.render.image_settings.file_format = 'FFMPEG'
bpy.context.scene.render.ffmpeg.format = 'MPEG4'
bpy.context.scene.render.resolution_x = 1920 # Set your desired resolution
bpy.context.scene.render.resolution_y = 1080
bpy.context.scene.render.fps = 30 # Set your desired frame rate
bpy.context.scene.render.filepath = render_output_path + render_output_filename
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = duration
bpy.ops.render.render(animation=True)
bpy.ops.wm.save_as_mainfile(filepath=original_full_path)