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, 16, 8, 65), 'socket.socket', 'socket.socket', ({(8, 30, 8, 44): 'socket.AF_INET', (8, 46, 8, 64): 'socket.SOCK_STREAM'}, {}), '(socket.AF_INET, socket.SOCK_STREAM)', False, 'import socket\n'), ((11, 6, 11, 84), 'cv2.VideoCapture', 'cv2.VideoCapture', ({(11, 23, 11, 83): '"""E:/songs/Attention Charlie Puth(GabbarWorld.com) 1080p.mp4"""'}, {}), "('E:/songs/Attention Charlie Puth(GabbarWorld.com) 1080p.mp4')", False, 'import cv2\n'), ((18, 20, 18, 61), 'cv2.imencode', 'cv2.imencode', ({(18, 33, 18, 39): '""".jpg"""', (18, 41, 18, 46): 'frame', (18, 48, 18, 60): 'encode_param'}, {}), "('.jpg', frame, encode_param)", False, 'import cv2\n'), ((20, 11, 20, 33), 'pickle.dumps', 'pickle.dumps', ({(20, 24, 20, 29): 'frame', (20, 31, 20, 32): '0'}, {}), '(frame, 0)', False, 'import pickle\n'), ((23, 26, 23, 49), 'struct.pack', 'struct.pack', ({(23, 38, 23, 42): '""">L"""', (23, 44, 23, 48): 'size'}, {}), "('>L', size)", False, 'import struct\n')]