Skip to content

Commit

Permalink
发版
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyiming748 committed Jul 29, 2024
1 parent c88050d commit 990f47a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
13 changes: 5 additions & 8 deletions Docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -16,6 +13,6 @@ services:
cpus: '4'
environment:
- root=/data
- to=vp9
- level=Info
- direction=ToRight
- to=h265
- direction=ToRight
- trans = 0 # 0不翻译标题
22 changes: 15 additions & 7 deletions constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 7 additions & 4 deletions conv/h265.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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() {
Expand All @@ -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)
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 990f47a

Please sign in to comment.