FFmpeg
使用 FFmpeg 实现 视频转码、缩略图、获取时长
转码
转码为 h264 mp4 文件
ffmpeg:
ffmpeg: /opt/homebrew/bin/ffmpeg
ffprobe: /opt/homebrew/bin/ffprobe
command_timeout: 1h
package main
import (
"github.com/langwan/langgo"
"github.com/langwan/langgo/components/ffmpeg"
)
func main() {
langgo.Run(&ffmpeg.Instance{})
ffmpeg.Get().Transcoding("../../../samples/sample.mov", "./output.mp4", true)
}
生成缩略图
ffmpeg:
ffmpeg: /opt/homebrew/bin/ffmpeg
ffprobe: /opt/homebrew/bin/ffprobe
command_timeout: 1h
package main
import (
"github.com/langwan/langgo"
"github.com/langwan/langgo/components/ffmpeg"
"time"
)
func main() {
langgo.Run(&ffmpeg.Instance{})
ffmpeg.Get().Thumbnail("../../../samples/sample.mov", "./output.jpg", time.Second, true)
}
获取视频时长
package main
import (
"fmt"
"github.com/langwan/langgo"
"github.com/langwan/langgo/components/ffmpeg"
)
func main() {
langgo.Run(&ffmpeg.Instance{})
duration, err := ffmpeg.Get().Duration("../../../samples/sample.mov")
if err != nil {
return
}
fmt.Println(duration)
}
12.96s
Last updated