diff --git a/conv/Rotate.go b/conv/Rotate.go index 7837c6e..605df7f 100644 --- a/conv/Rotate.go +++ b/conv/Rotate.go @@ -1,7 +1,6 @@ package conv import ( - "fmt" "github.com/zhangyiming748/ConvertVideo/mediainfo" "github.com/zhangyiming748/ConvertVideo/replace" "github.com/zhangyiming748/ConvertVideo/util" @@ -13,7 +12,6 @@ import ( ) func RotateVideo(in mediainfo.BasicInfo, direction string) { - if strings.Contains(in.PurgePath, "rotate") { return } @@ -61,21 +59,15 @@ func RotateVideo(in mediainfo.BasicInfo, direction string) { cmd = exec.Command("ffmpeg", "-y", "-i", in.FullPath, "-vf", transport, "-c:v", "libx265", "-c:a", "libopus", "-ac", "1", "-map_chapters", "-1", out) err := util.ExecCommand(cmd, FrameCount) if err != nil { - os.Exit(-1) + log.Fatalln("旋转视频命令发生错误") } originsize, _ := util.GetSize(in.FullPath) aftersize, _ := util.GetSize(out) sub, _ := util.GetDiffSize(originsize, aftersize) - fmt.Printf("savesize: %f MB\n", sub) - if aftersize < originsize { - if err = os.Remove(in.FullPath); err != nil { - log.Printf("删除失败:%v\n", in.FullPath) - } else { - log.Printf("删除成功:%v\n", in.FullPath) - } + log.Printf("转换前%fM转换后%fM节省%fM\n", originsize/util.MB, aftersize/util.MB, sub) + if err = os.Remove(in.FullPath); err != nil { + log.Printf("删除失败:%v\n", in.FullPath) } else { - log.Printf("转码后文件:%v\t大于源文件:%v\n,保留不删除", out, in.FullPath) + log.Printf("删除成功:%v\n", in.FullPath) } - log.Printf("本次转码完成,文件大小减少 %f MB\n", sub) - } diff --git a/conv/h265.go b/conv/h265.go index a71621a..92b1ead 100644 --- a/conv/h265.go +++ b/conv/h265.go @@ -1,7 +1,6 @@ package conv import ( - "fmt" "github.com/zhangyiming748/ConvertVideo/constant" "github.com/zhangyiming748/ConvertVideo/mediainfo" "github.com/zhangyiming748/ConvertVideo/replace" @@ -49,15 +48,11 @@ func ProcessVideo2H265(in mediainfo.BasicInfo) { } } out := strings.Join([]string{in.PurgePath, string(os.PathSeparator), middle, string(os.PathSeparator), dstPurgeName, ".mp4"}, "") - defer func() { - if err := recover(); err != nil { - log.Printf("出现错误\t输入文件:%v\t输出文件%v\n:", in.FullPath, out) - } - }() mp4 := strings.Replace(out, in.PurgeExt, "mp4", -1) - cmd := exec.Command("ffmpeg", "-i", in.FullPath, "-c:v", "libx265", "-tag:v", "hvc1", "-c:a", "libopus", "-ac", "1", "-map_chapters", "-1", mp4) + crf := FastMediaInfo.GetCRF("h265", width, height) + cmd := exec.Command("ffmpeg", "-i", in.FullPath, "-c:v", "libx265", "-crf", crf, "-tag:v", "hvc1", "-c:a", "libopus", "-ac", "1", "-map_chapters", "-1", mp4) if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" { - cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-threads", "1", "-c:v", "libx265", "-tag:v", "hvc1", "-c:a", "libopus", "-ac", "1", "-map_chapters", "-1", "-threads", "1", mp4) + cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-threads", "1", "-c:v", "libx265", "-crf", crf, "-tag:v", "hvc1", "-c:a", "libopus", "-ac", "1", "-map_chapters", "-1", "-threads", "1", mp4) } if width > 1920 && height > 1920 { log.Printf("视频大于1080P需要使用其他程序先处理视频尺寸:%v\n", in) @@ -72,7 +67,10 @@ func ProcessVideo2H265(in mediainfo.BasicInfo) { originsize, _ := util.GetSize(in.FullPath) aftersize, _ := util.GetSize(mp4) sub, _ := util.GetDiffSize(originsize, aftersize) - fmt.Printf("savesize: %f MB\n", sub) - log.Printf("本次转码完成,文件大小减少 %f MB\n", sub) - os.Remove(in.FullPath) + log.Printf("转换前%fM转换后%fM节省%fM\n", originsize/util.MB, aftersize/util.MB, sub) + if err := os.Remove(in.FullPath); err != nil { + log.Printf("删除失败:%v\n", in.FullPath) + } else { + log.Printf("删除成功:%v\n", in.FullPath) + } } diff --git a/go.mod b/go.mod index e8af377..5634e1f 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ toolchain go1.22.2 require ( github.com/schollz/progressbar/v3 v3.14.4 + github.com/zhangyiming748/DeepLX v0.0.1 github.com/zhangyiming748/FastMediaInfo v0.0.2 github.com/zhangyiming748/lumberjack v0.0.1 ) @@ -18,7 +19,6 @@ require ( github.com/tidwall/gjson v1.14.3 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect - github.com/zhangyiming748/DeepLX v0.0.1 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/term v0.20.0 // indirect )