fix: seeker initialization

* fix: seeker initialization

* fix: seeker initialization
This commit is contained in:
Adrian Shum 2022-10-22 14:48:45 +08:00 committed by GitHub
parent 84851a7776
commit 73cbcf1069
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 21 deletions

View file

@ -7,9 +7,9 @@
imagorvideo is a new initiative that brings video thumbnail capability through ffmpeg, built on the foundations of [imagor](https://github.com/cshum/imagor) - a fast, Docker-ready image processing server written in Go with libvips. imagorvideo is a new initiative that brings video thumbnail capability through ffmpeg, built on the foundations of [imagor](https://github.com/cshum/imagor) - a fast, Docker-ready image processing server written in Go with libvips.
imagorvideo uses ffmpeg C bindings that extracts image thumbnail from video, by attempting to select the best frame. It then forwards to libvips to perform all the image cropping, resizing and filters supported by imagor. imagorvideo uses ffmpeg C bindings that extracts image thumbnail from video, by attempting to select the best frame. It then forwards to libvips to perform all the image cropping, resizing and filters provided by imagor.
imagorvideo integrates ffmpeg AVIOContext with imagor [loader, storage and result storage](https://github.com/cshum/imagor#loader-storage-and-result-storage), which supports HTTP(s), S3, Google Cloud Storage out of box. It uses read stream for mkv and webm video types. For other video types that requires seeking from a non seek-able source such as HTTP, it simulates seek using memory or temp file as buffer. imagorvideo integrates ffmpeg AVIOContext read and seek callbacks with imagor [loader, storage and result storage](https://github.com/cshum/imagor#loader-storage-and-result-storage), which supports HTTP(s), S3, Google Cloud Storage out of box. For non seek-able source such as HTTP and S3, imagor simulates seek using memory or temp file buffer.
This also aims to be a reference project demonstrating imagor extension. This also aims to be a reference project demonstrating imagor extension.

View file

@ -79,26 +79,12 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
out = in out = in
return return
} }
var r io.ReadCloser rs, size, err := in.NewReadSeeker()
var rs io.ReadSeekCloser if err != nil {
var size = in.Size() return
if size > 0 {
switch mime.String() {
case "video/webm", "video/x-matroska":
// media types that does not require seek
if r, _, err = in.NewReader(); err != nil {
return
}
}
}
if r == nil {
if rs, size, err = in.NewReadSeeker(); err != nil {
return
}
r = rs
} }
defer func() { defer func() {
_ = r.Close() _ = rs.Close()
}() }()
if size <= 0 && rs != nil { if size <= 0 && rs != nil {
// size must be known // size must be known
@ -109,7 +95,7 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
return return
} }
} }
av, err := ffmpeg.LoadAVContext(r, size) av, err := ffmpeg.LoadAVContext(rs, size)
if err != nil { if err != nil {
return return
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 176 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 KiB

After

Width:  |  Height:  |  Size: 312 KiB

Before After
Before After