fix: seeker initialization
* fix: seeker initialization * fix: seeker initialization
This commit is contained in:
parent
84851a7776
commit
73cbcf1069
4 changed files with 7 additions and 21 deletions
|
|
@ -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 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.
|
||||
|
||||
|
|
|
|||
22
processor.go
22
processor.go
|
|
@ -79,26 +79,12 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
|
|||
out = in
|
||||
return
|
||||
}
|
||||
var r io.ReadCloser
|
||||
var rs io.ReadSeekCloser
|
||||
var size = in.Size()
|
||||
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 {
|
||||
rs, size, err := in.NewReadSeeker()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if r == nil {
|
||||
if rs, size, err = in.NewReadSeeker(); err != nil {
|
||||
return
|
||||
}
|
||||
r = rs
|
||||
}
|
||||
defer func() {
|
||||
_ = r.Close()
|
||||
_ = rs.Close()
|
||||
}()
|
||||
if size <= 0 && rs != nil {
|
||||
// size must be known
|
||||
|
|
@ -109,7 +95,7 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
|
|||
return
|
||||
}
|
||||
}
|
||||
av, err := ffmpeg.LoadAVContext(r, size)
|
||||
av, err := ffmpeg.LoadAVContext(rs, size)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 176 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 312 KiB |
Loading…
Add table
Add a link
Reference in a new issue