Skip to content

Commit

Permalink
新增自定义输出目录配置
Browse files Browse the repository at this point in the history
  • Loading branch information
auqhjjqdo committed Jun 15, 2023
1 parent add15c7 commit fd04184
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

## 简介

一款直播录制脚本,基于强大的[Streamlink](https://streamlink.github.io)
实现多平台直播源录制,通过挖掘直播平台官方API以轮询方式实现直播开播检测,致力于用最少的代码实现最多的功能
一款直播录制脚本,基于强大的[Streamlink](https://streamlink.github.io)实现多平台直播源录制,通过挖掘直播平台官方API以轮询方式实现直播开播检测,致力于用最少的代码实现最多的功能

## 已支持平台

Expand Down Expand Up @@ -87,6 +86,14 @@ python3 -m main.py

无需代理时去除引号填写`null`或删除该字段即可

### 输出目录配置

`output`字段为录制文件输出后保存的目录路径,非必填字段(请勿填写空字符串),默认输出到运行目录的`output`文件夹

路径分隔符请使用`/`,防止出现转义导致的不兼容问题

支持相对路径和绝对路径,例如`output/video``/tmp/output``D:/output`

### 直播录制配置

按照示例修改`user`列表,注意逗号、引号和缩进
Expand Down Expand Up @@ -128,8 +135,6 @@ YouTube的频道ID一般是由`UC`开头的一段字符,由于YouTube可以自

## 输出文件

默认将直播录制文件输出到运行目录的`output`文件夹

输出文件会在录制结束后使用ffmpeg封装为配置文件自定义的输出格式,音视频编码为直播平台直播流默认(一般视频编码为`H.264`,音频编码为`AAC`),录制清晰度为最高画质,封装结束后自动删除原始录制文件,输出格式为空或未填写时不进行封装

输出文件名命名格式为`[年.月.日 时.分.秒][平台][主播名]直播标题.格式`,日期时区为系统默认时区
1 change: 1 addition & 0 deletions config.sample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"proxy": "http://127.0.0.1:7890",
"output": "output",
"user": [
{
"platform": "Bilibili",
Expand Down
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class LiveRecoder:
def __init__(self, config: dict, user: dict):
self.proxy = config.get('proxy')
self.output = config.get('output', 'output')

self.id = user['id']
platform = user['platform']
Expand Down Expand Up @@ -141,7 +142,7 @@ def run_record(self, stream: Union[StreamIO, HTTPStream], url, title, format):

def stream_writer(self, stream, url, filename):
logger.info(f'{self.flag}获取到直播流链接:{filename}\n{stream.url}')
output = FileOutput(Path(f'output/{filename}'))
output = FileOutput(Path(f'{self.output}/{filename}'))
try:
stream_fd, prebuffer = open_stream(stream)
output.open()
Expand All @@ -160,13 +161,13 @@ def stream_writer(self, stream, url, filename):
def run_ffmpeg(self, filename, format):
logger.info(f'{self.flag}开始ffmpeg封装:{filename}')
new_filename = filename.replace(f'.{format}', f'.{self.format}')
ffmpeg.input(f'output/{filename}').output(
f'output/{new_filename}',
ffmpeg.input(f'{self.output}/{filename}').output(
f'{self.output}/{new_filename}',
codec='copy',
map_metadata='-1',
movflags='faststart'
).global_args('-hide_banner').run()
os.remove(f'output/{filename}')
os.remove(f'{self.output}/{filename}')


class Bilibili(LiveRecoder):
Expand Down

0 comments on commit fd04184

Please sign in to comment.