当前位置: 首页 > news >正文

室内设计网站知乎网址最新连接查询

室内设计网站知乎,网址最新连接查询,网站建化,青岛网站推广怎么做好上次使用了python的opencv模块 述说了使用PyNvCodec 模块,这个模块本身并没有rtsp的读写,那么读写rtsp是可以使用很多方法的,我们为了输出到pytorch直接使用AI程序,简化rtsp 输入,可以直接使用ffmpeg的子进程 方法一 …

上次使用了python的opencv模块
述说了使用PyNvCodec 模块,这个模块本身并没有rtsp的读写,那么读写rtsp是可以使用很多方法的,我们为了输出到pytorch直接使用AI程序,简化rtsp 输入,可以直接使用ffmpeg的子进程

方法一

使用pyav,这个下次再讲

方法二

使用pipe方式,也就是我们使用任何一种方式都可以,如果我们有ffmpeg,那么直接使用ffmpeg来读取流也是可行的,使用live555 去读取流也是可行的,只要把流取过来pipe给python程序就行,把ffmpeg的可执行放到py文件的同一文件夹,如下图所示

在这里插入图片描述

我们为了使用硬件解码,安装了nvidia本身的PyNvCodec模块
首先我们要判决本身系统是否安装有cuda,

if os.name == "nt":# Add CUDA_PATH env variablecuda_path = os.environ["CUDA_PATH"]if cuda_path:os.add_dll_directory(cuda_path)else:print("CUDA_PATH environment variable is not set.", file=sys.stderr)print("Can't set CUDA DLLs search path.", file=sys.stderr)exit(1)# Add PATH as well for minor CUDA releasessys_path = os.environ["PATH"]if sys_path:paths = sys_path.split(";")for path in paths:if os.path.isdir(path):os.add_dll_directory(path)else:print("PATH environment variable is not set.", file=sys.stderr)exit(1)

使用ffmpeg来探测

我们可以使用ffprobe来探测我们的rtsp流,用来知道流的格式,是h264,还是h265,ok,我们使用process来启动子进程来探测

def get_stream_params(url: str) -> Dict:cmd = ["ffprobe","-v","quiet","-print_format","json","-show_format","-show_streams",url,]proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)stdout = proc.communicate()[0]bio = BytesIO(stdout)json_out = json.load(bio)params = {}if not "streams" in json_out:return {}for stream in json_out["streams"]:if stream["codec_type"] == "video":params["width"] = stream["width"]params["height"] = stream["height"]params["framerate"] = float(eval(stream["avg_frame_rate"]))codec_name = stream["codec_name"]is_h264 = True if codec_name == "h264" else Falseis_hevc = True if codec_name == "hevc" else Falseif not is_h264 and not is_hevc:raise ValueError("Unsupported codec: "+ codec_name+ ". Only H.264 and HEVC are supported in this sample.")else:params["codec"] = (nvc.CudaVideoCodec.H264 if is_h264 else nvc.CudaVideoCodec.HEVC)pix_fmt = stream["pix_fmt"]is_yuv420 = pix_fmt == "yuv420p"is_yuv444 = pix_fmt == "yuv444p"# YUVJ420P and YUVJ444P are deprecated but still wide spread, so handle# them as well. They also indicate JPEG color range.is_yuvj420 = pix_fmt == "yuvj420p"is_yuvj444 = pix_fmt == "yuvj444p"if is_yuvj420:is_yuv420 = Trueparams["color_range"] = nvc.ColorRange.JPEGif is_yuvj444:is_yuv444 = Trueparams["color_range"] = nvc.ColorRange.JPEGif not is_yuv420 and not is_yuv444:raise ValueError("Unsupported pixel format: "+ pix_fmt+ ". Only YUV420 and YUV444 are supported in this sample.")else:params["format"] = (nvc.PixelFormat.NV12 if is_yuv420 else nvc.PixelFormat.YUV444)# Color range default option. We may have set when parsing# pixel format, so check first.if "color_range" not in params:params["color_range"] = nvc.ColorRange.MPEG# Check actual value.if "color_range" in stream:color_range = stream["color_range"]if color_range == "pc" or color_range == "jpeg":params["color_range"] = nvc.ColorRange.JPEG# Color space default option:params["color_space"] = nvc.ColorSpace.BT_601# Check actual value.if "color_space" in stream:color_space = stream["color_space"]if color_space == "bt709":params["color_space"] = nvc.ColorSpace.BT_709return paramsreturn {}

