title: Running FFMPEG command through Golang exec
body: <p>I need to run an <a href="https://ffmpeg.org/" rel="nofollow noreferrer">ffmpeg</a> command to create a video from images with a crossfade between images as the transition. The command is derived from this <a href="https://superuser.com/questions/833232/create-video-with-5-images-with-fadein-out-effect-in-ffmpeg/834035">post</a>. I need to run it through the Golang <a href="https://golang.org/pkg/os/exec/" rel="nofollow noreferrer">os/exec</a> package. The command I need to run is:</p>
  
  <pre><code>ffmpeg -loop 1 -t 5 -i img-0.png -loop 1 -t 5 -i img-1.png -loop 1 -t 5 -i img-2.png -filter_complex "[1:v][0:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b1v];[2:v][1:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b2v];[0:v][b1v][1:v][b2v][2:v]concat=n=5:v=1:a=0,format=yuv420p[v]" -map '[v]' -c:v libx264 -pix_fmt yuv420p -r 30 -s 1280x720 -aspect 16:9 -crf 1 -preset ultrafast output.mp4
  </code></pre>
  
  <p>If you run this command directly in the terminal, it works just fine. However, it does not work through my code. This is my code that takes a string command and runs it through the <a href="https://golang.org/pkg/os/exec/" rel="nofollow noreferrer">os/exec</a> package:</p>
  
  <pre><code>command := "ffmpeg -loop 1 -t 5 -i img-0.png -loop 1 -t 5 -i img-1.png -loop 1 -t 5 -i img-2.png -filter_complex "[1:v][0:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b1v];[2:v][1:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b2v];[0:v][b1v][1:v][b2v][2:v]concat=n=5:v=1:a=0,format=yuv420p[v]" -map '[v]' -c:v libx264 -pix_fmt yuv420p -r 30 -s 1280x720 -aspect 16:9 -crf 1 -preset ultrafast output.mp4"
  
  lastQuote := rune(0)
  f := func(c rune) bool {
      switch {
      case c == lastQuote:
          lastQuote = rune(0)
          return false
      case lastQuote != rune(0):
          return false
      case unicode.In(c, unicode.Quotation_Mark):
          lastQuote = c
          return false
      default:
          return unicode.IsSpace(c)
      }
  }
  parts := strings.FieldsFunc(command, f)
  
  cmd := exec.Command(parts[0], parts[1:]...)
  cmd.Stderr = os.Stderr
  cmd.Stdout = os.Stdout
  
  err := cmd.Run()
  if err != nil {
      return err
  }
  </code></pre>
  
  <p>When I run this, I get the ffmpeg error: No such filter: '"', Error configuring filters. I know it has something to do with the quotes that HAVE to be in the video filters, but I have tried everything to get it to work and I can't figure it out. </p>
  
  <p>Any help is greatly appreciated!</p>