How to use python to copy video settings from the compositor to the 3D viewport I have 15 short videos, created in Celestia (which will grow to 100+), that I'm using as backgrounds for a music video.

I previously used one long video for the background, but it was inefficient. I'm constantly going back and forth between Celestia and Blender making fine adjustments to short sections.

So I changed my workflow so that I now have short video backgrounds listed in the Compositor, and use a python script to select which video becomes the background for each mini-scene.

Unfortunately, there is no way in Celestia to start video capture frame-accurately, so I have to adjust the offset in Blender each time I make changes to the Celestia backgrounds.

That much is unavoidable, but I would really like to avoid the next step, which is to select the video and adjust the offset AGAIN in the 3D viewport.

By naming the clips and the background, I've managed to change the clip in the 3D view using python e.g. 

bpy.data.images["background_b"].filepath = bpy.data.images["Moon.b1"].filepath


However, I'm stuck with the start frame and offset. The tooltip says

bpy.data.screens["Animation.back"]..frame_start


but that gives a syntax error.

Can anyone tell me the proper syntax to reference the frame_start and frame_offset for the background in a 3D viewport, and an image node in the compositor?
OK!!! I finally worked it out.

In case anyone else needs this, here are examples:

Set-up Variables

clip = 'your.video.filename.mp4'

bg = bpy.data.screens['your.screen'].areas[n].spaces[0].background_images[0]

node_im = bpy.data.scenes['your.scene'].node_tree.nodes[clip]


Copy Video and Properties

bg.image = bpy.data.images[clip]
bg.image_user.frame_start = node_im.frame_start
back_im.image_user.frame_offset = node_im.frame_offset


Notes

Blender automatically assigns e.g. 'your.video.filename.mp4' as the image reference when you load a video into an image node. You can change that if you want, but beware that if you reload the clip, the field will revert to the clip's filename.

Finding 'n' from 'areas[n]' takes a bit of trial and error, especially if you have a complex screen.

for area in bpy.context.window.screen.areas: print(area.type)


outputs a list of the areas of your screen, so at least you can narrow down which are viewports.

After that:

bpy.data.screens["your.screen"].areas[n].spaces[0].background_images[0]


will tell you what,if any, image has been assigned to areas[n]'s background.

I have to say I'm surprised that this hasn't come up before - seems to me that duplicating a video background node in a 3D viewport would be a common need.