diff --git a/README.md b/README.md index 36fb154..38b3be9 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ Fork from `msw-file`,目前是一个音乐播放器。 初次使用请配置 `api_config.json`, **最重要的是配置 `token`** 。 +默认 ffmpeg 线程 `ffmpeg_threads` 为 1 ,大于 1 以上的值似乎对编码音频没有效果。 + #### api_config.json 说明 - `database_name` 字符串类型,指定 sqlite3 单文件数据库的位置,如果不存在则会自动创建。 diff --git a/api_config.json b/api_config.json index b65a0ac..6401e45 100644 --- a/api_config.json +++ b/api_config.json @@ -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"}, diff --git a/internal/pkg/api/api.go b/internal/pkg/api/api.go index 5dc299c..3a25725 100644 --- a/internal/pkg/api/api.go +++ b/internal/pkg/api/api.go @@ -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"` }