ffmpeg_threads

This commit is contained in:
2021-05-25 14:20:29 +08:00
parent 0611f27a69
commit d5afdfe62b
3 changed files with 6 additions and 2 deletions

View File

@@ -26,6 +26,8 @@ Fork from `msw-file`,目前是一个音乐播放器。
初次使用请配置 `api_config.json` **最重要的是配置 `token`**
默认 ffmpeg 线程 `ffmpeg_threads` 为 1 ,大于 1 以上的值似乎对编码音频没有效果。
#### api_config.json 说明
- `database_name` 字符串类型,指定 sqlite3 单文件数据库的位置,如果不存在则会自动创建。

View File

@@ -2,6 +2,7 @@
"database_name": "/tmp/music.sqlite3",
"addr": ":8080",
"token": "!! config your very strong token here !!",
"ffmpeg_threads": 1,
"ffmpeg_configs": {
"0. OPUS 128k": {"args": "-c:a libopus -ab 128k"},
"OPUS 96k": {"args": "-c:a libopus -ab 96k"},

View File

@@ -401,7 +401,7 @@ func (api *API) HandleGetFileStream(w http.ResponseWriter, r *http.Request) {
return
}
args := strings.Split(ffmpegConfig.Args, " ")
startArgs := []string {"-i", path}
startArgs := []string {"-threads", strconv.FormatInt(api.APIConfig.FfmpegThreads, 10), "-i", path}
endArgs := []string {"-vn", "-f", "ogg", "-"}
ffmpegArgs := append(startArgs, args...)
ffmpegArgs = append(ffmpegArgs, endArgs...)
@@ -479,7 +479,7 @@ func (api *API) HandlePrepareFileStreamDirect(w http.ResponseWriter, r *http.Req
api.Tmpfs.Record(objPath)
args := strings.Split(ffmpegConfig.Args, " ")
startArgs := []string {"-i", srcPath}
startArgs := []string {"-threads", strconv.FormatInt(api.APIConfig.FfmpegThreads, 10), "-i", srcPath}
endArgs := []string {"-vn", "-y", objPath}
ffmpegArgs := append(startArgs, args...)
ffmpegArgs = append(ffmpegArgs, endArgs...)
@@ -673,6 +673,7 @@ type APIConfig struct {
DatabaseName string `json:"database_name"`
Addr string `json:"addr"`
Token string `json:"token"`
FfmpegThreads int64 `json:"ffmpeg_threads"`
FfmpegConfigs map[string]*FfmpegConfig `json:"ffmpeg_configs"`
}