Skip to content

Commit

Permalink
libvorbis音轨不属于通用格式 放弃
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyiming748 committed Feb 12, 2024
1 parent 05e3518 commit a4249b9
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 13 deletions.
6 changes: 3 additions & 3 deletions conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions count/count.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package count

var num uint64

func GetNum() uint64 {
return num
}

func AddNum() {
num++
}
func SubNum() {
num--
}
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"processAll/GetAllFolder"
"processAll/GetFileInfo"
"processAll/alert"
"processAll/count"
"processAll/merge"
"processAll/processAudio"
"processAll/processImage"
Expand Down Expand Up @@ -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())}, "<br>")
i.SetText(text)
summary := strings.Join([]string{"共成功转换", fmt.Sprint(count.GetNum(), "个文件")}, "")
i.AppendText(summary)
for _, s := range ss {
i.AppendText(s)
}
Expand Down
9 changes: 9 additions & 0 deletions processImage/avif.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"processAll/GetFileInfo"
"processAll/count"
"processAll/mediaInfo"
"processAll/replace"
"processAll/util"
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion processVideo/PAL.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions processVideo/Resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion processVideo/Rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion processVideo/h265.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion processVideo/speedUp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit a4249b9

Please sign in to comment.