我已经编写了以下代码来通过GRPC传输视频。我正在使用客户端流媒体。客户端通过流以帧的形式发送视频。每个帧都转换为bytes数据类型并进行传输。
但是我的视频播放速度比实际速度慢。如何确保视频以实际速度播放?
imageTest.proto文件
syntax = "proto3";
option java_multiple_files = true;
option objc_class_prefix = "HLW";
// The greeting service definition.
service ImageTest {
// Sends a greeting
rpc Analyse (stream MsgRequest) returns (MsgReply) {}
}
// The request message containing the image.
message MsgRequest {
bytes img = 1;
}
// The response message containing the reply
message MsgReply {
int32 reply = 1;
}
imageTest_server.py
class Greeter(imageTest_pb2_grpc.ImageTestServicer):
def Analyse(self, request_iterator, context):
for req in request_iterator:
frame = np.array(list(req.img))
frame = frame.reshape( (576,704) )
frame = np.array(frame, dtype = np.uint8 )
cv2.imshow('Processed Image', frame)
cv2.waitKey(1)
return imageTest_pb2.MsgReply(reply = cnt )
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
imageTest_pb2_grpc.add_ImageTestServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()
imageTest_client.py
def run():
channel = grpc.insecure_channel('localhost:50051')
stub = imageTest_pb2_grpc.ImageTestStub(channel)
response = stub.Analyse( generateRequests() )
def generateRequests():
videogen = skvideo.io.vreader(URL)
for frame in videogen:
frame = cv2.cvtColor( frame, cv2.COLOR_RGB2GRAY )
frame = bytes(frame)
yield imageTest_pb2.MsgRequest(img= frame)
if __name__ == '__main__':
run()