基于python+ffmpeg的视频并发直播压力测试
来源:互联网 发布:淘宝客服售前售后 编辑:程序博客网 时间:2024/06/04 18:05
通过python与ffmpeg结合使用,可生成进行视频点播、直播的压力测试脚本。可支持不同类型的视频流,比如rtmp或者hls形式。
通过如下方式执行脚本:python multiRealPlay.py [rtmp|http] [thread counts] [interval Time]
[rtmp | http]:视频播放的不同形式
[thread counts]:并发线程数
[interval Time]:启动每个线程的间隔时间
#!/usr/bin/python# -*- coding: utf-8 -*- '''Created on 2015年7月22日@author: LiBiao'''import datetime,timeimport threadingimport subprocessimport os, base64import sysimport Queuequeue = Queue.Queue()#需要手动配置的参数#启动序号SLEEP_TIME = 0#直播地址FULL_ADDR = {}#需要手动配置的参数RTMP_ADDR = 'rtmp://192.168.1.208:1935/live/'HTTP_ADDR = 'http://192.168.1.208:80/live'liveID = '100002750' #来自于万视无忧中创建的直播urlKey = 'a1e5c680f7bfc85851de8ab2e63b0a33' #来自于万视无忧安全设置模块liveResCode = '71ac6c06d3' #直播源码#生成MD5值def getMD5_Value(inputdata): try: import hashlib hash = hashlib.md5(inputdata.encode('utf-8')) except ImportError: #for python << 2.5 import md5 hash = md5.new() return hash.hexdigest()#直播地址组装def build_live_addr(): t = time.strftime('%Y%m%d%H%M%S',time.localtime())[2:] data = '%s#%s#%s' %(liveID, t, urlKey) secret = getMD5_Value(data) rtmp_addr = '%s%s?liveID=%s&time=%s&secret=%s' %(RTMP_ADDR, liveResCode, liveID, t, secret) http_addr = '%s/%s/playlist.m3u8?liveID=%s&time=%s&secret=%s' %(HTTP_ADDR, liveResCode, liveID, t, secret) FULL_ADDR['rtmp'] = rtmp_addr FULL_ADDR['http'] = http_addr return FULL_ADDR#获取本机ip地址,用来产生区别于其他机器的数据def get_local_ip(): try: ip = os.popen("ifconfig | grep 'inet addr' | awk '{print $2}'").read() ip = ip[ip.find(':') + 1:ip.find('\n')] except Exception,e: print e return ipclass Video_To_Live(threading.Thread): def __init__(self,queue): threading.Thread.__init__(self) self.queue = queue def run(self): liveAddr = self.queue.get() #print liveAddr try: print liveAddr subprocess.call('./ffmpeg -i \"%s\" -c:v copy -c:a copy -bsf:a aac_adtstoasc -y -f flv -timeout 4000 /dev/null 2>/dev/null' %liveAddr,stdout=subprocess.PIPE,shell=True) except Exception as e: wiriteLog('ERROR',str(e)) self.queue.task_done()if __name__ == "__main__": time.sleep(SLEEP_TIME) parser = argparse.ArgumentParser(description = "Live Play") parser.add_argument('--liveType',action = "store",dest = "liveType",required = False) parser.add_argument('--pnum',action = "store",dest = "pnum",type = int,required = False) parser.add_argument('--itime',action = "store",dest = "itime",required = False) given_args = parser.parse_args() liveType = given_args.liveType threadNum = given_args.pnum intervalTime = given_args.itime print "%d 个 %s 进程开始运行........" %(threadNum, Video_To_Live) for i in xrange(threadNum): videotolive = Video_To_Live(queue) videotolive.setDaemon(True) videotolive.start() for i in xrange(threadNum): if liveType in ["http","rtmp"]: addr = build_live_addr() liveaddr = addr[liveType] queue.put(liveaddr) time.sleep(intervalTime) queue.join() print "进程退出"
0 0
- 基于python+ffmpeg的视频并发直播压力测试
- 基于python+ffmpeg的视频并发直播压力测试
- 视频网站基于srs的直播业务压力测试
- 基于ATS的视频服务器并发压力测试
- iOS平台基于ffmpeg的视频直播技术揭秘
- iOS平台基于ffmpeg的视频直播技术揭秘
- Red5的直播与点播的压力测试(并发数的测试)
- python实现基于UDP的视频直播程序
- 基于live555的视频直播
- 基于live555的视频直播
- 使用ffmpeg直播监控的视频
- 视频直播方面的知识ffmpeg
- 基于ffmpeg的视频截图
- 基于FFMPEG的视频解码
- 基于tcp/udp socket多线程并发实现对二进制协议的压力测试
- 基于live555的实时视频直播
- 基于SRS的视频直播服务器搭建
- iOS直播-基于RTMP的视频推送
- 关于PHP中浏览器禁止Cookie后,Session能使用吗?
- 修改dede后台上传文件大小限制
- height:100%和height:auto的区别
- js 如何获得ckeditor的值
- javascript 全局变量,私有变量。
- 基于python+ffmpeg的视频并发直播压力测试
- Query 允许链接(链式语法)。
- Win7上Git安装及简单配置过程
- JSON 教程
- 怎么把pdf页面转换成图片
- uiview常用方法
- 把 JSON 文本转换为 JavaScript 对象
- java4种内部类
- 在Javascript中 声明时用\"var\"与不用\"var\"的区别