在分析某款直播app时,发现可以通过wireshark(tshark)等抓取rtmp分析出rtmp://pili-live-rtmp.xxxx.xxxx.com/xxx/qn1575343585371A 的直播流的真实地址,通过rtmpdump录制为flv格式的视频(或者可用vlc media player观看和下载后),尝试用python爬取多个直播的视频,下载到本地时候,出现很多挫折,网上相关资料实在少的可怜,与之相关更是没有。 经过一天的摸坑,找到了pyshark库阅读文档之后,可以抓获rtmp协议并批量获取rtmp的地址,librtmp库的资料也是少的可怜,在阅读官方api,了解这个可以读取rtmp协议的视频流,但是屡次报错raise RTMPError("Failed to start RTMP playback,
import pyshark import librtmp
cap = pyshark.FileCapture('xxxx.pcap',only_summaries=True) cap = pyshark.FileCapture('xxxx.pcap') capture = pyshark.LiveCapture(interface = 'rvi0',bpf_filter='rtmpt') capture.sniff(timeout = 10) for pkt in cap: print(pkt) # 获取视频流真实地址 def rtmp_path(cap): streams_list1= [] for pkt in cap: info = pkt.info if 'play(' in info: streams_list1.append('rtmp://pili-live-rtmp.qiniu.xxxx.xxxx/xxxxx/'+pkt.info[6:22]) streams_list2 = list(set(streams_list1)) print(streams_list2) return(streams_list2,) #视频流解析 def analye(stream_path): conn = librtmp.RTMP(stream_path,live = True) conn.connect() stream = conn.create_stream(writeable = True) packet = conn.read_packet() print(packet.body) data = stream.read(1024*100) if __name__ == '__main__': stream = rtmp_path(cap) # analye(stream) |
共 0 个关于本帖的回复 最后回复于 2019-12-3 19:58