Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/danmaku/DanmakuConvert"]
path = src/danmaku/DanmakuConvert
url = https://github.com/timerring/DanmakuConvert.git
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
- **速度快**:采用 `pipeline` 流水线处理视频,理想情况下录播与直播相差半小时以内,没下播就能上线录播,**目前已知 b 站录播最快版本**!
- **多房间**:同时录制多个直播间内容视频以及弹幕文件(包含普通弹幕,付费弹幕以及礼物上舰等信息)。
- **占用小**:自动删除本地已上传的视频,极致节省空间。
- **模版化**:无需复杂配置,开箱即用,( :tada: NEW)通过 b 站搜索建议接口自动抓取相关热门标签。
- **模版化**:无需复杂配置,开箱即用,通过 b 站搜索建议接口自动抓取相关热门标签。
- **检测片段并合并**:对于网络问题或者直播连线导致的视频流分段,能够自动检测合并成为完整视频。
- **自动渲染弹幕**:自动转换xml为ass弹幕文件并且渲染到视频中形成**有弹幕版视频**并自动上传。
- **自动渲染弹幕**:自动转换xml为ass弹幕文件,该转换工具库已经开源 [DanmakuConvert](https://github.com/timerring/DanmakuConvert) 并且渲染到视频中形成**有弹幕版视频**并自动上传。
- **硬件要求极低**:无需GPU,只需最基础的单核CPU搭配最低的运存即可完成录制,弹幕渲染,上传等等全部过程,无最低配置要求,10年前的电脑或服务器依然可以使用!
- **( :tada: NEW)自动渲染字幕**(如需使用本功能,则需保证有 Nvidia 显卡):采用 OpenAI 的开源模型 [`whisper`](https://github.com/openai/whisper),自动识别视频内语音并转换为字幕渲染至视频中。
- **( :tada: NEW)自动切片上传**:根据弹幕密度计算寻找高能片段并切片,该自动切片工具库已开源 [auto-slice-video](https://github.com/timerring/auto-slice-video)
Expand All @@ -50,9 +50,9 @@ graph TD
whisper[whisperASR模型] --生成字幕-->parameter[查询视频分辨率]
subgraph 启动新进程
parameter[查询分辨率] -->ifDanmaku{判断}
ifDanmaku -->|有弹幕| DanmakuFactory[DanmakuFactory]
ifDanmaku -->|有弹幕| DanmakuConvert[DanmakuConvert]
ifDanmaku -->|无弹幕| ffmpeg1[ffmpeg]
DanmakuFactory[DanmakuFactory] --根据分辨率转换弹幕--> ffmpeg1[ffmpeg]
DanmakuConvert[DanmakuConvert] --根据分辨率转换弹幕--> ffmpeg1[ffmpeg]
ffmpeg1[ffmpeg] --渲染弹幕及字幕 --> Video[视频文件]
Video[视频文件] --计算弹幕密度并切片--> GLM[多模态视频理解模型]
GLM[多模态视频理解模型] --生成切片信息--> slice[视频切片]
Expand All @@ -69,7 +69,7 @@ graph TD
## 3. 测试硬件
+ OS: Ubuntu 22.04.4 LTS

>尽量使用 22.04+ 的版本,更早版本的 ubuntu 自带 gcc 版本无法更新至 DanmakuFactory 以及 biliup-rs 所需版本,若使用较早版本,请参考 [version `GLIBC_2.34‘ not found简单有效解决方法](https://blog.csdn.net/huazhang_001/article/details/128828999)。
>尽量使用 22.04+ 的版本,更早版本的 ubuntu 自带 gcc 版本无法更新至 biliup-rs 所需版本,若使用较早版本,请参考 [version `GLIBC_2.34‘ not found简单有效解决方法](https://blog.csdn.net/huazhang_001/article/details/128828999)。
+ CPU:2核 Intel(R) Xeon(R) Platinum 85
+ GPU:无
+ 内存:2G
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ graph TD
whisper[whisperASR模型] --生成字幕-->parameter[查询视频分辨率]
subgraph 启动新进程
parameter[查询分辨率] -->ifDanmaku{判断}
ifDanmaku -->|有弹幕| DanmakuFactory[DanmakuFactory]
ifDanmaku -->|有弹幕| DanmakuConvert[DanmakuConvert]
ifDanmaku -->|无弹幕| ffmpeg1[ffmpeg]
DanmakuFactory[DanmakuFactory] --根据分辨率转换弹幕--> ffmpeg1[ffmpeg]
DanmakuConvert[DanmakuConvert] --根据分辨率转换弹幕--> ffmpeg1[ffmpeg]
ffmpeg1[ffmpeg] --渲染弹幕及字幕 --> Video[视频文件]
Video[视频文件] --计算弹幕密度并切片--> GLM[多模态视频理解模型]
GLM[多模态视频理解模型] --生成切片信息--> slice[视频切片]
Expand Down
2 changes: 1 addition & 1 deletion docs/install-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Reference: https://github.com/timerring/bilive/issues/106

Reference: https://blog.csdn.net/huazhang_001/article/details/128828999

尽量使用 22.04+ 的版本,更早版本的 ubuntu 自带 gcc 版本无法更新至 DanmakuFactory 以及 biliup-rs 所需版本。
尽量使用 22.04+ 的版本,更早版本的 ubuntu 自带 gcc 版本无法更新至 biliup-rs 所需版本。

解决方案:手动更新版本,参照链接操作即可。

Expand Down
2 changes: 1 addition & 1 deletion docs/test-hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
+ OS: Ubuntu 20.04.4 LTS

> [!WARNING]
> 尽量使用 22.04+ 的版本,更早版本的 ubuntu 自带 gcc 版本无法更新至 DanmakuFactory 以及 biliup-rs 所需版本,若使用较早版本,请参考 [version `GLIBC_2.34‘ not found简单有效解决方法](https://blog.csdn.net/huazhang_001/article/details/128828999)。
> 尽量使用 22.04+ 的版本,更早版本的 ubuntu 自带 gcc 版本无法更新至 biliup-rs 所需版本,若使用较早版本,请参考 [version `GLIBC_2.34‘ not found简单有效解决方法](https://blog.csdn.net/huazhang_001/article/details/128828999)。

+ CPU:Intel(R) Core(TM) i5-9300H CPU 8 核
+ GPU:NVIDIA GeForce GTX 1650 显存 4GB
Expand Down
4 changes: 2 additions & 2 deletions src/burn/render_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def render_video(video_path):
jsonl_path = original_video_path[:-4] + '.jsonl'

# Recoginze the resolution of video
video_resolution = get_resolution(original_video_path)
resolution_x, resolution_y = get_resolution(original_video_path)
try:
# Process the danmakus to ass and remove emojis
subtitle_font_size, subtitle_margin_v = process_danmakus(xml_path, video_resolution)
subtitle_font_size, subtitle_margin_v = process_danmakus(xml_path, resolution_x, resolution_y)
except TypeError as e:
scan_log.error(f"TypeError: {e} - Check the return value of process_danmakus")
except FileNotFoundError as e:
Expand Down
2 changes: 0 additions & 2 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
BILIVE_DIR = str(Path(SRC_DIR).parent)
LOG_DIR = os.path.join(BILIVE_DIR, 'logs')
VIDEOS_DIR = os.path.join(BILIVE_DIR, 'Videos')
DanmakuFactory_bin = os.path.join('utils', 'DanmakuFactory')
DanmakuFactory_PATH = os.path.join(SRC_DIR, DanmakuFactory_bin)

def get_model_path():
SRC_DIR = str(Path(os.path.abspath(__file__)).parent)
Expand Down
1 change: 1 addition & 0 deletions src/danmaku/DanmakuConvert
Submodule DanmakuConvert added at f12912
5 changes: 4 additions & 1 deletion src/danmaku/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from .DanmakuConvert.dmconvert import convert_xml_to_ass

__all__ = ['convert_xml_to_ass']
76 changes: 33 additions & 43 deletions src/danmaku/generate_danmakus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import os
import subprocess
from src.config import DanmakuFactory_PATH
from src.log.logger import scan_log
from .adjust_price import update_danmaku_prices
from .remove_emojis import remove_emojis
from .DanmakuConvert.dmconvert import convert_xml_to_ass


def get_resolution(in_video_path):
Expand All @@ -19,69 +18,60 @@ def get_resolution(in_video_path):
# Use ffprobe to acquire the video resolution
result = subprocess.run(
['ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'csv=s=x:p=0', in_video_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
text=True,
check=True
capture_output=True
)
scan_log.debug(f"get_resolution FFmpeg output: {result.stdout}")
if result.stderr:
scan_log.debug(f"get_resolution FFmpeg debug: {result.stderr}")
resolution = result.stdout.strip()
scan_log.info("The video resolution is " + resolution)
return resolution
resolution_x, resolution_y = map(int, resolution.split('x'))
scan_log.info(f"The video resolution x is {resolution_x} and y is {resolution_y}")
return resolution_x, resolution_y
except subprocess.CalledProcessError as e:
scan_log.error(f"Error: {e.stderr}")
return '1920x1080'
scan_log.error(f"get_resolution Error: {e.stderr}")
return 1920, 1080

def process_danmakus(in_xml_path, resolution):
def process_danmakus(in_xml_path, resolution_x, resolution_y):
"""Generate and process the danmakus according to different resolution.
Args:
in_xml_path: str, the xml path to generate ass file
resolution: str, the resolution of the video
resolution_x: int, the x resolution of the video
resolution_y: int, the y resolution of the video
Return:
subtitle_font_size: str, the font size of subtitles
subtitle_margin_v: str, the margin v of subtitles
"""
if os.path.isfile(in_xml_path):
# Adjust the price of sc and guard
update_danmaku_prices(in_xml_path)
in_ass_path = in_xml_path[:-4] + '.ass'
if resolution == '1280x720':
boxsize = '500x720'
boxfont = '23'
danmakufont = '38'
out_ass_path = in_xml_path[:-4] + '.ass'
if resolution_x == 1280 and resolution_y == 720:
boxfont = 30
danmakufont = 38
subtitle_font_size = '15'
subtitle_margin_v = '20'
elif resolution == '1920x1080':
boxsize = '500x1080'
boxfont = '50'
danmakufont = '55'
subtitle_font_size = '16'
subtitle_margin_v = '60'
elif resolution == '1080x1920':
boxsize = '500x1920'
boxfont = '55'
danmakufont = '60'
elif resolution_x == 720 and resolution_y == 1280:
boxfont = 30
danmakufont = 38
subtitle_font_size = '8'
subtitle_margin_v = '60'
elif resolution == '720x1280':
boxsize = '500x1280'
boxfont = '28'
danmakufont = '38'
elif resolution_x == 1920 and resolution_y == 1080:
boxfont = 42
danmakufont = 42
subtitle_font_size = '16'
subtitle_margin_v = '60'
elif resolution_x == 1080 and resolution_y == 1920:
boxfont = 42
danmakufont = 42
subtitle_font_size = '8'
subtitle_margin_v = '60'
else:
boxsize = '500x1080'
boxfont = '38'
danmakufont = '38'
boxfont = 38
danmakufont = 38
subtitle_font_size = '16'
subtitle_margin_v = '60'
# Convert danmakus to ass file
try:
result = subprocess.run(
[DanmakuFactory_PATH, "-o", in_ass_path, "-i", in_xml_path, "--resolution", resolution, "--msgboxsize", boxsize, "--msgboxfontsize", boxfont, "-S", danmakufont, "--ignore-warnings"],
check=True, capture_output=True, text=True)
scan_log.debug(f"DanmakuFactory output: {result.stdout}")
except subprocess.CalledProcessError as e:
scan_log.error(f"Error: {e.stderr}")
# Remove emojis from ass danmakus (the ffmpeg does not support emojis)
remove_emojis(in_ass_path)
scan_log.info(f"The emojis of {in_ass_path} has been removed.")
convert_xml_to_ass(danmakufont, boxfont, resolution_x, resolution_y, in_xml_path, out_ass_path)
return subtitle_font_size, subtitle_margin_v
31 changes: 0 additions & 31 deletions src/danmaku/remove_emojis.py

This file was deleted.

Binary file removed src/utils/DanmakuFactory
Binary file not shown.