import cv2
import io
import socket
import struct
import time
import pickle
import zlib
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('127.0.0.1', 8485))
connection = client_socket.makefile('wb')
cam = cv2.VideoCapture("E:/songs/Attention Charlie Puth(GabbarWorld.com) 1080p.mp4")
cam.set(3, 320)
cam.set(4, 240)
img_counter = 0
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
while True:
    ret, frame = cam.read()
    result, frame = cv2.imencode('.jpg', frame, encode_param)
#    data = zlib.compress(pickle.dumps(frame, 0))
    data = pickle.dumps(frame, 0)
    size = len(data)
    print("{}: {}".format(img_counter, size))
    client_socket.sendall(struct.pack(">L", size) + data)
    img_counter += 1
cam.release()

[(8, 'socket.socket', 'socket.socket', False, 'import socket\n'), (11, 'cv2.VideoCapture', 'cv2.VideoCapture', False, 'import cv2\n'), (18, 'cv2.imencode', 'cv2.imencode', False, 'import cv2\n'), (20, 'pickle.dumps', 'pickle.dumps', False, 'import pickle\n'), (23, 'struct.pack', 'struct.pack', False, 'import struct\n')]