Last active
May 29, 2022 14:13
-
-
Save ArseniySavin/04f3d50ff6f38bbb472dc2f715b1936f to your computer and use it in GitHub Desktop.
Getting first frame used ffmpeg. Read / Write into stdin /stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func FirstFrame(path string, data []byte) (*bufio.Reader, error) { | |
cmd := exec.Command(path, | |
"-i", "-", // read from stdin | |
"-vframes", fmt.Sprint(1), // frame | |
"-s", fmt.Sprintf("%dx%d", 640, 360), // size | |
"-q:v", fmt.Sprint(2), // quality | |
"-f", "singlejpeg", // jpeg binary | |
"-", // read from stdout | |
) | |
// stdin read | |
cmd.Stdin = bytes.NewBuffer(data) | |
var buffer bytes.Buffer | |
// stdout set buffer | |
cmd.Stdout = &buffer | |
if cmd.Run() != nil { | |
return nil, fmt.Errorf("Cannot run or found ffmpeg file by path: %s", path) | |
} | |
// reading of stdout | |
reader := bufio.NewReader(&buffer) | |
return reader, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It may be. I try many -f options, but correct work only singlejpeg.
Thank you. Your hint is useful.