From 990f47a10ba345b3c0be1f4ffba8f7e00aeee0f1 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 29 Jul 2024 21:59:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Docker-compose.yml | 13 +++++-------- constant/constant.go | 22 +++++++++++++++------- conv/h265.go | 11 +++++++---- main.go | 2 ++ 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Docker-compose.yml b/Docker-compose.yml index d2d1fc2..7faa01b 100644 --- a/Docker-compose.yml +++ b/Docker-compose.yml @@ -2,11 +2,8 @@ version: '3.9' name: conv_video services: conv: - container_name: 'conv' - build: - context: . - dockerfile: Dockerfile - cache_from: [] + container_name: 'conv_video' + image: zhangyiming748/convertvideo:latest volumes: - '/path/to/video:/data' deploy: @@ -16,6 +13,6 @@ services: cpus: '4' environment: - root=/data - - to=vp9 - - level=Info - - direction=ToRight \ No newline at end of file + - to=h265 + - direction=ToRight + - trans = 0 # 0不翻译标题 \ No newline at end of file diff --git a/constant/constant.go b/constant/constant.go index 6328c6a..41897a6 100644 --- a/constant/constant.go +++ b/constant/constant.go @@ -5,19 +5,27 @@ import ( ) var ( - Root string = "/data" // 工作目录 如果为空 默认/data - //Root string = "C:\\Users\\zen\\Github\\ConvertVideo\\video" // 工作目录 如果为空 默认/data - //To string = "clip" // 转换到的编码 如果为空 默认vp9 - To string = "h265" // 转换到的编码 如果为空 默认vp9 - //To string = "merge" // 转换到的编码 如果为空 默认vp9 - Direction string = "ToRight" - CpuNums int = runtime.NumCPU() // 核心数 + Root string = "/data" // 工作目录 如果为空 默认/data + To string = "h265" // 转换到的编码 如果为空 默认vp9 + Direction string = "ToRight" + CpuNums int = runtime.NumCPU() // 核心数 + TransTitle bool ) const ( MaxCPU = 12 ) +func SetTransTitle(s string) { + if s == "0" { + TransTitle = false + } else { + TransTitle = true + } +} +func GetTransTitle() bool { + return TransTitle +} func GetCpuNums() int { return CpuNums } diff --git a/conv/h265.go b/conv/h265.go index ce27569..542fd45 100644 --- a/conv/h265.go +++ b/conv/h265.go @@ -2,10 +2,11 @@ package conv import ( "fmt" + "github.com/zhangyiming748/ConvertVideo/constant" "github.com/zhangyiming748/ConvertVideo/mediainfo" "github.com/zhangyiming748/ConvertVideo/replace" "github.com/zhangyiming748/ConvertVideo/util" - DeepLx "github.com/zhangyiming748/DeepLX" + "github.com/zhangyiming748/DeepLX" "github.com/zhangyiming748/FastMediaInfo" "log" "os" @@ -21,7 +22,6 @@ func ProcessVideo2H265(in mediainfo.BasicInfo) { width int height int ) - mi := FastMediaInfo.GetStandMediaInfo(in.FullPath) FrameCount := mi.Video.FrameCount width, _ = strconv.Atoi(mi.Video.Width) @@ -43,8 +43,10 @@ func ProcessVideo2H265(in mediainfo.BasicInfo) { log.Println("创建输出文件夹") } dstPurgeName := replace.ForFileName(in.PurgeName) // 输入文件格式化后的新文件名 - if dst, err := DeepLx.TranslateByDeepLX("auto", "zh", dstPurgeName, ""); err == nil { - dstPurgeName = dst + if constant.GetTransTitle() { + if dst, err := DeepLx.TranslateByDeepLX("auto", "zh", dstPurgeName, ""); err == nil { + dstPurgeName = dst + } } out := strings.Join([]string{in.PurgePath, string(os.PathSeparator), middle, string(os.PathSeparator), dstPurgeName, ".mp4"}, "") defer func() { @@ -70,4 +72,5 @@ func ProcessVideo2H265(in mediainfo.BasicInfo) { sub, _ := util.GetDiffSize(originsize, aftersize) fmt.Printf("savesize: %f MB\n", sub) log.Printf("本次转码完成,文件大小减少 %f MB\n", sub) + os.Remove(in.FullPath) } diff --git a/main.go b/main.go index 8648332..c199fcd 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,8 @@ func main() { log.Printf("程序总用时:%v分\n", t.GetDuration().Minutes()) }() + constant.SetTransTitle(os.Getenv("trans")) + if direction := os.Getenv("direction"); direction == "" { log.Printf("$direction为空,使用默认值%v\n", constant.GetDirection()) } else {