<jupyter_start><jupyter_text>--- Safety and Security - Build and Maintain Video IndexThis is an index from timestamp to begin stream cut, end stream cut, and event pointer.The video player uses the event pointer to fetch frames when seeking to a specific frame.---  Import dependencies<jupyter_code>%load_ext autoreload
%autoreload 2
import grpc
import imp
import os
import pravega.grpc_gateway as pravega
import pravega.video as video
imp.reload(video);
import pravega.video as video
from pravega.video import UnindexedStream, OutputStream, IndexedStream, opencv_image_to_mpl, VideoPlayer
imp.reload(video);<jupyter_output><empty_output><jupyter_text>Define Pravega stream parameters<jupyter_code>gateway = os.environ['PRAVEGA_GRPC_GATEWAY_ADDRESS']
scope = 'examples'
stream = 'safety-and-security-video'<jupyter_output><empty_output><jupyter_text>Initialize connection to Pravega GRPC Gateway<jupyter_code>pravega_channel = grpc.insecure_channel(gateway, options=[
        ('grpc.max_receive_message_length', 9*1024*1024),
    ])
pravega_client = pravega.grpc.PravegaGatewayStub(pravega_channel)<jupyter_output><empty_output><jupyter_text>Build timestamp index<jupyter_code>imp.reload(video);
import pravega.video as video
from pravega.video import UnindexedStream, OutputStream, IndexedStream, opencv_image_to_mpl
indexed_stream = IndexedStream(pravega_client, scope, stream)<jupyter_output><empty_output><jupyter_text>Batch index builder (stop at tail)<jupyter_code>%%time
indexed_stream.update_index(force_full=True)<jupyter_output><empty_output><jupyter_text>Show number of records in the index, first and last index records<jupyter_code>len(indexed_stream.index_df)
indexed_stream.index_df.iloc[[0,-1]].T<jupyter_output><empty_output><jupyter_text>Continuous index builder (never stops)<jupyter_code>indexed_stream.continuous_index_builder()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08728046833422033, 'fraction_numerical': 0.006386375731772219, 'mean_word_length': 9.217391304347826, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '170684', 'license': 'Apache-2.0', 'n_tokens_mistral': 642, 'n_tokens_neox': 630, 'n_words': 130, 'path': 'jupyterhub/notebooks/safety_and_security_index_builder.ipynb', 'repo_name': 'vangork/video-samples', 'size': '1879'}