vapoursynth/vapoursynth — pull request #111 by splinter98 (2014-10-31 16:07:29+00:00)
Title: Pyframedata

get_read_frame and get_write_frame exports frame data in a Python
friendly way. A nice clean solution to #14 that doesn't require any new dependencies.

Uses Cython's [Typed Memoryviews](http://docs.cython.org/src/userguide/memoryviews.html) which uses [PEP3118](http://legacy.python.org/dev/peps/pep-3118/) buffer protocol. This
allows the functions to be used as inputs into other libraries which
supports the buffer protocol, for example numpy.

Example:
```python
import vapoursynth as vs
import numpy as np
core = vs.get_core()
clip = core.std.BlankClip(color=[128,0,0])
fr = clip.get_frame(0)
mem = fr.get_read_frame(0)
#Access pixel x,y = mem[x,y] or mem[x][y]
p = mem[0,0] #p = 128 mem[0][0] also works
#create numpy array using mem as the data
import numpy as np
np.asarray(mem)

#Make clip Bright Red
def mod_frame(n, f):
fout = f.copy()
data = fout.get_write_frame(0)
for x, row in enumerate(data):
for y, value in enumerate(row):
data[x,y] = 255
return fout

out = core.std.ModifyFrame(clip,clip, selector=mod_frame)
out.set_output()
```