• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    Go
  • Created over 10 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A server for transcoding gif to video on the fly

gifserver

gifserver is a service written in Go that transcodes GIFs to videos on the fly. Useful for displaying user uploaded GIFs on a website without incurring slowdowns from excess bandwidth.

The server is a wrapper around ffmpeg, you must have the ffmpeg command installed on your system.

The server will automatically cache transcoded GIFs to disk so subsequent requests will avoid the initial conversion time. The server is aware of what's currently being converted so multiple requests to the same GIF during a conversion do not trigger multiple conversions.

Install

go get github.com/leafo/gifserver

gifserver -help

Running

gifserver

By default the command will look for a config file named gifserver.json in the current directory. You can override the config file's path with the -config command line flag.

To transcode a GIF just request the server at the /transcode path with the URL of the GIF you would like converted: (The http:// is optional):

http://localhost:9090/transcode?url=leafo.net/dump/test.gif

The type of video will be detected from the Accept header. If nothing could be detected a MP4 is returned by default. If there are any problems an HTTP 500 error is returned and the server returns an error message.

The /transcode path takes the following query parameters:

  • url the url of the gif to load (required)
  • format the format to transcode to, either mp4, ogv, png (optional)

Using png as the format will return an image that has the first frame of the GIF.

Config

A JSON file is used to configure the server. The default config is as follows:

{
	"Address": ":9090",
	"Secret": "",
	"CacheDir": "gifcache",
	"MaxBytes": 5242880,
	"MaxWidth": 512,
	"MaxHeight": 512,
	"MaxConcurrency": 0
}

Your config can replace any combination of the defaults with your own values.

  • Address the address to bind the server to
  • Secret secret key to use for singed URLs. If "" is the secret key then signed URLs are disabled
  • CacheDir where to cache transcoded GIFs
  • MaxBytes the max size of GIF in bytes allowed to be processed, setting to 0 disabled
  • MaxWidth the max width of GIF that can be processed, setting to 0 disables
  • MaxHeight the max width of GIF that can be processed, setting to 0 disables
  • MaxConcurrency the max number of transcodes that can be in process at once, additional ones are queued. Setting to 0 disables

Signed URLs

You should used signed URLs whenever possible to avoid malicious users from triggering a denial-of-service-attack on your server by sending a large amount of conversion requests.

To enable signed URLs provide a Secret in your config file. The server uses SHA1 HMAC to generate signatures for URLs. Generating the signature is relatively simple:

Given the following request to transcode a GIF:

http://localhost:9090/transcode?url=leafo.net/dump/test.gif

Take the entire path and query from the URL an perform a SHA1 HMAC digest on it. Base64 encode the sum. Then append the URL escaped signature to the end of the URL as the query parameter sig:

sum = hmac_sha1(theSecret, "/transcode?url=leafo.net/dump/test.gif")
signature = encode_base64(sum)

signed_url = url + "&sig=" + url_escape(signature)

Then perform the request with the signed URL. You should always append the signature at the end of the URL. You must not change the order of the original query parameters in any way when appending the signature otherwise the signature is invalid.

Preventing Abuse

A few config options to prevent malicious GIFs from blocking the server are included.

MaxBytes, MaxWidth, and MaxHeight should all be set to reasonable values to prevent large images from being loaded and taking up a large amount of memory.

MaxConcurrency should be set to prevent an influx of trascode requests from taking over the CPU.

About

Author: Leaf Corcoran (leafo) (@moonscript)
Email: [email protected]
Homepage: http://leafo.net
License: MIT, Copyright (C) 2014 by Leaf Corcoran

More Repositories

1

moonscript

πŸŒ™ A language that compiles to Lua
Lua
3,026
star
2

lapis

A web framework for Lua and OpenResty written in MoonScript
MoonScript
2,923
star
3

sticky-kit

A jQuery plugin for creating smart sticky elements
CoffeeScript
2,908
star
4

lessphp

LESS compiler written in PHP
PHP
2,210
star
5

scssphp

SCSS compiler written in PHP
PHP
1,351
star
6

sightreading.training

🎹 Sight reading training tool
JavaScript
443
star
7

magick

Lua bindings to ImageMagick for LuaJIT using FFI
Lua
404
star
8

pgmoon

A pure Lua Postgres driver for use in OpenResty & more
MoonScript
393
star
9

gifine

Quickly record and edit gifs and videos of your desktop
Lua
285
star
10

etlua

Embedded Lua templates
Lua
219
star
11

aroma

a game engine: lua, opengl es 2.0, native client
C
197
star
12

streak.club

a website for running creative streaks
MoonScript
142
star
13

tableshape

Test the shape or structure of a Lua table, inspired by React.PropTypes & LPeg
MoonScript
112
star
14

lovekit

Miscellaneous code for making games in LOVE with MoonScript
Lua
96
star
15

moonscript-vim

MoonScript support for vim
Vim Script
96
star
16

lua-enet

Bindings to ENet for Lua
C
85
star
17

gh-actions-lua

GitHub action for Lua/LuaJIT
JavaScript
83
star
18

heroku-openresty

Run OpenResty on Heroku with the Lua buildpack
Lua
78
star
19

sitegen

static site generator in MoonScript
Lua
76
star
20

lua-payments

Various payment provider APIs for Lua (and OpenResty): Stripe, PayPal
MoonScript
72
star
21

web_sanitize

Lua library for sanitizing, parsing, and editing untrusted HTML
MoonScript
70
star
22

moonlisp

a Lisp that compiles to Lua
C
67
star
23

scssphp-compass

Compass for scssphp
PHP
66
star
24

image-server-tutorial

An example of an image processing server in OpenResty and Lua
Lua
66
star
25

compohub

A website for listing game jams
CoffeeScript
62
star
26

lua-openai

OpenAI API bindings for Lua
MoonScript
52
star
27

lapis-community

Pluggable message board for Lapis powered websites
MoonScript
49
star
28

goattracker2

a fork of goattracker2
C
45
star
29

itchio-app-old

Desktop itch.io client
C++
45
star
30

gh-actions-luarocks

GitHub action for installing LuaRocks
JavaScript
43
star
31

loadkit

Loadkit allows you to load arbitrary files within the Lua package path
MoonScript
42
star
32

lapis-console

Interactive console for working with Lapis
Lua
42
star
33

cloud_storage

A Lua library for communicating with Google Cloud Storage
Lua
40
star
34

moonscript-javascript

MoonScript compiled to JavaScript with Emscripten
JavaScript
38
star
35

moonscript-tmbundle

textmate support for MoonScript
37
star
36

lapis-bayes

Naive Bayes classifier for use in Lua
MoonScript
30
star
37

moonrocks

command line tool for working with rocks.moonscript.org
Lua
29
star
38

lua-twitter

A Lua twitter library that works with OpenResty or LuaSocket
Lua
27
star
39

lua-mailgun

Lua bindings to Mailgun HTTP API
MoonScript
26
star
40

ludum-dare-browser

a website for browsing ludum dare games
HTML
25
star
41

lapis-redis

Redis integration for Lapis
Lua
23
star
42

lua-syntaxhighlight

A code syntax to HTML highlighter using lexers from Textadept
Lua
21
star
43

luajit-geoip

luajit bindings to maxmind geoip
MoonScript
21
star
44

lapis-systemd

systemd integration for lapis
Lua
18
star
45

lapis-exceptions

Exception tracking for Lapis
MoonScript
17
star
46

moonscript-javascript-compiler

compile moonscript to javascript
MoonScript
16
star
47

mursic

sight reading training tool
MoonScript
15
star
48

lapis-site

The homepage for Lapis
HTML
14
star
49

lua-date

LuaDate 2 modified to work with newer versions of lua/luajit
Lua
14
star
50

lua-base58

base58 decode and encode for strings in pure lua
MoonScript
13
star
51

moondoc

MoonScript library documentation generator
Lua
13
star
52

lapis-archlinux-docker

Dockerfile for running lapis in archlinux
Dockerfile
13
star
53

moonscript-love

LΓ–VE game engine with baked in moonscript support
C
13
star
54

lua-uinput

A Lua library for creating a virtual keyboard on Linux with uinput
MoonScript
13
star
55

ludum-dare-22

A game built in 48 hours for the Ludum Dare Competition
12
star
56

moonscript-site

CSS
11
star
57

heroku-lapis-example

An example of running Lapis on Heroku with heroku-openresty
Lua
11
star
58

imagesize

Detect size & format of image file
MoonScript
10
star
59

ludum-dare-27

theme: 10 seconds
MoonScript
9
star
60

ludum-dare-38

lets make a game "a small world"
MoonScript
9
star
61

ludum-dare-25

Make a game in 48 hours!
MoonScript
9
star
62

moonscript-textadept

Textadept support for MoonScript
MoonScript
9
star
63

saltw-bot

irc/twitch bot written in MoonScript
MoonScript
9
star
64

lapis-stats

Statsd and Influxdb support for Lua, OpenResty & Lapis
Lua
8
star
65

selfwatch

inspired by selfspy
Go
8
star
66

snes-renoise-instruments

Various snes samples ripped from spc -> xrni
8
star
67

lapis-spec-screenshot

A busted screenshot handler that takes images of your pages when testing
Lua
8
star
68

ludum-dare-24

Let's make a video game!
7
star
69

giflib

gif
MoonScript
7
star
70

garfield

garfield comic viewer 🐱
MoonScript
7
star
71

weeklyloops

loops for http://streak.club/s/134/weekly-loop
Go
7
star
72

lapis-annotate

Annotate lapis models with their schema from the database
Lua
7
star
73

moonscrape

web scraper
MoonScript
6
star
74

lessphp-site

the lessphp homepage
PHP
6
star
75

lapis-eswidget

A widget base class designed for generating ES modules for bundling JavaScript & more
MoonScript
5
star
76

wallrun-js

Trying to get love2d game working in browser using fengari
MoonScript
5
star
77

elng

an interpreted language running on erlang
Erlang
5
star
78

dullcache

A simple large file cache for sitting in front of storage provider to offload bandwidth
Go
5
star
79

ludum-dare-32

Something butt
MoonScript
4
star
80

uglyphp

a templating language for php with emphasis on macros
PHP
4
star
81

fireplace

GTK+ campfire client
Python
4
star
82

album-1

my first album, chiptune
4
star
83

net.leafo.MIDIThing

Control your MIDI modules from Renoise
TeX
4
star
84

gh-actions-openresty

Install OpenResty inside of your GitHub Actions runner
JavaScript
4
star
85

ludum-dare-23

make a game in 48 hours!
4
star
86

talkxtyper

Type with your voice
Go
4
star
87

workdad

a chorded keyboard layout and training program
MoonScript
3
star
88

lapis-http

HTTP library wrangler for OpenResty & Lua
MoonScript
3
star
89

somestory

lets make a game for real this time....
Lua
3
star
90

ludum-dare-30

Connected worlds
Lua
3
star
91

pixel-react

creating pixelated game interface with html in react
JavaScript
3
star
92

st

my terminal
Objective-C
3
star
93

awesome-config

My awesome configuration
Lua
2
star
94

godot-game-1

GDScript
2
star
95

ludum-dare-41

combine two genres
GDScript
2
star
96

noteshed

a personal wiki for notes
2
star
97

ludum-dare-31

Entire Game on One Screen
MoonScript
2
star
98

ludum-dare-40

Lets make another game
Lua
2
star
99

moonparse

MoonScript
2
star
100

gslog2pg

Copy Google Cloud storage logs into PostgreSQL
MoonScript
2
star