How to get particular frame of video "image"?

import bpy
img = bpy.data.images.load(‘H:\Video_Edit.mov’)
pixels = list(img.pixels)

This returns pixels of first frame. How to change number of frame returned?

Have you tried changing to the current frame in the timeline? (you may have to set the movie to Auto Refresh first)

Or export the movie as an image sequence and load the single image directly.

I tried to dig deeper into subject. All the following is pure speculation based on observations and what I can get from API manual:

It seems there is a texture object, which has ImageUser object, which has Image object.

The problem is that python seems to be able to access only the pixels of the Image object directly, thus bypassing mapping and other options of ImageUser such as frame offset. Though using frame offset would be still a workaround as I suspect, the Image object does have possibility to return particular frame number pixels internally, but for some reason it seems it didn’t made to the Python API.

And yes, Auto Refresh is an option of image user, and timeline seems not to affect anything.

If it is really so and image object has no way of returning frame, it arguably could be considered a bug.

On the other hand - there could by some creepy workaround, like using UV/Image Viewer with it’s imageUser, or the Clip Editor, and read pixels from their “canvas”, but how to access them is another research for me :slight_smile:

When in doubt report it as a bug anyway. The devs might have solution that forum users are unaware of. Just provide an example BLEND file for your bug report.

Report was rejected as known issue. https://projects.blender.org/tracker/index.php?func=detail&aid=37216&group_id=9&atid=498

Yey! I Found it. A dirty workaround:

import bpy

frameStart = 1
frameEnd = 155
frameStep = 50
viewer_area = None
viewer_space = None

for area_search in bpy.context.screen.areas:
if viewer_area == None and area_search.type == ‘IMAGE_EDITOR’:
viewer_area = area_search
break

if viewer_area == None:
viewer_area = bpy.context.screen.areas[0]
viewer_area.type = “IMAGE_EDITOR”

for space in viewer_area.spaces:
if space.type == “IMAGE_EDITOR”:
viewer_space = space

path = ‘H:\Data\_blender\Fluid\Video_Edit.mov’
img = bpy.data.images.load(path)
w = img.size[0]
h = img.size[1]
viewer_space.image = img

frame = 1
for frame in range(1, 100, 10):
viewer_space.image_user.frame_offset = frame
#switch back and forth to force refresh
viewer_space.draw_channels = ‘COLOR_ALPHA’
viewer_space.draw_channels = ‘COLOR’
pixels = list(viewer_space.image.pixels)
tmp = bpy.data.images.new(name=“sample”+str(frame), width=w, height=h, alpha=False, float_buffer=False)
tmp.pixels = pixels

img.user_clear()
bpy.data.images.remove(img)