vid2gif 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c76ffb4af0de09b6b1091d4d9b3b1f6216982f25
4
+ data.tar.gz: 880ab43898254520cb38279e225635df422d8e02
5
+ SHA512:
6
+ metadata.gz: b544c2fce166797172425bdd3fe74935865303d6aca716964a9b5cc54ad1e0dd742a46d16344dc2b2776210981be820484ec9817bacb535c513d4bde97d0662a
7
+ data.tar.gz: 0f36c0ed042e1712dad6443bd8e2568ede24f1a0ae9f9621d71c689fa52e4390b38393adc12c521ca947ce7d548ce16c8fdb8b3d93a6744e79ff3ef460b8f62b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vid2gif.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jeff Sandberg
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Vid2gif
2
+
3
+ Useful, but simple, little script for generating animated gifs on the command line.
4
+
5
+ Uses ffmpeg to do the heavy lifting, all the script really does is take options in one end and feeds em to ffmpeg.
6
+
7
+ # Installation
8
+ You need to have ffmpeg installed first, then its as simple as `gem install vid2gif`.
9
+
10
+ ## OS X with Homebrew
11
+ ```
12
+ brew install ffmpeg
13
+ gem install vid2gif
14
+ ```
15
+
16
+ # Basic usage
17
+ The gem is pretty easy to use:
18
+
19
+ `vid2gif -r 500 yourvideo.mp4` produces a gif, scaled to 500px wide, named `yourvideo.gif`
20
+
21
+ For more detailed help, see `vid2gif -h`
22
+
23
+ # license
24
+ ```
25
+ The MIT License (MIT)
26
+
27
+ Copyright (c) 2015 Jeff Sandberg
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ of this software and associated documentation files (the "Software"), to deal
31
+ in the Software without restriction, including without limitation the rights
32
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ copies of the Software, and to permit persons to whom the Software is
34
+ furnished to do so, subject to the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included in
37
+ all copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
45
+ THE SOFTWARE.
46
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'chronic_duration'
5
+ require 'open3'
6
+
7
+ options = {}
8
+
9
+ dither_setting = {
10
+ bayer1: 'bayer:bayer_scale=1',
11
+ bayer2: 'bayer:bayer_scale=2',
12
+ bayer3: 'bayer:bayer_scale=3',
13
+ heckbert: 'heckbert',
14
+ floyd_steinberg: 'floyd_steinberg',
15
+ sierra2: 'sierra2',
16
+ sierra24: 'sierra2_4a'
17
+ }
18
+ OptionParser.new do |opts|
19
+ opts.banner = 'Usage: vid2gif [options] filename.mp4'
20
+
21
+ opts.separator ''
22
+ opts.separator 'Video options:'
23
+
24
+ opts.on('-s', '--start TIME', 'Video Start timecode', ' h:m:s.sss form, for ffmpeg') do |time|
25
+ options[:start] = ChronicDuration.parse(time)
26
+ end
27
+
28
+ opts.on('-t', '--time TIME', Float, 'Duration of video/gif') do |time|
29
+ options[:duration] = time
30
+ end
31
+
32
+ opts.on('-e', '--end TIME', 'Video end timecode') do |time|
33
+ fail ArgumentError, 'Duration (-t) must be nil to use end timecode' unless options[:duration].nil?
34
+ e = ChronicDuration.parse(time)
35
+ s = options[:start] || 0
36
+ options[:duration] = e - s
37
+ end
38
+
39
+ opts.separator ''
40
+ opts.separator 'Gif output options:'
41
+
42
+ opts.on('-r', '--size SIZE', /(-?\d+)(?:x(-?\d+))?/, 'WIDTH[xHEIGHT]', ' Use -1 to preserve aspect ratio (ex -1x200 for a gif 200px tall and whatever wide)') do |_, width, height|
43
+ options[:width] = width
44
+ options[:height] = height
45
+ end
46
+
47
+ opts.on('-f', '--fps FRAMERATE', Float, 'Framerate of output gif', ' Defaults to video\'s framerate') do |fps|
48
+ options[:framerate] = fps
49
+ end
50
+
51
+ opts.on('-o', '--output FILENAME', 'gif output name. Defaults to input name') do |filename|
52
+ options[:filename] = filename
53
+ end
54
+
55
+ opts.separator ''
56
+ opts.separator 'Stuff for nerds'
57
+
58
+ opts.on('-d', '--diff', 'use diff for stats_mode setting in palettegen.', ' tl;dr: favor whats moving for palette') do |diff|
59
+ options[:diff] = diff
60
+ end
61
+
62
+ opts.on('--dither MODE', dither_setting.keys, 'Dither settings.', ' Consult ffmpeg manual for details') do |dither|
63
+ options[:dither] = dither_setting[dither]
64
+ end
65
+
66
+ opts.on '--dmr', '--diff-mode-rectangle', 'Enable diff-mode: rectangle for dithering', ' Can lead to smaller files' do |dmr|
67
+ options[:diff_mode] = dmr
68
+ end
69
+
70
+ opts.separator ''
71
+ opts.separator 'Other stuff:'
72
+
73
+ opts.on_tail('-h', '--help', 'Show this message') do
74
+ puts opts
75
+ exit
76
+ end
77
+
78
+ opts.on_tail('-v', '--version', 'Show the version') do
79
+ puts Vid2gif::Version
80
+ exit
81
+ end
82
+ end.parse!
83
+
84
+ palette = Tempfile.new(['gif_palette', '.gif'])
85
+
86
+ filters = []
87
+ filters << "fps=#{options[:fps]}" if options[:fps]
88
+
89
+ # rubocop:disable Style/ParenthesesAroundCondition
90
+ filters << 'scale=%s:%s:flags=lanczos' % [options[:width] || -1, options[:height] || -1] if (options[:width] || options[:height])
91
+ # rubocop:enable Style/ParenthesesAroundCondition
92
+
93
+ palettegen_filters = 'palettegen'
94
+ palettegen_filters << '=stats_mode=diff' if options[:diff]
95
+
96
+ arguments = []
97
+ arguments << "-ss #{options[:start]}" if options[:start]
98
+ arguments << "-t #{options[:duration]}" if options[:duration]
99
+ arguments << "-i #{ARGV[0]}"
100
+
101
+ puts "Generating palette\n"
102
+ Open3.popen2e(['ffmpeg', *arguments, "-vf #{filters.dup.push(palettegen_filters).join(',')}", "-y #{palette.path}"].join(' ')) do |_, output, _|
103
+ puts output.read
104
+ end
105
+
106
+ paletteuse_filters_string = 'paletteuse'
107
+ paletteuse_filters = []
108
+ paletteuse_filters << "dither=#{options[:dither]}" if options[:dither]
109
+ paletteuse_filters << 'diff_mode=rectangle' if options[:diff_mode]
110
+ paletteuse_filters_string += "=#{paletteuse_filters.join(':')}" unless paletteuse_filters.empty?
111
+
112
+ filename = options[:filename] || File.basename(ARGV[0], '.*') + '.gif'
113
+
114
+ if filters.empty?
115
+ filter_command = "[0:v][1:v] #{paletteuse_filters_string}"
116
+ else
117
+ filter_command = "#{filters.join(',')} [x]; [x][1:v] #{paletteuse_filters_string}"
118
+ end
119
+ puts "Generating gif\n"
120
+ Open3.popen2e(['ffmpeg', *arguments, "-i #{palette.path}", "-lavfi \"#{filter_command}\"", "-y #{filename}"].join(' ')) do |_, output, _|
121
+ puts output.read
122
+ end
123
+
124
+ palette.unlink
125
+
126
+ puts "Gif created at #{filename}"
@@ -0,0 +1 @@
1
+ require "vid2gif/version"
@@ -0,0 +1,3 @@
1
+ module Vid2gif
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vid2gif/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vid2gif'
8
+ spec.version = Vid2gif::VERSION
9
+ spec.authors = ['Jeff Sandberg']
10
+ spec.email = ['paradox460@gmail.com']
11
+
12
+ spec.summary = 'A simple command-line tool for making gifs out of videos'
13
+ spec.description = 'Simple tool based around ffmpeg for making gifs out of videos, from the command line.'
14
+ spec.homepage = 'http://github.com/paradox460/vid2gif'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'bin'
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.10'
31
+
32
+ spec.add_runtime_dependency 'chronic_duration', '~> 0.10.0'
33
+
34
+ spec.requirements << 'ffmpeg 2.7.2 or above'
35
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vid2gif
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Sandberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chronic_duration
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ description: Simple tool based around ffmpeg for making gifs out of videos, from the
42
+ command line.
43
+ email:
44
+ - paradox460@gmail.com
45
+ executables:
46
+ - vid2gif.rb
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/vid2gif.rb
56
+ - lib/vid2gif.rb
57
+ - lib/vid2gif/version.rb
58
+ - vid2gif.gemspec
59
+ homepage: http://github.com/paradox460/vid2gif
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ allowed_push_host: https://rubygems.org
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements:
79
+ - ffmpeg 2.7.2 or above
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.5.1
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A simple command-line tool for making gifs out of videos
85
+ test_files: []
86
+ has_rdoc: