Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add k8s manifest; update readme for current architecture 提供 K8s manif… #48

Merged
merged 1 commit into from
Feb 17, 2025
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
199 changes: 153 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<div align="center"><a name="readme-top"></a>

<a href="https://github.com/sutro-planet/pytvzhen-web" target="_blank">
Expand Down Expand Up @@ -31,79 +30,187 @@
</div>

# 简介
本项目着眼于从原始视频到翻译后最终视频的整个工作流程,确保从一而终的整个过程顺畅高效。项目提供了web后端和一个用于测试的前端页面<br>
[本项目测试地址](https://github.com/sutro-planet/easyvideotrans)
<br>

本项目着眼于从原始视频到翻译后最终视频的整个工作流程,确保从一而终的整个过程顺畅高效。项目提供了web后端和一个用于测试的前端页面

[本项目官方部署地址](https://easyvideotrans.com/), [项目Grafana监控仪表盘](https://grafana.sutroplanet.com/d/ee5da809-66e2-4498-9c9c-78a8ebf476a5/easyvideotrans-public?orgId=1)

本方案优势:

- 本方案使用模块化结构,提供 k8s 服务文件,可以在你的服务器(或者可爱的游戏本)上简单地进行 self-host
- 方案简单好用,经过验证,十分可靠,避免被巨量的不靠普方案迷惑,节约用户选择成本。<br>
- 翻译结果质量高,大幅减少人工校对。前期项目<a href="https://github.com/CuSO4Gem/pytvzhen">pytvzhen</a>已经接受广大群友考验,倍受好评。<br>
- 翻译结果质量高,大幅减少人工校对。前期项目 <a href="https://github.com/CuSO4Gem/pytvzhen">pytvzhen</a>
已经接受广大群友考验,倍受好评。<br>
- 方案开源可靠,免费使用。代码结构清晰,可读性强,可扩展性强,适合二次开发。


相关技术说明:
在[技术关注&开发计划](#技术关注开发计划)部分,我们列出了本方案的主要技术关注点,以及后续的开发计划。本项目重点强调易用、可靠、以及产生最终最终视频的速度。因此我们排除了大量不稳定、不可靠的方案,进保留整个工作流程中最好用的方案献给广大用户。
在 [技术关注&开发计划](#技术关注开发计划)
部分,我们列出了本方案的主要技术关注点,以及后续的开发计划。本项目重点强调易用、可靠、以及产生最终最终视频的速度。因此我们排除了大量不稳定、不可靠的方案,进保留整个工作流程中最好用的方案献给广大用户。

<p align="center">
<img src="doc/assets/logo.png" alt="图片">
</p>


# 目录
- [简介](#简介)
- [目录](#目录)
- [相关项目介绍](#相关项目介绍)
- [在线版本](#在线版本)
- [部署](#部署)
- [Docker部署(推荐)](#docker部署推荐)
- [本地部署](#本地部署)
- [环境准备](#环境准备)
- [运行](#运行)
- [API说明](#api说明)
- [技术关注\&开发计划](#技术关注开发计划)
- [主要上游开源项目](#主要上游开源项目)

# 相关项目介绍
* [easyvideotrans-frontend](https://github.com/sutro-planet/easyvideotrans-frontend)正式web前端

* [easyvideotrans-frontend](https://github.com/sutro-planet/easyvideotrans-frontend)正式web前端
* [pytvzhen](https://github.com/CuSO4Gem/pytvzhen)离线客户端

* [https://easyvideotrans.com/](https://easyvideotrans.com/)在线版本

我们部署了一个[在线版本](https://easyvideotrans.com/),可以翻译长达60分钟油管或着任意自定义长度的视频,欢迎随时使用。你可以通过访问
我们部署了一个 [在线版本](https://easyvideotrans.com/),可以翻译长达60分钟油管或着任意自定义长度的视频,欢迎随时使用。你可以通过访问
[Grafana 图表](https://grafana.sutroplanet.com/d/ee5da809-66e2-4498-9c9c-78a8ebf476a5/easyvideotrans)
来了解该在线版本的健康情况。
来了解该在线版本的健康情况。

# 部署

## Docker部署(推荐)
请先了解当前 EasyVideoTrans 项目架构

![架构](./doc/assets/architecture.png)

EasyVideoTrans 项目采用微服务架构,主要由三个 Docker 镜像组成:

* EasyVideoTrans 前端镜像
* 功能:处理浏览器前端请求
* Docker 镜像地址:`hanfa/pytvzhen-web:latest`
* EasyVideoTrans 服务镜像:
* 功能:处理视频管理和基本的音频处理任务。
* Docker 镜像地址:`hanfa/easyvideotrans:latest`
* EasyVideoTrans GPU 工作负载镜像:
* 功能:专门用于处理需要 GPU 加速的音频分离和转录任务。
* Docker 镜像地址:`hanfa/easyvideotrans-workloads:latest`

这种架构通过分离计算密集型任务和常规服务逻辑,优化了资源利用率和系统性能。

## K8s 部署(推荐)

K8s manifest 文件存于 [./k8s/prod](./k8s/prod) 目录,请确保你的集群至少有一个含有`nvidia.com/gpu: 1`的节点。

请全局搜索 `CHANGE ME` 然后自定义你的节点,PVC,以及其他资源的名称。

你可以轻易使用以下命令进行部署

```shell
sudo docker run --rm -p 8888:8080 -v output:/app/output --runtime=nvidia --gpus all hanfa/pytvzhen-web:latest
kubectl apply -k ./k8s/prod
```

## Docker Compose 部署(推荐)

```shell
version: '3.8'

services:
easyvideotrans-frontend:
image: hanfa/pytvzhen-frontend:latest
environment:
- APP_ENV=prod
ports:
- "3000:3000"
deploy:
resources:
limits:
cpus: '4'
memory: 2G
reservations:
cpus: '2'
memory: 1G

easyvideotrans:
image: hanfa/easyvideotrans:latest
environment:
- CELERY_TASK_TIME_LIMIT=7200
- CELERY_TASK_SOFT_TIME_LIMIT=3600
- CELERY_METRICS_SERVER_PORT=8081
ports:
- "8080:8080"
- "8081:8081"
volumes:
- easyvideotrans-output:/app/output

rabbit-mq:
image: rabbitmq:3.13-management
ports:
- "5672:5672"
- "15672:15672"
- "15692:15692"
volumes:
- rabbitmq-plugins:/etc/rabbitmq/enabled_plugins
- rabbitmq-config:/etc/rabbitmq/rabbitmq.conf

easyvideotrans-workloads:
image: docker.io/hanfa/easyvideotrans-workloads:latest
environment:
- APP_ENV=production
- OUTPUT_DIR=/app/static/outputs
ports:
- "8188:8188"
deploy:
resources:
limits:
cpus: '4'
memory: 25G
devices:
- capabilities: [gpu]
reservations:
cpus: '2'
memory: 10G
devices:
- capabilities: [gpu]
volumes:
- easyvideotrans-output:/app/workloads/static/outputs

volumes:
easyvideotrans-output:
rabbitmq-plugins:
driver: local
driver_opts:
type: none
device: ./rabbitmq/enabled_plugins
o: bind
rabbitmq-config:
driver: local
driver_opts:
type: none
device: ./rabbitmq/rabbitmq.conf
o: bind
```

## 本地部署

以下操作可能过时,具体配环境请参考以下Dockerfile

* 前端 [Dockerfile for frontend](https://github.com/sutro-planet/easyvideotrans-frontend/blob/main/Dockerfile)
for `hanfa/pytvzhen-web:latest`
* 服务层 [Dockerfile](./Dockerfile) for `hanfa/easyvideotrans:latest`
* GPU服务层 [Dockerfile-gpu-workload](./Dockerfile-gpu-workload) for `hanfa/easyvideotrans-workloads:latest`

### 环境准备
安装依赖需要:requirements.txt中的各种依赖,pythorch库,ffmpeg(可选)。本工程Python 3.9.19上验证。另外如果你想体验完整的工作流程,推荐下载一个字幕文件编辑器,尽管本程序用不到,但是在转换视频的工作中,你一定用得到,我使用Aegisub。

安装依赖需要:requirements.txt中的各种依赖,pythorch库,ffmpeg(可选)。本工程Python
3.9.19上验证。另外如果你想体验完整的工作流程,推荐下载一个字幕文件编辑器,尽管本程序用不到,但是在转换视频的工作中,你一定用得到,我使用Aegisub。

各种基本库安装
``
pip install -r requirements.txt
``

pytorch安装:
在[点击这里](https://pytorch.org/get-started/locally/),选择合适的安装版本,**必须要选择gpu版!!!!** 原因是作者偷懒没有做cpu方案,其实如果你愿意,改几行源码实现在CPU上跑应该也不难。
在[点击这里](https://pytorch.org/get-started/locally/),选择合适的安装版本,**必须要选择gpu版!!!!**
原因是作者偷懒没有做cpu方案,其实如果你愿意,改几行源码实现在CPU上跑应该也不难。

其他依赖:

确保 RabbitMQ 作为broker在[./configs/celery.json](./configs/celery.json)里定义的`broker_url`运行,
具体方法参考[这里](https://www.rabbitmq.com/docs/download),用`sudo rabbitmqctl status` 确保其正常运行。

ffmpeg安装

```
sudo apt-get install ffmpeg
```

[faster-whisper](https://github.com/SYSTRAN/faster-whisper/)下载自动模型的时候,国内可能会比较慢,甚至无法下载!!faster-whisper_models目录中,使得目录结构为:

```
faster-whisper_models
|-models--Systran--faster-whisper-base.en
Expand All @@ -112,28 +219,29 @@ faster-whisper_models
```

### 运行

0. 修改配置
修改pytvzhen.json中的**VIDEO_MAX_DURATION**,配置下载视频的最大长度,单位为秒。
修改pytvzhen.json中的**VIDEO_MAX_DURATION**,配置下载视频的最大长度,单位为秒。

1. 在一个 terminal 里面启动 Celery 队列和 worker 来处理视频渲染请求。

`celery -A src.task_manager.celery_tasks.celery_app worker --concurrency 1 -Q video_preview`

2. 在另一个 terminal 里运行flask app。

```
flask run --host=0.0.0.0 --debug
```

然后浏览器打开http://127.0.0.1:5000.

# API说明
[API文档](./doc/api.md)

# 技术关注&开发计划

后续计划:谨慎添加更多可靠的功能,增加其他语言到中文的翻译
| 项目名称 | 功能 | 当前状况 | 计划 |
| --- | --- | --- | --- |
| [whisper](https://github.com/openai/whisper)、[stable-whisper](https://github.com/jianfch/stable-ts)| 语言转字幕| 效果不如faster-whisper | 不添加 |
| [whisper](https://github.com/openai/whisper)、[stable-whisper](https://github.com/jianfch/stable-ts)| 语言转字幕|
效果不如faster-whisper | 不添加 |
| [Funasr](https://gitcode.com/alibaba-damo-academy/FunASR/)| 语言转字幕| 还没验证 | 验证后再决策 |
| [GPT-SoVITS](https://github.com/RVC-Boss/GPT-SoVITS)| TTS | TTS输出不稳定 | 观望|
| [ChatTTS](https://github.com/2noise/ChatTTS) | TTS | TTS输出不稳定 | 观望 |
Expand All @@ -143,17 +251,16 @@ flask run --host=0.0.0.0 --debug
| 百度翻译、有道翻译、迅飞翻译 | 翻译 | 效果远不如谷歌 | 不添加 |
| [ChatGpt](https://chatgpt.com) | 翻译 | 效果不错 | 后续添加 |



# 主要上游开源项目
- [pytvzhen](https://github.com/CuSO4Gem/pytvzhen)
- [pytube](https://github.com/pytube/pytube)
- [ffmpeg](https://ffmpeg.org/)
- [faster-whisper](https://github.com/SYSTRAN/faster-whisper)
- [vocal-remover](https://github.com/tsurumeso/vocal-remover/releases)
- [srt](https://srt.readthedocs.io/en/latest/api.html)
- [pygtrans](https://github.com/foyoux/pygtrans)
- [edge-tts](https://github.com/hasscc/hass-edge-tts)
- [GPT-SoVITS](https://github.com/RVC-Boss/GPT-SoVITS)
- [moviepy](https://github.com/Zulko/moviepy)

- [pytvzhen](https://github.com/CuSO4Gem/pytvzhen)
- [pytube](https://github.com/pytube/pytube)
- [ffmpeg](https://ffmpeg.org/)
- [faster-whisper](https://github.com/SYSTRAN/faster-whisper)
- [vocal-remover](https://github.com/tsurumeso/vocal-remover/releases)
- [srt](https://srt.readthedocs.io/en/latest/api.html)
- [pygtrans](https://github.com/foyoux/pygtrans)
- [edge-tts](https://github.com/hasscc/hass-edge-tts)
- [GPT-SoVITS](https://github.com/RVC-Boss/GPT-SoVITS)
- [moviepy](https://github.com/Zulko/moviepy)

Binary file added doc/assets/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions k8s/prod/easyvideotrans-frontend.ingressroute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: easyvideotrans-frontend
namespace: easyvideotrans
spec:
entryPoints:
- websecure
tls:
secretName: wildcard.deimos.cloud-tls
routes:
- match: Host(`easyvideotrans.com`) || Host(`www.easyvideotrans.com`)
kind: Rule
services:
- name: easyvideotrans-frontend
port: 3000
12 changes: 12 additions & 0 deletions k8s/prod/easyvideotrans-frontend.service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: easyvideotrans-frontend
spec:
type: ClusterIP
selector:
app: easyvideotrans-frontend
ports:
- protocol: TCP
port: 3000
targetPort: 3000
33 changes: 33 additions & 0 deletions k8s/prod/easyvideotrans-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: easyvideotrans-frontend
labels:
app: easyvideotrans-frontend
spec:
replicas: 1
selector:
matchLabels:
app: easyvideotrans-frontend
template:
metadata:
labels:
app: easyvideotrans-frontend
spec:
restartPolicy: Always
containers:
- name: easyvideotrans-frontend
image: hanfa/pytvzhen-frontend:latest
env:
- name: APP_ENV
value: "prod"
ports:
- containerPort: 3000
protocol: TCP
resources:
limits:
cpu: "4"
memory: "2Gi"
requests:
cpu: "2"
memory: "1Gi"
36 changes: 36 additions & 0 deletions k8s/prod/easyvideotrans-pv-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: easyvideotrans-output-pvc
namespace: easyvideotrans
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 200Gi
storageClassName: local-path
volumeMode: Filesystem
volumeName: easyvideotrans-output-pv
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: easyvideotrans-output-pv
namespace: easyvideotrans
spec:
capacity:
storage: 200Gi
accessModes:
- ReadWriteMany
storageClassName: local-path
local:
path: /mnt/easyvideotrans-ssd/root/k3smnt # CHANGE ME for a local path of your node
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- sutro-gpu1 # CHANGE ME to the name of your node
Loading
Loading