duanbiaoshu2021 2017-08-15 01:59
浏览 387

Golang exec.Command()错误-通过Golang的ffmpeg命令

Currently working with this ffmpeg command to edit video

ffmpeg -i "video1.ts" -c:v libx264 -crf 20 -c:a aac -strict -2 "video1-fix.ts"

When I enter it in the terminal, it works. However when I try to use the Golang exec.Command() func, I get err response of

&{/usr/local/bin/ffmpeg [ffmpeg -i "video1.ts" -c:v libx264 -crf 20 -c:a aac -strict -2 "video1-fix.ts"] []  <nil> <nil> <nil> [] <nil> <nil> <nil> <nil> <nil> false [] [] [] [] <nil> <nil>}

Here below is my code

cmdArguments := []string{"-i", "\"video-1.ts\"", "-c:v", "libx264",
         "-crf", "20", "-c:a", "aac", "-strict", "-2", "\"video1-fix.ts\""}

err := exec.Command("ffmpeg", cmdArguments...)
fmt.Println(err)

Am i missing something from my command syntax? Not sure why it is not loading the videos

  • 写回答

1条回答 默认 最新

  • duanmao1975 2017-08-15 07:23
    关注

    as @JimB says, exec.Command does not return an error. Here is changed code from example https://golang.org/pkg/os/exec/#Command

    By the way you dont need to use "\"video-1.ts\"" - your quotes is shell feature.

    package main
    
    import (
        "bytes"
        "fmt"
        "log"
        "os/exec"
    )
    
    func main() {
        cmdArguments := []string{"-i", "video-1.ts", "-c:v", "libx264",
         "-crf", "20", "-c:a", "aac", "-strict", "-2", "video1-fix.ts"}
    
        cmd := exec.Command("tr", cmdArguments...)
    
        var out bytes.Buffer
        cmd.Stdout = &out
        err := cmd.Run()
        if err != nil {
            log.Fatal(err)
        }
        fmt.Printf("command output: %q
    ", out.String())
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置