diff --git a/backend/app/service/commands/compress.go b/backend/app/service/commands/compress.go index f1b3a23..0bdc74c 100644 --- a/backend/app/service/commands/compress.go +++ b/backend/app/service/commands/compress.go @@ -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 { diff --git a/backend/app/service/commands/compress_test.go b/backend/app/service/commands/compress_test.go index aa82219..44ee36b 100644 --- a/backend/app/service/commands/compress_test.go +++ b/backend/app/service/commands/compress_test.go @@ -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) + }) + }) +} diff --git a/backend/go.mod b/backend/go.mod index 29022b5..fc89c53 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -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 diff --git a/backend/quyun b/backend/quyun new file mode 100755 index 0000000..ffd50f3 Binary files /dev/null and b/backend/quyun differ