I am trying to decode a bmp image using the image and golang.org/x/image/bmp libraries. The image is output by ffmpeg into stdout. This is the code to get the frame:
cmd := exec.Command("ffmpeg", "-accurate_seek", "-ss", strconv.Itoa(index), "-i",
filename, "-frames:v", "1", "-hide_banner", "-loglevel", "0", "pipe:.bmp")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
o := bufio.NewReader(&out)
and then I decode it using img, _, err := image.Decode(o)
However this gives an error of "image: unknown format". I have already registered the bmp format in the main method, and I have successfully decoded actual BMP files from disk previously, just not from stdout.
I have tried just using bmp.Decode instead of image.Decode but this just gives the error "EOF".
I thought maybe I was not getting the stdout in the correct way, but if I just write it straight to a file:
o := bufio.NewReader(&out)
outputfile, err := os.Create("test.bmp")
if err != nil {
log.Fatal(err)
}
defer outputfile.Close()
io.Copy(outputfile, o)
then it works fine and I can open it.
Edit: code