feat: fix command issues

This commit is contained in:
yanghao05
2025-03-29 18:48:34 +08:00
parent 4cdda96d6e
commit 0bc301b224

View File

@@ -262,9 +262,9 @@ 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", dstPath)
cmd := exec.Command("ffmpeg", "-i", srcPath, "-c:v", "libx264", "-crf", "23", "-r", "25", "-c:a", "copy", fmt.Sprintf("%q", dstPath))
if width > 1920 || height > 1080 {
cmd = exec.Command("ffmpeg", "-i", srcPath, "-c:v", "libx264", "-crf", "23", "-r", "25", "-c:a", "copy", "-vf", "scale=1920:1080", dstPath)
cmd = exec.Command("ffmpeg", "-i", fmt.Sprintf("%q", srcPath), "-c:v", "libx264", "-crf", "23", "-r", "25", "-c:a", "copy", "-vf", "scale=1920:1080", fmt.Sprintf("%q", dstPath))
}
log.Infof("executing command: %s", cmd.String())
@@ -276,7 +276,7 @@ func compressVideo(srcPath, dstPath string) error {
}
func getVideoSize(filePath string) (int, int, error) {
cmd := exec.Command("ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=height,width", "-of", "default=noprint_wrappers=1:nokey=1", filePath)
cmd := exec.Command("ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=height,width", "-of", "default=noprint_wrappers=1:nokey=1", fmt.Sprintf("%q", filePath))
out, err := cmd.Output()
if err != nil {
return 0, 0, errors.Wrapf(err, "failed to execute command: %s", cmd.String())