Python 如何播放已通过VLC传输的H264 RTSP数据-已通过wireshark转储到文件
背景故事 我的局域网上有一个IP摄像头,我使用VLC(Python 如何播放已通过VLC传输的H264 RTSP数据-已通过wireshark转储到文件,python,wireshark,h.264,rtsp,ip-camera,Python,Wireshark,H.264,Rtsp,Ip Camera,背景故事 我的局域网上有一个IP摄像头,我使用VLC(CTRL+N)连接到它,添加了rtsp://192.168.1.10编解码器信息,提供的编解码器是:编解码器:H264-MPEG-4 AVC(第10部分)(H264),我假设应该将其解析为H264,我也尝试将其解析为MPEG,但失败了,我将其解析为H264正确吗 00000000 24 00 05 A0 80 60 35 85 14 0C 1F DE 43 13 B7 58 00000010 7C 81 9A 26 26 64
CTRL+N
)连接到它,添加了rtsp://192.168.1.10
编解码器信息,提供的编解码器是:编解码器:H264-MPEG-4 AVC(第10部分)(H264)
,我假设应该将其解析为H264,我也尝试将其解析为MPEG,但失败了,我将其解析为H264正确吗
00000000 24 00 05 A0 80 60 35 85 14 0C 1F DE 43 13 B7 58
00000010 7C 81 9A 26 26 64 33 FF 7C 11 99 87 4B 15 FA 06
00000020 06 47 12 C5 6E 39 56 56 82 0D E0 1F 8D 1B 8A A7
magic, channel, length = struct.unpack(">BBH", data)
bits_header_a, bits_header_b, sequence_number, timestamp, ssrc_identifier = struct.unpack(">BBHII", data)
first_byte = "{0:>08s}".format(bin(ord(frame[0]))[2:])
second_byte = "{0:>08s}".format(bin(ord(frame[1]))[2:])
rest_of_data = frame[2:]
# First byte
nal_unit_a = int(first_byte[:3], 2)
fragment_type = int(first_byte[3:], 2)
# Second byte
start_bit = int(second_byte[0], 2)
end_bit = int(second_byte[1], 2)
nal_unit_b = int(second_byte[3:], 2)
# Video data
if 0x1C == fragment_type:
# Middle frame, just add
if 0 == start_bit and 0 == end_bit:
total_data += rest_of_data
continue
# First frame in sequence
elif 1 == start_bit:
print " [*] Found start frame"
nal_unit = chr((nal_unit_a << 5) | nal_unit_b)
if ord(nal_unit) != ( (ord(frame[0]) & 0xe0) | (ord(frame[1]) & 0x1F)):
print "Unexpected"
total_data += "\x00\x00\x00\x01"
total_data += nal_unit
total_data += rest_of_data
continue
# End
elif 0 == start_bit and 1 == end_bit:
print " [*] Found end frame"
total_data += rest_of_data