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()

[((103, 152), 'socket.socket', 'socket.socket', (['socket.AF_INET', 'socket.SOCK_STREAM'], {}), '(socket.AF_INET, socket.SOCK_STREAM)\n', (116, 152), False, 'import socket\n'), ((244, 322), 'cv2.VideoCapture', 'cv2.VideoCapture', (['"""E:/songs/Attention Charlie Puth(GabbarWorld.com) 1080p.mp4"""'], {}), "('E:/songs/Attention Charlie Puth(GabbarWorld.com) 1080p.mp4')\n", (260, 322), False, 'import cv2\n'), ((482, 523), 'cv2.imencode', 'cv2.imencode', (['""".jpg"""', 'frame', 'encode_param'], {}), "('.jpg', frame, encode_param)\n", (494, 523), False, 'import cv2\n'), ((585, 607), 'pickle.dumps', 'pickle.dumps', (['frame', '(0)'], {}), '(frame, 0)\n', (597, 607), False, 'import pickle\n'), ((701, 724), 'struct.pack', 'struct.pack', (['""">L"""', 'size'], {}), "('>L', size)\n", (712, 724), False, 'import struct\n')]