MCPcopy Index your code
hub / github.com/cshum/imagorvideo

github.com/cshum/imagorvideo @v1.1.15

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.15 ↗ · + Follow
104 symbols 328 edges 16 files 30 documented · 29%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

imagorvideo

Test Status Codecov Docker Hub

imagorvideo is a new initiative that brings video thumbnail capability through ffmpeg, built on the foundations of imagor - a fast, secure image processing server and Go library, using libvips.

imagorvideo uses ffmpeg C bindings that extracts video thumbnail by selecting the best frame from a RMSE histogram. It then goes through the rest of imagor pipeline to perform image cropping, resizing and filters.

imagorvideo implements ffmpeg read and seek I/O callbacks with imagor loader, storage and result storage, which supports HTTP(s), File System, AWS S3 and 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.

Quick Start

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

Docker Variants

imagorvideo publishes three Docker image families:

  • ghcr.io/cshum/imagorvideo: default ffmpeg variant. This is the recommended baseline and matches the default imagorvideo Dockerfile.
  • ghcr.io/cshum/imagorvideo-mozjpeg: mozjpeg-ffmpeg variant. Use this when you want the MozJPEG-backed JPEG stack in addition to video thumbnail support.
  • ghcr.io/cshum/imagorvideo-magick: magick-ffmpeg variant. Use this when you need ImageMagick-backed formats or operations on top of the ffmpeg pipeline.

All three variants keep ffmpeg support. The difference is the underlying imagor native image stack used after frame extraction.

Original:

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

Result:

http://localhost:8000/unsafe/300x0/7x7/filters:label(imagorvideo,-10,-7,15,yellow):fill(yellow)/http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
http://localhost:8000/unsafe/300x0/0x0:0x14/filters:frame(1m59s):fill(yellow):label(imagorvideo,center,bottom,12,black,20)/http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
http://localhost:8000/unsafe/300x0/7x7/filters:frame(0.6):label(imagorvideo,10,-7,15,yellow):fill(yellow)/http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

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 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 endpoint and security for image operations supported.

Filters

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

  • frame(n) specify the position or time duration for imaging, which skips the automatic best frame selection:
  • Float between 0.0 and 1.0 position index of the video. Example frame(0.5), frame(1.0)
  • Time duration of the elapsed time since the start of video. Example frame(5m1s), frame(200s)
  • seek(n) seeks to the approximate position or time duration, then perform automatic best frame selection around that point:
  • Float between 0.0 and 1.0 position index of the video. Example seek(0.5)
  • Time duration of the elapsed time since the start of video. Example seek(5m1s), seek(200s)
  • max_frames(n) restrict the maximum number of frames allocated for image selection. The smaller the number, the faster the processing time.

frame(n) vs seek(n)

There are differences you may want to choose one over the other. frame(n) gives you the precise time frame specified. However, precise may not be the best in some circumstances:

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

Retrieving the frame at 5 minutes elapsed time of this video:

http://localhost:8000/unsafe/filters:frame(5m)/http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

It results a complete black frame.

black

This is where seek(n) comes handy. It seeks to the key frame before the 5 minutes elapsed time, then perform best frame selection starting from that point using Root Mean Square Error (RMSE) histogram. The result is a reasonable image that sits close to the specified time:

http://localhost:8000/unsafe/filters:seek(5m)/http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

seek 5m

Metadata

imagorvideo provides metadata endpoint that extracts video metadata, including dimension, duration and FPS data. It processes header only, 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
{
  "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,
  "has_video": true,
  "has_audio": false
}

Configuration

Configuration options specific to imagorvideo. Please see imagor configuration for all existing options available.

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

Extension points exported contracts — how you extend this code

Option (FuncType)
Option imagorvideo option
option.go
LoggingHandlerFunction (FuncType)
(no doc)
ffmpeg/logging.go

Core symbols most depended-on inside this repo

Close
called by 10
ffmpeg/ffmpeg.go
ProcessFrames
called by 8
ffmpeg/ffmpeg.go
LoadAVContext
called by 7
ffmpeg/ffmpeg.go
Error
called by 7
ffmpeg/errors.go
SelectFrame
called by 6
ffmpeg/ffmpeg.go
Startup
called by 5
processor.go
WithLogger
called by 5
option.go
SelectDuration
called by 5
ffmpeg/ffmpeg.go

Shape

Function 64
Method 21
Struct 9
Class 5
FuncType 3
TypeAlias 2

Languages

Go76%
C21%
C++3%

Modules by API surface

ffmpeg/ffmpeg.go30 symbols
ffmpeg/ffmpeg.c20 symbols
processor_test.go15 symbols
ffmpeg/ffmpeg_test.go7 symbols
processor.go6 symbols
ffmpeg/logging.go6 symbols
option.go4 symbols
ffmpeg/callback.go4 symbols
ffmpeg/ffmpeg.h3 symbols
ffmpeg/errors.go3 symbols
ffmpeg/logging.c2 symbols
ffmpeg/errors_test.go1 symbols

For agents

$ claude mcp add imagorvideo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact