Imagor instance to support both video and HTML previews
Find a file
Adrian Shum d6b3ec4bdc
feat(ffmpeg): seek and select frame by duration and float position (#39)
* feat(ffmpeg): seek by duration

* remove selected_frame

* test: update golden files

* remove selected_frame

* feat(ffmpeg): seek by duration

* feat(ffmpeg): seek by duration

* feat(ffmpeg): seek by duration

* feat(ffmpeg): seek by duration

* feat(ffmpeg): seek by duration

* test: update golden files

* feat(ffmpeg): seek by duration

* test: update golden files
2022-10-21 23:19:04 +08:00
.github chore: update sponsor button 2022-10-04 08:10:33 +08:00
cmd/imagorvideo feat: imagorvideo init 2022-09-08 20:44:10 +08:00
ffmpeg feat(ffmpeg): seek and select frame by duration and float position (#39) 2022-10-21 23:19:04 +08:00
testdata feat(ffmpeg): seek and select frame by duration and float position (#39) 2022-10-21 23:19:04 +08:00
.dockerignore feat: imagorvideo init 2022-09-08 20:44:10 +08:00
.gitignore feat: imagorvideo init 2022-09-08 20:44:10 +08:00
config.go feat: imagorvideo init 2022-09-08 20:44:10 +08:00
config_test.go test: ffmpeg processor tests 2022-09-16 14:21:56 +08:00
Dockerfile build: go 1.19.2 2022-10-06 14:45:15 +08:00
go.mod build: imagor 1.2.2 2022-10-18 10:59:46 +08:00
go.sum build: imagor 1.2.2 2022-10-18 10:59:46 +08:00
LICENSE feat: imagorvideo init 2022-09-08 20:44:10 +08:00
Makefile feat: imagorvideo init 2022-09-08 20:44:10 +08:00
option.go feat: imagorvideo init 2022-09-08 20:44:10 +08:00
processor.go feat(ffmpeg): seek and select frame by duration and float position (#39) 2022-10-21 23:19:04 +08:00
processor_test.go feat(ffmpeg): seek and select frame by duration and float position (#39) 2022-10-21 23:19:04 +08:00
README.md feat(ffmpeg): seek and select frame by duration and float position (#39) 2022-10-21 23:19:04 +08:00

imagorvideo

Test Status Coverage Status Docker Hub GitHub Container Registry

imagorvideo is a new initiative that brings video thumbnail capability through ffmpeg, built on the foundations of 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 read stream for mkv and webm video types. For other video types that requires seeking from a non seek-able source such as HTTP or S3, it simulates seek using memory or temp file as buffer.

This also aims to be a reference project demonstrating imagor extension.

Quick Start

docker run -p 8000:8000 shumc/imagorvideo -imagor-unsafe

Original:

http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

Result:

http://localhost:8000/unsafe/300x0/7x7/filters:label(imagorvideo,-10,-7,20,yellow):fill(yellow)/http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

imagorvideo

imagorvideo works by streaming out a limited number of frame data, looping through and calculating the histogram of each frame. It then choose the best frame for imaging, based on root-mean-square error (RMSE). This allow skipping the black frames that usually occur at the beginning of videos.

imagorvideo then converts the selected frame to RGB image data, forwards to the imagor libvips processor, which has always been best at image processing with tons of features. Check out imagor documentations for all the image options supported.

Filters

imagorvideo supports the following filters, which can be used in conjunction with imagor filters:

  • frame(n) specifying the frame index n for imaging. This allows skipping the default automatic selection, which involves computing root-mean-square error (RMSE) of histogram frames data.
  • max_frames(n) restrict the maximum number of frames allocated for image selection. The smaller the number, the faster the processing time.

Example:

http://localhost:8000/unsafe/300x0/7x7/filters:max_frames(70):fill(yellow)/http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

Metadata

imagorvideo provides metadata endpoint that extracts video metadata, dimension and duration data. By default, it only process the header without extracting the frame data for better processing speed.

To use the metadata endpoint, add /meta right after the URL signature hash before the image operations:

http://localhost:8000/unsafe/meta/https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_30MB.mp4

Appending the max_frames() or frame(n) filter however, would activate frame processing. This results more processing time but would also allows retrieving frame related info such as frames per second fps:

http://localhost:8000/unsafe/meta/filters:max_frames()/https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_30MB.mp4
{
  "format": "mp4",
  "content_type": "video/mp4",
  "orientation": 1,
  "duration": 10000,
  "width": 1920,
  "height": 1080,
  "title": "Big Buck Bunny, Sunflower version",
  "artist": "Blender Foundation 2008, Janus Bager Kristensen 2013",
  "fps": 30, // available only if frame processing activated
  "has_video": true,
  "has_audio": false
}

Configuration

Config options specific to imagorvideo. Please refer to imagor configuration for all existing options supported.

  -ffmpeg-fallback-image string
        FFmpeg fallback image on processing error. Supports image path enabled by loaders or storages