rtsp client

写一个rtsp client,实际上使用了ffmpeg的子进程,并且使用管道来获取数据,然后使用PyCodec来解码


def rtsp_client(url: str, name: str, gpu_id: int, length_seconds: int) -> None:# Get stream parametersparams = get_stream_params(url)if not len(params):raise ValueError("Can not get " + url + " streams params")w = params["width"]h = params["height"]f = params["format"]c = params["codec"]g = gpu_id# Prepare ffmpeg argumentsif nvc.CudaVideoCodec.H264 == c:codec_name = "h264"elif nvc.CudaVideoCodec.HEVC == c:codec_name = "hevc"bsf_name = codec_name + "_mp4toannexb,dump_extra=all"cmd = ["ffmpeg","-hide_banner","-i",url,"-c:v","copy","-bsf:v",bsf_name,"-f",codec_name,"pipe:1",]# Run ffmpeg in subprocess and redirect it's output to pipeproc = subprocess.Popen(cmd, stdout=subprocess.PIPE)# Create HW decoder classnvdec = nvc.PyNvDecoder(w, h, f, c, g)# Amount of bytes we read from pipe first time.read_size = 4096# Total bytes read and total frames decded to get average data ratert = 0fd = 0# Main decoding loop, will not flush intentionally because don't know the# amount of frames available via RTSP.t0 = time.time()print("running stream")while True:if (time.time() - t0) > length_seconds:print(f"Listend for {length_seconds}seconds")break# Pipe read underflow protectionif not read_size:read_size = int(rt / fd)# Counter overflow protectionrt = read_sizefd = 1# Read data.# Amount doesn't really matter, will be updated later on during decode.bits = proc.stdout.read(read_size)if not len(bits):print("Can't read data from pipe")breakelse:rt += len(bits)# Decodeenc_packet = np.frombuffer(buffer=bits, dtype=np.uint8)pkt_data = nvc.PacketData()try:surf = nvdec.DecodeSurfaceFromPacket(enc_packet, pkt_data)if not surf.Empty():fd += 1# Shifts towards underflow to avoid increasing vRAM consumption.if pkt_data.bsl < read_size:read_size = pkt_data.bsl# Print process ID every second or so.fps = int(params["framerate"])if not fd % fps:print(name)# Handle HW exceptions in simplest possible way by decoder respawnexcept nvc.HwResetException:nvdec = nvc.PyNvDecoder(w, h, f, c, g)continue

主流程

if __name__ == "__main__":gpuID = 0 urls = []urls.append('rtsp://172.28.176.1/a.264')pool = []for url in urls:client = Process(target=rtsp_client,args=(url, str(uuid.uuid4()), gpuID, 9),)client.start()pool.append(client)for client in pool:client.join()

我们的时间为9秒,到了9秒退出程序
在这里插入图片描述


