Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyiming748 committed Aug 9, 2024
2 parents a7feadc + b417c8b commit 41add9f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
18 changes: 5 additions & 13 deletions conv/Rotate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package conv

import (
"fmt"
"github.com/zhangyiming748/ConvertVideo/mediainfo"
"github.com/zhangyiming748/ConvertVideo/replace"
"github.com/zhangyiming748/ConvertVideo/util"
Expand All @@ -13,7 +12,6 @@ import (
)

func RotateVideo(in mediainfo.BasicInfo, direction string) {

if strings.Contains(in.PurgePath, "rotate") {
return
}
Expand Down Expand Up @@ -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)

}
20 changes: 9 additions & 11 deletions conv/h265.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package conv

import (
"fmt"
"github.com/zhangyiming748/ConvertVideo/constant"
"github.com/zhangyiming748/ConvertVideo/mediainfo"
"github.com/zhangyiming748/ConvertVideo/replace"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)

0 comments on commit 41add9f

Please sign in to comment.