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

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.xdnf.cn/news/16764.html

相关文章:

  • 【qiankun】基于vite的qiankun微前端框架下,子应用的静态资源无法加载的问题
  • 进阶向:YOLOv11模型轻量化
  • 浅谈“压敏电阻”
  • 【Prompt集合】一个学习英文单词更好的提示词
  • 前端开发(HTML,CSS,VUE,JS)从入门到精通!第一天(HTML5)
  • WinForm之CheckBox 控件
  • 微服务架构技巧篇——接口类设计技巧
  • 循环神经网络RNN原理精讲,详细举例!
  • 【笔记】重学单片机(51)
  • 嵌入式硬件中瓷片电容的基本原理与详解
  • 51c自动驾驶~合集12
  • 图像处理中级篇 [2]—— 外观检查 / 伤痕模式的原理与优化设置方法
  • MELF电阻的原理,特性和应用
  • 8,FreeRTOS时间片调度
  • 技术速递|GitHub Copilot for Eclipse 迈出重要一步
  • Leetcode-206.反转链表
  • 当过滤条件不符合最左前缀时,如何有效利用索引? | OceanBase SQL 优化实践
  • 免费语音识别(ASR)服务深度指南​
  • 39.MySQL索引
  • 基于深度学习的医学图像分析:使用YOLOv5实现医学图像目标检测
  • react+ant design怎么样式穿透-tooltip怎么去掉箭头
  • 限流算法详解:固定窗口、滑动窗口、令牌桶与漏桶算法全面对比
  • 实现implements InitializingBean, DisposableBean 有什么用
  • 【2025/07/30】GitHub 今日热门项目
  • arkui 动画曲线
  • 分布式搜索和分析引擎Elasticsearch实战指南
  • SpringBoot 2.7.18 升级 3.4.6
  • duiLib 自定义资源目录
  • C#垃圾回收机制:原理与实践
  • 极致业务弹性 密度性能双管齐下—联想问天 WR5220 G5 服务器测试