diff --git a/conf.ini b/conf.ini index ae4281d..c0af3fa 100644 --- a/conf.ini +++ b/conf.ini @@ -3,12 +3,12 @@ # mission = video # mission = OGG # mission = audio -# mission = image +mission = image # mission = rotate # mission = resize # mission = avmerger # mission = extractAAC -mission = speedUpAudio +# mission = speedUpAudio # mission = speedUpVideo # mission = gif # mission = encoder @@ -31,7 +31,7 @@ gif = gif;webm txt = txt [root] folder = /Users/zen/git -image = /Volumes/noname +image = /Users/zen/Downloads/图片助手(ImageAssistant)_批量图片下载器/telegra.ph audio = /Users/zen/container/useWget/柒柒音声/done/do video = /mnt/f/large/AV/other gif = /Users/zen/Downloads/Fugtrup collection/archive/webp diff --git a/count/count.go b/count/count.go new file mode 100644 index 0000000..4fd9020 --- /dev/null +++ b/count/count.go @@ -0,0 +1,14 @@ +package count + +var num uint64 + +func GetNum() uint64 { + return num +} + +func AddNum() { + num++ +} +func SubNum() { + num-- +} diff --git a/main.go b/main.go index 6c233b3..391e6a3 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "processAll/GetAllFolder" "processAll/GetFileInfo" "processAll/alert" + "processAll/count" "processAll/merge" "processAll/processAudio" "processAll/processImage" @@ -257,6 +258,8 @@ func sendEmail(start, end time.Time, ss ...string) { i.SetSubject(strings.Join([]string{"AllInOne", util.GetVal("main", "mission"), "任务完成"}, ":")) text := strings.Join([]string{start.Format("任务开始时间 2006年01月02日 15:04:05"), end.Format("任务结束时间 2006年01月02日 15:04:05"), fmt.Sprintf("任务用时%.3f分", end.Sub(start).Minutes())}, "
") i.SetText(text) + summary := strings.Join([]string{"共成功转换", fmt.Sprint(count.GetNum(), "个文件")}, "") + i.AppendText(summary) for _, s := range ss { i.AppendText(s) } diff --git a/processImage/avif.go b/processImage/avif.go index 833f62a..f78d200 100644 --- a/processImage/avif.go +++ b/processImage/avif.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "processAll/GetFileInfo" + "processAll/count" "processAll/mediaInfo" "processAll/replace" "processAll/util" @@ -36,6 +37,14 @@ func ProcessImages(dir, pattern, threads string) { 转换一张图片为AVIF */ func ProcessImage(in GetFileInfo.BasicInfo, threads string) { + defer func() { + if err := recover(); err != nil { + slog.Warn("转换失败", slog.Any("错误", err)) + } else { + count.AddNum() + slog.Debug("转换成功", slog.Any("文件", in.FullPath)) + } + }() mi, ok := in.MediaInfo.(mediaInfo.ImageInfo) if ok { slog.Debug("断言图片mediainfo结构体成功", slog.Any("MediainfoVideo结构体", mi)) diff --git a/processVideo/PAL.go b/processVideo/PAL.go index 93e981f..4a41cea 100644 --- a/processVideo/PAL.go +++ b/processVideo/PAL.go @@ -43,7 +43,7 @@ func Fix4x3(in GetFileInfo.BasicInfo, threads string) { slog.Debug("新建文件夹", slog.String("全名", dst)) out := strings.Join([]string{dst, mp4}, string(os.PathSeparator)) slog.Debug("io", slog.String("源文件:", in.FullPath), slog.String("输出文件:", out)) - var cmd *exec.Cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-aspect", "4:3", "-c:v", "libx265", "-c:a", "aac", "-ac", "1", "-tag:v", "hvc1", "-threads", threads, out) + var cmd *exec.Cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-aspect", "4:3", "-c:v", "libx265", "-ac", "1", "-tag:v", "hvc1", "-threads", threads, out) err := util.ExecCommand(cmd) if err == nil { if err = os.Remove(in.FullPath); err != nil { diff --git a/processVideo/Resize.go b/processVideo/Resize.go index ffe823e..859b7e5 100644 --- a/processVideo/Resize.go +++ b/processVideo/Resize.go @@ -75,19 +75,19 @@ func Resize(in GetFileInfo.BasicInfo, threads string, p string) { var cmd *exec.Cmd switch p { case "1920x1080": - cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1080", "-c:v", "copy", "-tag:v", "hvc1", "-c:a", "libvorbis", "-ac", "1", "-threads", threads, out) + cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1080", "-c:v", "copy", "-tag:v", "hvc1", "-ac", "1", "-threads", threads, out) if mi.VideoCodecID != "hvc1" { - cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1080", "-c:v", "libx265", "-tag:v", "hvc1", "-c:a", "libvorbis", "-ac", "1", "-threads", threads, out) + cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1080", "-c:v", "libx265", "-tag:v", "hvc1", "-ac", "1", "-threads", threads, out) } case "1080x1920": - cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1920", "-c:v", "copy", "-tag:v", "hvc1", "hvc1", "-c:a", "libvorbis", "-ac", "1", "-threads", threads, out) + cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1920", "-c:v", "copy", "-tag:v", "hvc1", "hvc1", "-ac", "1", "-threads", threads, out) if mi.VideoCodecID != "hvc1" { - cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1920", "-c:v", "libx265", "-tag:v", "hvc1", "-c:a", "libvorbis", "-ac", "1", "-threads", threads, out) + cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1920", "-c:v", "libx265", "-tag:v", "hvc1", "-ac", "1", "-threads", threads, out) } case "1920x1920": - cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=1920:1920", "-c:v", "copy", "-tag:v", "hvc1", "-c:a", "libvorbis", "-ac", "1", "-threads", threads, out) + cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=1920:1920", "-c:v", "copy", "-tag:v", "hvc1", "-ac", "1", "-threads", threads, out) if mi.VideoCodecID != "hvc1" { - cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=1920:1920", "-c:v", "libx254", "-tag:v", "hvc1", "hvc1", "-c:a", "libvorbis", "-ac", "1", "-threads", threads, out) + cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-strict", "-2", "-vf", "scale=1920:1920", "-c:v", "libx254", "-tag:v", "hvc1", "hvc1", "-ac", "1", "-threads", threads, out) } default: slog.Warn("不正常的视频源", slog.Any("视频信息", in.FullPath)) diff --git a/processVideo/Rotate.go b/processVideo/Rotate.go index 92eaea2..ee33eb4 100644 --- a/processVideo/Rotate.go +++ b/processVideo/Rotate.go @@ -42,7 +42,7 @@ func RotateVideo(in GetFileInfo.BasicInfo, direction, threads string) { default: return } - cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-vf", transport, "-c:v", "libx265", "-c:a", "libvorbis", "-tag:v", "hvc1", "-threads", threads, out) + cmd = exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-vf", transport, "-c:v", "libx265", "-tag:v", "hvc1", "-threads", threads, out) err := util.ExecCommand(cmd) if err == nil { if err = os.RemoveAll(in.FullPath); err != nil { diff --git a/processVideo/h265.go b/processVideo/h265.go index 8bac142..9d84e03 100644 --- a/processVideo/h265.go +++ b/processVideo/h265.go @@ -69,7 +69,7 @@ func ProcessVideo2H265(in GetFileInfo.BasicInfo, threads string) { slog.Debug("", slog.String("out", out), slog.String("extName", in.PurgeExt)) mp4 := strings.Replace(out, in.PurgeExt, "mp4", -1) slog.Debug("调试", slog.String("输入文件", in.FullPath), slog.String("输出文件", mp4)) - cmd := exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-c:v", "libx265", "-c:a", "libvorbis", "-ac", "1", "-tag:v", "hvc1", "-map_chapters", "-1", "-threads", threads, mp4) + cmd := exec.Command("ffmpeg", "-threads", threads, "-i", in.FullPath, "-c:v", "libx265", "-ac", "1", "-tag:v", "hvc1", "-map_chapters", "-1", "-threads", threads, mp4) if mi.VideoWidth > 1920 && mi.VideoHeight > 1920 { slog.Warn("视频大于1080P需要使用其他程序先处理视频尺寸", slog.Any("原视频", in)) ResizeVideo(in, threads) diff --git a/processVideo/speedUp.go b/processVideo/speedUp.go index 9df1fdb..3c0855e 100644 --- a/processVideo/speedUp.go +++ b/processVideo/speedUp.go @@ -58,7 +58,7 @@ func speedUp(in, out string, speed string) { ff := audio2video(speed) pts := strings.Join([]string{"setpts=", ff, "*PTS"}, "") atempo := strings.Join([]string{"atempo", ff}, "=") - cmd := exec.Command("ffmpeg", "-i", in, "-filter:a", atempo, "-vf", pts, "-c:v", "libx265", "-c:a", "libvorbis", "-ac", "1", "-tag:v", "hvc1", out) + cmd := exec.Command("ffmpeg", "-i", in, "-filter:a", atempo, "-vf", pts, "-c:v", "libx265", "-ac", "1", "-tag:v", "hvc1", out) util.ExecCommand(cmd) if err := os.RemoveAll(in); err != nil { slog.Warn("删除失败", slog.String("源文件", in), slog.Any("错误内容", err))