# RTPStreamVideo **Repository Path**: bkbai/RTPStreamVideo ## Basic Information - **Project Name**: RTPStreamVideo - **Description**: rtp服务器和客户端的python实现 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 3 - **Created**: 2019-10-16 - **Last Updated**: 2023-12-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README How to: > 打开Server.py,指定服务器端口地址 * SERVER_PORT = int(9000) > 打开ClientLauncher.py,设置客户端参数 * serverAddr = "localhost" * serverPort = int(9000) * rtpPort = int(9001) * fileName = "video.mjpeg" > 运行Server.py和ClientLauncher.py Function: @ file format Lab`s` proprietary MJPEG(Motion JPEG) format # The server streams a video which has been encoded into a proprietary MJPEG file format # This format stores the video as concatenated JPEG-encoded images # Each image being preceded by a 5-Byte header which indicates the bit size of the image # Server parses the bitstream of MJPEG file to extract the JPEG images # Server sends the images to client at periodic intervals # Client then displays the individual JPEG images sent from server @ Client # Send RTSP commands to server by pressing buttons: > RTSP(Real Time Streaming Protocol) * A network control protocol designed for use in entertainment and communications system to control streaming media servers * Used for establishing and controlling media sessions between end points * Clients issue VCR-style commands e.g play, pause .. to facilitate real-time control of playback of media files from server # Most RTSP servers use the RTP(Real-time Transport Protocol) in conjunction with RTCP(Real-time Control Protocol) for media stream delivery. # Commands > SETUP * Send SETUP request to the server * Insert Transport header(specify port for RTP data socket you just created) * RTP : Real-time Transport Protocol * Read server`s` response * Parse Session header(from response) to get RTSP Session ID * Create a datagram socket for receiving RTP data * Set timeout on socket to 0.5 seconds > PLAY * Send PLAY request * Insert Session header * Use the Session ID(returned in the SETUP response) * Not put the Transport header in the request * Read the Server`s` response > PAUSE * Send PAUSE request * Insert the Session header * Use the Session ID returned in the SETUP response * Not put the Transport header in this request * Read the server`s` response > TEARDOWN * Send TEARDOWN request * Insert the Session header * Use the Session ID returned in the SETUP response * Not put the Transport header in this request * Read the server`s` response *** Must insert CSeq header in every request you send Which starts at 1 and incremented by one for each request you send What we need to implement @ Client.py # SETUP function # PLAY function # PAUSE function # TEARDOWN function @ RtpPacket.py # Set the RTP-version filed(V) = 2 # Set padding(P), extension(X), # of contributing sources(CC), and marker(M) fields => all to 0 # Set payload type field(PT). we use MJPEG type, type number is 26 # Set sequence number.(frameNbr argument) # Set timestamp (via Python time module) # Set source identifier(SSRC)(identifies the server,pick an ID you like) # We have no other contributing sources(field CC == 0), the CSRC-field does not exist. The packet header is 12 bytes