英文:
Convert .mp4 to gif using ffmpeg in golang
问题
我想将我的mp4文件转换为gif格式。我之前在命令提示符中使用了一个命令,可以将我的.mp4文件转换为gif,但在Go语言中却没有任何效果。以下是我的命令:
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
我在Go语言中尝试了以下方式,但没有效果。请有人帮助我解决这个问题。
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)
}
如果有任何更改,请告诉我,提前感谢。
英文:
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
得分: 1
这不完全是你要找的,但可以这样做:
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("执行命令失败:%s", cmd))
}
}
希望对你有所帮助!
英文:
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))
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论