Example #1
0
# Flow of data: VideoStream decodes frame ---> returns VideoFrame function variables
#               which contains other procedures e.g. image/ndarray to convert data further.
# Hence all the frames are decoded individually though returned as VideoFrame function variables.
# Possibility of editing the ffvideo.pyx to return decoded data individually straight away.
################################################################################

import ffvideo

# Possible ideas:
# • Manipulate decode next frame function to allow modify the encoded data which is decoded and returned as
# a VideoFrame attribute.
# • Create blank flv and 'pump' data into it whilst decoding next frame?

# The FLV file we are using resides in the /flvs folder.
file_name = 'flvs/american_football.flv'
video_stream = ffvideo.VideoStream(file_name)

for frame in video_stream:
    # Note: VideoStream frames all return VideoFrame frames where all the data has
    #       been decoded in VideoStream.

    # Need to access VideoStream decoding functions and manipulate it to allow
    # for decoding of a single frame of data.

    # Accessible variables returned (from VideoFrame via VideoStream).
    # print frame.data # Prints RGB output. Please use with some caution; may cause interpreter crash.

    # Prints out the basic information from the VideoFrame that was generated, the data inside is
    # decoded and is in RGB format ready to be converted to an image using the PIL library.
    print "Frame dimensions (w/h/s): ", frame.width, frame.height, frame.size
    print "Frame mode:", frame.mode
Example #2
0
ORIGIN = (200, 180)
WIDTH = 300
FINAL_SIZE = (112, 80)

PADDED_CHAR_WIDTH = 16  # power of 2 to ensure sectors end at a line boundary

FRAME_DATA_BYTES = PADDED_CHAR_WIDTH * FINAL_SIZE[1]
FRAME_BYTES = 512 * int(math.ceil(FRAME_DATA_BYTES / 512.0))
PADDING_BYTES = FRAME_BYTES - FRAME_DATA_BYTES

ASPECT = float(FINAL_SIZE[0]) / FINAL_SIZE[1]
HEIGHT = int(WIDTH / ASPECT)

START_FRAME = 5

vs = ffvideo.VideoStream('clips/matt-ontheradio-centre.m4v')
frames = []
for i, frame in enumerate(vs):
    img = frame.image()
    x0, y0 = ORIGIN
    img = img.crop((x0, y0, x0 + WIDTH, y0 + HEIGHT))
    img = img.resize(FINAL_SIZE)
    img = img.crop((0, 0, PADDED_CHAR_WIDTH * 8, FINAL_SIZE[1]))

    bright = ImageEnhance.Brightness(img)
    img = bright.enhance(3.0)

    contrast = ImageEnhance.Contrast(img)
    img = contrast.enhance(3.0)

    img = img.convert('1')
ORIGIN = (0, 0)
WIDTH = 720
FINAL_SIZE = (128, 96)

PADDED_CHAR_WIDTH = 16  # power of 2 to ensure sectors end at a line boundary

FRAME_DATA_BYTES = PADDED_CHAR_WIDTH * FINAL_SIZE[1]
FRAME_BYTES = 512 * int(math.ceil(FRAME_DATA_BYTES / 512.0))
PADDING_BYTES = FRAME_BYTES - FRAME_DATA_BYTES

ASPECT = float(FINAL_SIZE[0]) / FINAL_SIZE[1]
HEIGHT = int(WIDTH / ASPECT)

START_FRAME = 0

vs = ffvideo.VideoStream('clips/jules-quarterscreen-2.m4v')
frames = []
for i, frame in enumerate(vs):
    img = frame.image()
    x0, y0 = ORIGIN
    img = img.crop((x0, y0, x0 + WIDTH, y0 + HEIGHT))
    img = img.resize(FINAL_SIZE)
    img = img.crop((0, 0, PADDED_CHAR_WIDTH * 8, FINAL_SIZE[1]))

    bright = ImageEnhance.Brightness(img)
    img = bright.enhance(3.0)

    contrast = ImageEnhance.Contrast(img)
    img = contrast.enhance(3.0)

    img = img.transpose(Image.FLIP_LEFT_RIGHT)
Example #4
0
def get_resolution(filename):
    s = ffvideo.VideoStream(filename)
    return s.width, s.height
Example #5
0
ORIGIN = (200, 50)
WIDTH = 320
FINAL_SIZE = (64, 80)

PADDED_CHAR_WIDTH = 8  # power of 2 to ensure sectors end at a line boundary

FRAME_DATA_BYTES = PADDED_CHAR_WIDTH * FINAL_SIZE[1]
FRAME_BYTES = 512 * int(math.ceil(FRAME_DATA_BYTES / 512.0))
PADDING_BYTES = FRAME_BYTES - FRAME_DATA_BYTES

ASPECT = float(FINAL_SIZE[0]) / FINAL_SIZE[1]
HEIGHT = int(WIDTH / ASPECT)

START_FRAME = 15

vs = ffvideo.VideoStream('clips/matt-clap.m4v')
frames = []
for i, frame in enumerate(vs):
	img = frame.image()
	x0, y0 = ORIGIN
	img = img.crop((x0, y0, x0 + WIDTH, y0 + HEIGHT))
	img = img.resize(FINAL_SIZE)
	img = img.crop((0, 0, PADDED_CHAR_WIDTH * 8, FINAL_SIZE[1]))

	bright = ImageEnhance.Brightness(img)
	img = bright.enhance(1.6)

	contrast = ImageEnhance.Contrast(img)
	img = contrast.enhance(1.5)

	img = img.convert('1')
Example #6
0
from optparse import OptionParser

_log = logging.getLogger(__name__)

if __name__ == '__main__':
    parser = OptionParser()

    parser.add_option('--model',
                      default=None,
                      help='File containing the model')
    parser.add_option('--video', default=None, help='The video to process')
    parser.add_option('--output',
                      '-o',
                      default='model.prof',
                      help='Output file for profiling information')

    options, args = parser.parse_args()

    logging.basicConfig(level=logging.INFO)

    _log.info('Loading model')
    mod = model.load_model(options.model)

    _log.info('Opening %s' % options.video)
    video = ffvideo.VideoStream(options.video)

    _log.info('Video is %fs long' % video.duration)
    profile.run("mod.choose_thumbnails(video, n=5)", options.output)

    _log.info('Saved profile to %s' % options.output)