Import a few elementary helpers (OpenCV, Numeric Python, Matplotlib, scikit-video):

and just a side note: OpenCV is usually the much more efficent and more common soultion to read/write video frames from python, but in this particular case scikit-video works better, because it's able to handle arbitrary ffmpeg-options, which we'll need to work around rec.709 vs. rec.601 color coefficient differnces.

In [149]:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import colors
import skvideo.io
# import cv2

read the first frame of a testclip:

(note: even if we read a 10bit source file, an 8bit converted input will be used, if not otherwise specified. but that's rather avantagous for this simple demonstartion, because for proper handling of 10bit integer data, the matplotlib based image viewing routines would have to look a litte bit more complicated)

In [150]:
TESTFILE = "/srv/archive/test/ebu-10-422.avi"

frame = skvideo.io.vread(TESTFILE, num_frames=1, 
                         outputdict={'-vf': 'scale=in_color_matrix=bt709:out_color_matrix=bt709'})[0]

#cap = cv2.VideoCapture(TESTFILE)
#ret, frame = cap.read()

frame.shape
Out[150]:
(1080, 1920, 3)

show a preview of the frame:

In [151]:
plt.imshow(frame)
plt.show()

crop a little section from the center of the frame:

In [152]:
w, h, channels = frame.shape
d = 5 ## distance from center
sect = frame[w//2-d:w//2+d, h//2-d:h//2+d,:]

plt.imshow(sect)
plt.show()

plot and print the actual RGB values for the uppermost line of pixels.

In [153]:
for chan, name in enumerate(['red','green','blue']):
    plt.plot(sect[0,:,chan], drawstyle='steps-mid', color=name)
plt.show()
In [154]:
for chan, name in enumerate(['red','green','blue']):
    print(name + ':')
    print(sect[:,:,chan])
red:
[[  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]
 [  0   0   0   0   0 203 203 203 203 203]]
green:
[[203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]
 [203 203 203 203 203   0   0   0   0   0]]
blue:
[[  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]
 [  0   0   0   0   0 204 204 204 204 204]]