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

python之使用ffmpeg下载直播推流视频rtmp、m3u8协议实时获取时间进度

一、ffmpeg下载

录制函数

    def download_video_by_live_url():playUrl = "rtmp://....."    #推流url:rtmp、m3u8等print(f"已开始录制: playUrl:{playUrl}")now_time = datetime.now().strftime('%Y_%m_%d__%H_%M_%S')output_file =  now_time + ".mp4"output_file = re.sub(r'[\\/:*?"<>|]', '', output_file)ffmpeg_command = ["ffmpeg","-i", playUrl,"-c", "copy","-f", "mp4",output_file]process = subprocess.Popen(ffmpeg_command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True,  # decode bytes to strencoding="utf-8",bufsize=1)time_pattern = re.compile(r'time=(\d+:\d+:\d+\.\d+)')start_time = time.time()try:for line in process.stderr:line = line.strip()if 'time=' in line:match = time_pattern.search(line)if match and time.time() - start_time > 10:start_time = time.time()current_time = match.group(1)print(f" Progress: {current_time}", flush=True)if 'No such stream' in line:print(f"直播结束,结束录制!")breakexcept KeyboardInterrupt:print(f"检测到手动中断,正在优雅停止 ffmpeg...")process.stdin.write('q'.encode("GBK"))process.communicate()process.kill()except Exception as e:print(f"[{current_name}][{nickname}]录制出错: {e}")process.wait()
http://www.dtcms.com/a/307747.html

相关文章:

  • 26.(vue3.x+vite)以pinia为中心的开发模板
  • 【RH134 问答题】第 11 章 管理网络安全
  • Git踩坑
  • Spring面试
  • wpf之ControlTemplate
  • ACL 2024 大模型方向优秀论文:洞察NLP前沿​关键突破!
  • SpringMVC核心原理与实战指南
  • C++游戏开发(2)
  • 解决Android Studio中创建的模拟器第二次无法启动的问题
  • Android Studio怎么显示多排table,打开文件多行显示文件名
  • Android Studio 中Revert Commit、Undo Commit 和 Drop Commit 使用场景
  • 【智能体agent】入门之--1.初体验
  • HighgoDB查询慢SQL和阻塞SQL
  • 微信小程序性能优化与内存管理
  • HTTP 请求头(Request Headers)清单
  • 【13】大恒相机SDK C#开发 —— Fom1中实时处理的8个图像 实时显示在Form2界面的 pictureBox中
  • MySQL 中的聚簇索引和非聚簇索引的区别
  • 淘宝 API HTTP/2 多路复用与连接优化实践:提升商品数据采集吞吐量
  • Ceph、K8s、CSI、PVC、PV 深入详解
  • TTS语音合成|f5-tts语音合成服务器部署,实现http访问
  • 【n8n】如何跟着AI学习n8n【03】:HTTPRequest节点、Webhook节点、SMTP节点、mysql节点
  • 【11】大恒相机SDK C++开发 ——原图像数据IFrameData内存中上下颠倒,怎么裁剪ROI 实时显示在pictureBox中
  • 5G毫米波射频前端设计:从GaN功放到混合信号集成方案
  • 初始sklearn 数据集获取、分类、划分与特征工程
  • mysql笔记02:DML插入、更新、删除数据
  • 【读书笔记】Design Patterns (1994)✅
  • 贝锐蒲公英X4 Pro 5G新品路由器:异地组网+8网口+双频WiFi全都有
  • 大模型005
  • 反射之专题
  • C++:结构体(Structure)