3

I want to convert my mp4 file to gif format. I was used the command that is working in command prompt. i.e., converting my .mp4 into gif but in go lang it is not done anything. Here is my command:

ffmpeg -i Untitled.mp4 -vf "fps=5,scale=320:-1:flags=lanczos" -c:v pam -f image2pipe - | convert -delay 5 - -loop 0 -layers optimize test.gif

I was used in go lang like this but it is not working. please any one help me to solve my problem.

    cmd3 := exec.Command("ffmpeg", "-i", "Untitled.mp4", "-vf", "`fps=5,scale=320:-1:flags=lanczos`", "-c:v", "pam", "-f", "image2pipe", "- |", "convert", "-delay", "5", "-", "-loop", "0", "-layers", "optimize", "test.gif")

stdout2, err2 := cmd3.StdoutPipe()
log.Println("gif", stdout2)

if err2 != nil {
    log.Fatal(err2, "............")
}
if err2 := cmd3.Start(); err2 != nil {
    log.Fatal(err2)
}

if any changes is there please inform me thanks in advance.

1
  • Perfect answer saved my time thanks Jan 6, 2022 at 14:23

1 Answer 1

1

This is not exactly what you are looking for, but it is possible to do it like this:

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    cmd := "ffmpeg -i Untitled.mp4 -vf \"fps=5,scale=320:-1:flags=lanczos\" -c:v pam -f image2pipe - | convert -delay 5 - -loop 0 -layers optimize test.gif"
    _, err := exec.Command("bash","-c",cmd).Output()
    if err != nil {
        fmt.Println(fmt.Sprintf("Failed to execute command: %s", cmd))
    }
}
1
  • 1
    Its working thank you
    – v teja
    Jan 7, 2022 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.