Comments (20)
。。。#1可还行。。。
from live-stream-recorder.
虽然我本来并没有打算支持国内的直播站点,不过因为上游比较牛逼,所以 streamlink 支持的直播站点 基本都能支持(包括斗鱼、熊猫)。你可以试一下这个通用脚本:
#!/bin/bash
# Douyu.tv Live Stream Recorder
if [[ ! -n "$1" ]]; then
echo "usage: $0 live_url [format] [loop|once]"
exit 1
fi
# Record the best format available but not better that 720p by default
FORMAT="${2:-720p,480p,best}"
while true; do
# Monitor live streams of specific channel
while true; do
LOG_PREFIX=$(date +"[%Y-%m-%d %H:%M:%S]")
echo "$LOG_PREFIX Try to get current live stream of $1"
# Get the m3u8 address with streamlink
M3U8_URL=$(streamlink --stream-url "$1" "$FORMAT")
(echo "$M3U8_URL" | grep -q ".m3u8") && break
(echo "$M3U8_URL" | grep -q ".flv") && break
echo "$LOG_PREFIX The stream is not available now."
echo "$LOG_PREFIX Retry after 30 seconds..."
sleep 30
done
# Record using MPEG-2 TS format to avoid broken file caused by interruption
FNAME="douyu_${1}_$(date +"%Y%m%d_%H%M%S").ts"
echo "$LOG_PREFIX Start recording, stream saved to \"$FNAME\"."
echo "$LOG_PREFIX Use command \"tail -f $FNAME.log\" to track recording progress."
# Start recording
ffmpeg -i "$M3U8_URL" -codec copy -f mpegts "$FNAME" > "$FNAME.log" 2>&1
# Exit if we just need to record current stream
LOG_PREFIX=$(date +"[%Y-%m-%d %H:%M:%S]")
echo "$LOG_PREFIX Live stream recording stopped."
[[ "$3" == "once" ]] && break
done
使用方法:
./record.sh "https://www.douyu.com/3614"
./record.sh "https://www.panda.tv/371037"
好用的话再告诉我,我把它添加到 repo 里去。
from live-stream-recorder.
收到,今晚测试一下。
from live-stream-recorder.
问个事,如果要加一个looping 在录制到指定大小或者指定时长后自动分P,直接改造 # Starting recording 哪里的东西就好了吧?
from live-stream-recorder.
我没试过,不过使用 ffmpeg 的 segmenter 应该可行?
from live-stream-recorder.
ffmpeg 自带的 segmenter 有bug,会断流一两秒甚至很久,不完美。不如直接手动stop后秒开另一个。顶多丢几帧。
from live-stream-recorder.
原来如此,学习了。
from live-stream-recorder.
因为另一个app用的这个,有bug还有很多莫名奇妙的放飞自我(不看他分分钟给你来几万个小文件出来)所以现在一直在找替代产品。
from live-stream-recorder.
测试通过~
from live-stream-recorder.
OK
from live-stream-recorder.
剩下的问题就是实现跨平台了。我尝试写个py脚本?
from live-stream-recorder.
哈哈,我个人没有跨平台的需求,所以当初图方便就直接用 Bash 了。
如果你愿意,可以写个 Python 版本的 fork 呀。
from live-stream-recorder.
9042573 已添加。
from live-stream-recorder.
# Start recording
ffmpeg -i "$M3U8_URL" -codec copy -f mpegts "$FNAME"
照着这里修改成python脚本时候报了一个非法参数错误在FNAME参数那里。修改成定值如test.ts就没问题
能帮忙看一下是什么情况吗?
全部脚本代码如下:
#!/usr/bin/python
import os,time,sys
import streamlink
import subprocess
import shlex
# StreamUrl full support website: https://streamlink.github.io/plugin_matrix.html
# e.g. URL = 'https://www.douyu.com/90080'
# 直播地址变量,支持列表请看这里:https://streamlink.github.io/plugin_matrix.html
# 示例:URL = 'https://www.douyu.com/90080'
URL = 'https://www.douyu.com/288016'
# video quality,support worst,480p,720p,best
# 录播质量
Quality = "best"
# record once or loop
# 录制一次直播还是无人监管模式
RecTimes = "once"
# Live Stream Recorder Start
if URL == None :
print('请修改本文件中开始的固定变量来存储录像地址')
print('please change the var URL at top to define the stream URL')
time.sleep(3)
sys.exit()
while True :
# Create log file
Log_Date = time.strftime("%Y_%m_%d_%H:%M:%S", time.localtime())
# Monitor live streams of specific channel
while True :
try :
# Get the M3U8 Dict address with streamlink
M3U8_Dict = streamlink.streams(URL)
# Get the specific quality use variable Quality
M3U8_Key = M3U8_Dict[Quality]
M3U8_Url = M3U8_Key.url
break
except :
print('Monitor live stream now, current not live, please wait...')
print('Retry after 5 seconds...')
time.sleep(5)
# Record using MPEG-2 TS format to avoid broken file caused by interruption
Filename = 'record' + Log_Date + '.ts'
# Start recording
FFmpeg_Cmd = 'ffmpeg -i "' + M3U8_Url + '" -codec copy -f mpegts "' + Filename + '"'
print(FFmpeg_Cmd)
# exque code use shell or cmd
#FFmpeg_Cmd = shlex.split(FFmpeg_Cmd)
print(FFmpeg_Cmd)
Recording_Stream = subprocess.Popen(FFmpeg_Cmd)
# 报存储文件名那里参数错误
# Exit if we just need to record current stream
if RecTimes == "once" : break
from live-stream-recorder.
具体的报错信息是什么呢?打印出来的 FFmpeg_Cmd
是怎样的呢?
from live-stream-recorder.
from live-stream-recorder.
找到毛病。应该是时间参数里面的 : 搞得鬼。那么问题来了,怎么输出带 : 的文件名。2333
from live-stream-recorder.
Windows 系统下文件名是不能包含 :
冒号字符的。
from live-stream-recorder.
也就是win下面无解咯。。。
from live-stream-recorder.
是的,可以考虑使用其他格式作为文件名(比如 record_%Y%m%d_%H%M%S.ts
)。
from live-stream-recorder.
Related Issues (12)
- 百度云网盘挂了 HOT 1
- record_youtube.sh 会快速重试,产生大量视频片段 HOT 2
- YouTube Error 429 HOT 1
- 增加保存路径选项及录制分段
- 录制b站直播的时候会因为没有UA而返回403
- 请教一下 HOT 5
- 希望支持Pixiv sketch的直播,这个画师的直播都是默认没有历史观看的,只能自己存档 HOT 4
- youtube error HOT 2
- 一处信息更新、两处提议
- 似乎是使用不了了? HOT 3
- YouTube忽然更新导致所有现有录播工具损坏 HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from live-stream-recorder.