fix: fix compress command

This commit is contained in:
yanghao05
2025-03-31 14:39:02 +08:00
parent 0bc301b224
commit 2c7a873953
2 changed files with 23 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package commands package commands
import ( import (
"bytes"
"crypto/md5" "crypto/md5"
"encoding/json" "encoding/json"
"fmt" "fmt"
@@ -262,13 +263,16 @@ func compressVideo(srcPath, dstPath string) error {
} }
log.Infof("video size: %dx%d", width, height) 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("%q", dstPath)) cmd := exec.Command("ffmpeg", "-i", srcPath, "-c:v", "libx264", "-crf", "23", "-r", "25", "-c:a", "copy", fmt.Sprintf("'%s'", dstPath))
if width > 1920 || height > 1080 { if width > 1920 || height > 1080 {
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)) 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))
} }
var stderr bytes.Buffer
cmd.Stderr = &stderr
log.Infof("executing command: %s", cmd.String()) log.Infof("executing command: %s", cmd.String())
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Errorf("stderr: %s", stderr.String())
return errors.Wrapf(err, "failed to execute compress command: %s", cmd.String()) return errors.Wrapf(err, "failed to execute compress command: %s", cmd.String())
} }
@@ -276,9 +280,12 @@ func compressVideo(srcPath, dstPath string) error {
} }
func getVideoSize(filePath string) (int, int, 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", fmt.Sprintf("%q", filePath)) 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.Stderr = &stderr
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
log.Errorf("stderr: %s", stderr.String())
return 0, 0, errors.Wrapf(err, "failed to execute command: %s", cmd.String()) return 0, 0, errors.Wrapf(err, "failed to execute command: %s", cmd.String())
} }
lines := strings.Split(string(out), "\n") lines := strings.Split(string(out), "\n")

View File

@@ -1,10 +1,19 @@
{ {
"folders": [ "folders": [
{ {
"path": "backend" "path": "backend",
"name": "Backend",
}, },
{ {
"path": "frontend/admin" "path": "frontend/admin",
}, "name": "Admin"
] }
],
"settings": {
"github.copilot.chat.codeGeneration.instructions": [
{
"file": "./.vscode/daisyui.md"
}
]
}
} }