fix: video issues
This commit is contained in:
@@ -22,16 +22,16 @@ func GetMediaDuration(path string) (int64, error) {
|
||||
}
|
||||
duration := string(durationOutput)
|
||||
duration = strings.TrimSpace(duration)
|
||||
durationInt, err := strconv.Atoi(duration)
|
||||
durationFloat, err := strconv.ParseFloat(duration, 64)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "duration conversion error")
|
||||
}
|
||||
return int64(durationInt), nil
|
||||
return int64(durationFloat), nil
|
||||
}
|
||||
|
||||
func CutMedia(input, output string, start, end int64) error {
|
||||
// ffmpeg -ss 00:00:00 -i input.mp4 -to 00:01:00 -c copy output.mp4
|
||||
cmd := exec.Command("ffmpeg", "-ss", strconv.FormatInt(start, 10), "-i", input, "-t", strconv.FormatInt(end, 10), "-c", "copy", output)
|
||||
cmd := exec.Command("ffmpeg", "-y", "-ss", strconv.FormatInt(start, 10), "-i", input, "-t", strconv.FormatInt(end, 10), "-c", "copy", output)
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
@@ -81,8 +81,8 @@ func CutMedia(input, output string, start, end int64) error {
|
||||
|
||||
// GetFrameImageFromVideo extracts target time frame from a video file and saves it as an image.
|
||||
func GetFrameImageFromVideo(input, output string, time int64) error {
|
||||
// ffmpeg -i input.mp4 -ss 00:00:01 -vframes 1 output.jpg
|
||||
cmd := exec.Command("ffmpeg", "-i", input, "-ss", strconv.FormatInt(time, 10), "-vframes", "1", output)
|
||||
// ffmpeg -y -i input.mp4 -ss 00:00:01 -vframes 1 output.jpg
|
||||
cmd := exec.Command("ffmpeg", "-y", "-i", input, "-ss", strconv.FormatInt(time, 10), "-vframes", "1", output)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "stdout pipe error")
|
||||
|
||||
Reference in New Issue
Block a user