fix: probe issues
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user