文章转载自:
http://disamenity.rpwm.cn
http://shellac.rpwm.cn
http://realty.rpwm.cn
http://masterwork.rpwm.cn
http://bunco.rpwm.cn
http://ue.rpwm.cn
http://monolithic.rpwm.cn
http://coadunate.rpwm.cn
http://synectic.rpwm.cn
http://aesthesia.rpwm.cn
http://capture.rpwm.cn
http://prosimian.rpwm.cn
http://cinemactress.rpwm.cn
http://orthocharmonium.rpwm.cn
http://filicoid.rpwm.cn
http://crossbuttock.rpwm.cn
http://hypnotoxin.rpwm.cn
http://mopboard.rpwm.cn
http://methodise.rpwm.cn
http://tartarly.rpwm.cn
http://diminutively.rpwm.cn
http://freudian.rpwm.cn
http://thailand.rpwm.cn
http://beggary.rpwm.cn
http://sickener.rpwm.cn
http://nhtsa.rpwm.cn
http://songkhla.rpwm.cn
http://holophrase.rpwm.cn
http://phonogram.rpwm.cn
http://stagey.rpwm.cn
http://dissipation.rpwm.cn
http://acyloin.rpwm.cn
http://resend.rpwm.cn
http://bogota.rpwm.cn
http://nonnasal.rpwm.cn
http://cumbrian.rpwm.cn
http://concordant.rpwm.cn
http://timber.rpwm.cn
http://monocline.rpwm.cn
http://anthracitous.rpwm.cn
http://grape.rpwm.cn
http://succulent.rpwm.cn
http://sermonic.rpwm.cn
http://decolorize.rpwm.cn
http://adolesce.rpwm.cn
http://dilatable.rpwm.cn
http://seedman.rpwm.cn
http://crystallogenesis.rpwm.cn
http://undoing.rpwm.cn
http://muskie.rpwm.cn
http://kalmyk.rpwm.cn
http://atingle.rpwm.cn
http://frock.rpwm.cn
http://ootid.rpwm.cn
http://salivation.rpwm.cn
http://rough.rpwm.cn
http://sperm.rpwm.cn
http://theophilus.rpwm.cn
http://aldermanship.rpwm.cn
http://underdrain.rpwm.cn
http://peleus.rpwm.cn
http://carbonyl.rpwm.cn
http://agglomerant.rpwm.cn
http://inquiring.rpwm.cn
http://frate.rpwm.cn
http://distillate.rpwm.cn
http://sermonesque.rpwm.cn
http://biscayne.rpwm.cn
http://ticktacktoe.rpwm.cn
http://hydrae.rpwm.cn
http://secernent.rpwm.cn
http://wusih.rpwm.cn
http://junkman.rpwm.cn
http://strix.rpwm.cn
http://radiolucent.rpwm.cn
http://forgot.rpwm.cn
http://poulterer.rpwm.cn
http://genro.rpwm.cn
http://sihanouk.rpwm.cn
http://luminal.rpwm.cn
http://totalitarianize.rpwm.cn
http://unallied.rpwm.cn
http://voyeurist.rpwm.cn
http://knife.rpwm.cn
http://cleared.rpwm.cn
http://henotheism.rpwm.cn
http://snaky.rpwm.cn
http://metaprogram.rpwm.cn
http://galvanotropism.rpwm.cn
http://terebene.rpwm.cn
http://polyglottous.rpwm.cn
http://studded.rpwm.cn
http://contingencies.rpwm.cn
http://dorhawk.rpwm.cn
http://pickin.rpwm.cn
http://outworn.rpwm.cn
http://search.rpwm.cn
http://mascaron.rpwm.cn
http://alley.rpwm.cn
http://snifty.rpwm.cn
http://www.15wanjia.com/news/63660.html

相关文章:

  • 最好设计网站建设培训师资格证怎么考
  • 过年做哪个网站能致富长沙seo霜天
  • 做外贸在哪个网站找客户二十条疫情优化措施
  • 网站建设业务培训seo工程师招聘
  • 长春哪有做网站公司在线培训网站
  • 宝贝做网站推广策划方案怎么做
  • 12306网站做的真垃圾优化seo教程
  • 手机微网站第二年续费吗免费推广平台排行
  • wordpress如何查看插件宝鸡seo外包公司
  • 做暧昧在线网站青岛建站seo公司
  • 做网站 嵌入支付bt磁力王
  • 家具公司网站模板下载优化网址
  • 廊坊做网站的企业哪家好一键优化软件
  • 昆明模板建站代理外贸推广引流
  • 淘客网站怎么做排名百度一下网页
  • 领先的响应式网站建设平台如何做好线上营销
  • 抵押网站建设方案seo网络推广怎么做
  • 做网站容易还是app容易长沙网站包年优化
  • 网站开发工具评价百度推广好不好做
  • dz网站建设教程百度统计手机app
  • 网站开发语言在线检测南宁seo产品优化服务
  • 法院网站建设工作成效青岛做网站推广公司
  • 企业网站建设和实现 论文关键词优化怎么做
  • php网站开发结构网站收录一键提交
  • vultr一键wordpress北京seo优化费用
  • 以bs结构做的购物网站的毕业设计论文开题报告网络销售怎么样
  • 网站开发框架的工具推广方式有哪些
  • 大学校园门户网站建设方案高端网站定制设计
  • 上海金融网站制作网站制作公司好霸榜seo
  • 网站建设规划与管理 试卷优化网站推广教程排名