fix: probe issues

This commit is contained in:
Rogee
2025-03-31 15:09:12 +08:00
parent 2c7a873953
commit f52eab00b0
4 changed files with 21 additions and 4 deletions

View File

@@ -263,9 +263,10 @@ func compressVideo(srcPath, dstPath string) error {
}
log.Infof("video size: %dx%d", width, height)
cmd := exec.Command("ffmpeg", "-i", srcPath, "-c:v", "libx264", "-crf", "23", "-r", "25", "-c:a", "copy", fmt.Sprintf("'%s'", dstPath))
// cmd := exec.Command("ffmpeg", "-i", srcPath, "-c:v", "libx264", "-crf", "23", "-r", "25", "-c:a", "copy", fmt.Sprintf("'%s'", dstPath))
cmd := exec.Command("sh", "-c", fmt.Sprintf("ffmpeg -i '%s' -c:v libx264 -crf 23 -r 25 -c:a copy '%s'", srcPath, dstPath))
if width > 1920 || height > 1080 {
cmd = exec.Command("ffmpeg", "-i", fmt.Sprintf("'%s'", srcPath), "-c:v", "libx264", "-crf", "23", "-r", "25", "-c:a", "copy", "-vf", "scale=1920:1080", fmt.Sprintf("'%s'", dstPath))
cmd = exec.Command("sh", "-c", fmt.Sprintf("ffmpeg -i '%s' -c:v libx264 -crf 23 -r 25 -c:a copy -vf scale=1920:1080 '%s'", srcPath, dstPath))
}
var stderr bytes.Buffer
cmd.Stderr = &stderr
@@ -281,7 +282,7 @@ func compressVideo(srcPath, dstPath string) error {
func getVideoSize(filePath string) (int, int, error) {
var stderr bytes.Buffer
cmd := exec.Command("ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=height,width", "-of", "default=noprint_wrappers=1:nokey=1", fmt.Sprintf("'%s'", filePath))
cmd := exec.Command("sh", "-c", fmt.Sprintf("ffprobe -v error -select_streams v:0 -show_entries stream=height,width -of default=noprint_wrappers=1:nokey=1 '%s'", filePath))
cmd.Stderr = &stderr
out, err := cmd.Output()
if err != nil {

View File

@@ -33,3 +33,19 @@ func Test_compressVideo(t *testing.T) {
})
})
}
func Test_runCommand(t *testing.T) {
Convey("runCommand", t, func() {
Convey("test ffprobe", func() {
file := "/mnt/yangpingliang/publish/原唱《义烈女》庄兄你一席话义重情长(杨红霞).mp4"
if _, err := os.Stat(file); os.IsNotExist(err) {
t.Fatalf("File does not exist: %s", file)
}
width, height, err := getVideoSize(file)
So(err, ShouldBeNil)
So(width, ShouldNotBeZeroValue)
So(height, ShouldNotBeZeroValue)
})
})
}

View File

@@ -32,6 +32,7 @@ require (
github.com/soheilhy/cmux v0.1.5
github.com/speps/go-hashids/v2 v2.0.1
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
github.com/swaggo/files/v2 v2.0.2
github.com/uber/jaeger-client-go v2.30.0+incompatible
go.ipao.vip/atom v1.1.8
@@ -126,7 +127,6 @@ require (
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/viper v1.20.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect

BIN
backend/quyun Executable file

Binary file not shown.