<jupyter_start><jupyter_text>Install dependenciesSee [install_dependencies.ipynb](install_dependencies.ipynb).  How to use this Notebook1. Click *Kernel* -> *Restart Kernel and Run All Cells*.  Import dependencies<jupyter_code>%load_ext autoreload
%autoreload 2
from PIL import Image, ImageDraw, ImageFont
import io
import cv2
from matplotlib import pyplot as plt
import numpy as np
import grpc
import imp
import pravega.grpc_gateway as pravega
import pravega.video as video
from pravega.video import UnindexedStream, OutputStream, opencv_image_to_mpl, VideoDataGenerator, generate_image_bytes
imp.reload(video);<jupyter_output><empty_output><jupyter_text>Define Pravega stream parameters<jupyter_code>gateway = 'hop-claudio-ubuntu18-desktop.solarch.lab.emc.com:54672'
scope = 'examples'
#stream = 'generated-video'
stream = 'object-detector-input-video'<jupyter_output><empty_output><jupyter_text>Initialize connection to Pravega GRPC Gateway<jupyter_code>pravega_channel = grpc.insecure_channel(gateway)
pravega_client = pravega.grpc.PravegaGatewayStub(pravega_channel)<jupyter_output><empty_output><jupyter_text>Create data generator<jupyter_code>imp.reload(video);
import pravega.video as video
from pravega.video import UnindexedStream, OutputStream, IndexedStream, opencv_image_to_mpl, VideoDataGenerator
height = int(450)
width = int(height * 16/9)
num_cameras = 1
frames_per_sec = 3.0
width, height
video_data_generator = VideoDataGenerator(
    pravega_client, scope, stream, verbose=False,
    frames_per_sec=num_cameras*frames_per_sec, width=width, height=height, quality=92)
#video_data_generator.truncate_stream()<jupyter_output><empty_output><jupyter_text>View sample generated image<jupyter_code>img_bytes = video_data_generator.generate_image_bytes(frame_number=12345)
serialized_event_len = 500 + int(len(img_bytes) * 4/3)
print('JPEG image size: %d bytes' % len(img_bytes))
print('Serialized event length: %d bytes' % serialized_event_len)
image_bytes_array = np.frombuffer(img_bytes, dtype=np.uint8)
image_array = cv2.imdecode(image_bytes_array, cv2.IMREAD_UNCHANGED)
plt.imshow(opencv_image_to_mpl(image_array));
MB_per_sec = serialized_event_len * video_data_generator.frames_per_sec * 1e-6
serialized_event_len, MB_per_sec<jupyter_output><empty_output><jupyter_text>Generate video frames<jupyter_code>video_data_generator.write_generated_video(num_frames=10000)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08868628263572316, 'fraction_numerical': 0.01699129714048902, 'mean_word_length': 9.72888888888889, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '220028', 'license': 'Apache-2.0', 'n_tokens_mistral': 872, 'n_tokens_neox': 836, 'n_words': 151, 'path': 'jupyterhub/notebooks/video_data_generator.ipynb', 'repo_name': 'vangork/video-samples', 'size': '2413'}