Skip to content

Commit d97d542

Browse files
committed
1.0.0
0 parents  commit d97d542

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
npm-debug.log
3+
node_modules
4+
*.js

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.coffee

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Tomáš Hanáček
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# To GIF
2+
3+
Convert video to gif
4+
5+
## Installation
6+
7+
```
8+
npm install togif
9+
```
10+
11+
## Example
12+
13+
```
14+
var toGif = require 'togif'
15+
16+
var input = path.resolve(__dirname, 'test.mp4')
17+
var output = path.resolve(__dirname, 'test.gif')
18+
var ffmpeg = path.resolve(__dirname, 'ffmpeg')
19+
20+
toGif(input, output, {ffmpeg: ffmpeg}, function(err) {
21+
console.log(err)
22+
})
23+
24+
```

example.coffee

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
toGif = require './'
2+
path = require 'path'
3+
4+
5+
input = path.resolve(__dirname, 'test.mp4')
6+
output = path.resolve(__dirname, 'test.gif')
7+
ffmpeg = path.resolve(__dirname, 'ffmpeg')
8+
convert = path.resolve(__dirname, 'convert')
9+
10+
toGif input, output, {ffmpeg, convert}, (err) ->
11+
console.log(err)

index.coffee

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{exec} = require 'child_process'
2+
escape = require 'shell-escape'
3+
path = require 'path'
4+
temp = require('temp').track()
5+
6+
7+
togif = (input, output, options, callback) ->
8+
rate = options.rate or 10
9+
delay = options.delay or 'auto'
10+
ffmpeg = options.ffmpeg or 'ffmpeg'
11+
convert = options.convert or 'convert'
12+
13+
if delay is 'auto'
14+
delay = 1000 / rate / 100 | 0
15+
16+
input = escape([input])
17+
output = escape([output])
18+
19+
temp.mkdir {}, (err, tempDir) ->
20+
return callback(err) if err
21+
22+
tempPath = path.join(tempDir, '/%04d.png')
23+
24+
cmd = [ffmpeg]
25+
cmd.push('-i', input)
26+
cmd.push('-r', String(rate))
27+
cmd.push(tempPath)
28+
cmd = cmd.join(' ')
29+
30+
exec cmd, (err) ->
31+
return callback(err) if err
32+
33+
cmd = [convert]
34+
cmd.push('+dither')
35+
cmd.push('-layers', 'Optimize')
36+
cmd.push('-delay', String(delay))
37+
cmd.push(path.join(tempDir, '/*.png'))
38+
cmd.push(output)
39+
cmd = cmd.join(' ')
40+
41+
exec(cmd, callback)
42+
43+
module.exports = togif

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "togif",
3+
"version": "1.0.0",
4+
"description": "Convert video to gif",
5+
"main": "index.js",
6+
"author": "Tomas Hanacek <tomas.hanacek1@gmail.com>",
7+
"license": "MIT",
8+
"keywords": [
9+
"video",
10+
"gif",
11+
"osx"
12+
],
13+
"dependencies": {
14+
"shell-escape": "^0.2.0",
15+
"temp": "^0.8.1"
16+
},
17+
"devDependencies": {
18+
"coffee-script": "^1.9.3"
19+
},
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/tomashanacek/togif"
23+
},
24+
"bugs": {
25+
"url": "https://github.com/tomashanacek/togif/issues"
26+
},
27+
"homepage": "https://github.com/tomashanacek/togif",
28+
"scripts": {
29+
"prepublish": "coffee -c index.coffee",
30+
"postpublish": "rm index.js"
31+
}
32+
}

0 commit comments

Comments
 (0)