Skip to content

Commit

Permalink
h265视频不设置crf最节省空间
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyiming748 committed Aug 9, 2024
1 parent 31b191c commit a7feadc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions conv/Resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ func Resize(in mediainfo.BasicInfo, p string) {
dst = strings.Join([]string{dst, "resize"}, string(os.PathSeparator)) //二级目录
fname := replace.ForFileName(in.PurgeName) //仅文件名
fname = strings.Join([]string{fname, "mp4"}, ".")
os.Mkdir(dst, 0777)
_ = os.Mkdir(dst, 0777)
log.Printf("输出文件夹:%v\n", dst)
out := strings.Join([]string{dst, fname}, string(os.PathSeparator))
log.Printf("源文件:%v\t目标文件:%v\n", in.FullPath, out)
var cmd *exec.Cmd
switch p {
case "1920x1080":
cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1080", "-c:v", "libvpx-vp9", "-crf", "31", "-c:a", "libvorbis", "-ac", "1", out)
cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1080", "-c:v", "libx265", "-c:a", "libopus", "-ac", "1", out)
case "1080x1920":
cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1920", "-c:v", "libvpx-vp9", "-crf", "31", "-c:a", "libvorbis", "-ac", "1", out)
cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-strict", "-2", "-vf", "scale=-1:1920", "-c:v", "libx265", "-c:a", "libopus", "-ac", "1", out)
case "1920x1920":
cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-strict", "-2", "-vf", "scale=1920:1920", "-c:v", "libvpx-vp9", "-crf", "31", "-c:a", "libvorbis", "-ac", "1", out)
cmd = exec.Command("ffmpeg", "-i", in.FullPath, "-strict", "-2", "-vf", "scale=1920:1920", "-c:v", "libx265", "-c:a", "libopus", "-ac", "1", out)
default:
log.Fatalf("不正常的视频源:%v\n", in.FullPath)
}
Expand Down
4 changes: 2 additions & 2 deletions conv/Rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func RotateVideo(in mediainfo.BasicInfo, direction string) {
in.InsertVideoInfo()
log.Printf("插入细节信息后:%v\n", in)
dst := strings.Join([]string{in.PurgePath, "rotate"}, string(os.PathSeparator))
os.Mkdir(dst, os.ModePerm)
_ = os.Mkdir(dst, os.ModePerm)
FrameCount := ""
for _, v := range in.VInfo.Media.Track {
if v.Type == "Video" {
Expand Down Expand Up @@ -58,7 +58,7 @@ func RotateVideo(in mediainfo.BasicInfo, direction string) {
log.Printf("没有查询到crf,使用默认crf:%v\n", crf)
}
log.Printf("获取到的crf=%v\n", crf)
cmd = exec.Command("ffmpeg", "-y", "-i", in.FullPath, "-vf", transport, "-c:v", "libx265", "-crf", crf, "-c:a", "libvorbis", "-ac", "1", "-map_chapters", "-1", out)
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)
Expand Down

0 comments on commit a7feadc

Please sign in to comment.