Skip to content

Commit

Permalink
fix: incomplete data caused by buffer pool
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Nov 30, 2024
1 parent 2d2008f commit 348c0a3
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions common/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,7 @@ func CompressImageForTelegramByFFmpegFromBytes(input []byte, maxDepth uint, extr
}
vfKwArg := ffmpeg.KwArgs{"vf": fmt.Sprintf("scale=%d:%d:flags=lanczos", newWidth, newHeight)}

buf := imageBufferPool.Get().(*bytes.Buffer)
buf.Reset()
defer func() {
buf.Reset()
imageBufferPool.Put(buf)
}()
if buf.Cap() < inputLen {
buf.Grow(inputLen - buf.Cap())
}
buf := bytes.NewBuffer(nil)

err = ffmpeg.Input("pipe:").Output("pipe:", vfKwArg, ffmpeg.KwArgs{"format": "mjpeg"}, ffmpeg.MergeKwArgs(extraFFmpegKwArgs)).WithInput(bytes.NewReader(input)).WithOutput(buf).Run()

Expand Down

0 comments on commit 348c0a3

Please sign in to comment.