golang 使用ffmpeg获取video的任意帧
func GetFrame(
index int)
*bytes.Buffer {
filename :=
"test.mp4"
width :=
2752
height :=
2208
// cmd :=
exec.Command(
"ffmpeg",
"-i", filename,
"-vframes", strconv.Itoa(
index),
"-s", fmt.Sprintf(
"%dx%d", width, height),
"-f",
"singlejpeg",
"-")
cmd :=
exec.Command(
"ffmpeg",
"-i", filename,
"-vframes",
"1",
"-s", fmt.Sprintf(
"%dx%d", width, height),
"-f",
"singlejpeg",
"-")
buf := new(bytes.Buffer)
cmd.Stdout = buf
if cmd.Run() != nil {
panic(
"could not generate frame")
}
return buf
}