1
votes

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
exec.Command returns a *Cmd, not an error.JimB

1 Answers

3
votes

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\n", out.String())
}