vrtk 0.0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +35 -0
- data/Gemfile.lock +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/setup +8 -0
- data/bin/vrtk +10 -0
- data/src/vrtk/app.rb +86 -0
- data/src/vrtk/applets/all.rb +4 -0
- data/src/vrtk/applets/base_applet.rb +47 -0
- data/src/vrtk/applets/clipper_applet.rb +70 -0
- data/src/vrtk/applets/collager_applet.rb +89 -0
- data/src/vrtk/clipper/clipper_error.rb +6 -0
- data/src/vrtk/clipper/ffmpeg.rb +59 -0
- data/src/vrtk/clipper/font_finder.rb +48 -0
- data/src/vrtk/clipper/video_clipper.rb +85 -0
- data/src/vrtk/collager/collager.rb +139 -0
- data/src/vrtk/config.rb +11 -0
- data/src/vrtk/utils/utils.rb +26 -0
- data/src/vrtk/version.rb +3 -0
- data/src/vrtk.rb +4 -0
- data/vrtk.gemspec +22 -0
- metadata +67 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 60dde66ce7137992d6519c05f968a0722c2621ce
|
|
4
|
+
data.tar.gz: 6f31e89c64304c6bf3aa6b16c83a73639d4e912c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4899d30eb74a812d54b119c363b28112d22c0a621c682ada3470bb43f299e98865244dba3a0e451a5e989550ee094b2ec26ccaeb1cb0ce2431381c71c397608e
|
|
7
|
+
data.tar.gz: e6d3a24dc701fea801093a84fe8f0bc8e467cbb9eead13bd624cc7501675c44338f9a8ea806899596ccdf32c39a5d407a89ff5a190b22995873ec9172ba2adf0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
6
|
+
|
|
7
|
+
gemspec
|
|
8
|
+
|
|
9
|
+
group :video_clipper do
|
|
10
|
+
require 'ostruct'
|
|
11
|
+
require 'logger'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
group :collager do
|
|
15
|
+
require 'ostruct'
|
|
16
|
+
require 'logger'
|
|
17
|
+
gem 'mini_magick'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
group :ffmpeg do
|
|
21
|
+
require 'ostruct'
|
|
22
|
+
require 'logger'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
group :applets do
|
|
27
|
+
require 'ostruct'
|
|
28
|
+
require 'optparse'
|
|
29
|
+
require 'logger'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
group :app do
|
|
33
|
+
gem 'colorize'
|
|
34
|
+
require 'optparse'
|
|
35
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
vrtk (0.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
colorize (0.8.1)
|
|
10
|
+
mini_magick (4.8.0)
|
|
11
|
+
|
|
12
|
+
PLATFORMS
|
|
13
|
+
x64-mingw32
|
|
14
|
+
|
|
15
|
+
DEPENDENCIES
|
|
16
|
+
colorize
|
|
17
|
+
mini_magick
|
|
18
|
+
vrtk!
|
|
19
|
+
|
|
20
|
+
BUNDLED WITH
|
|
21
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# VRTK - Video Releaser's Toolkit
|
|
2
|
+
|
|
3
|
+
VRTK is designed to help people who works with video publishing.
|
|
4
|
+
Currently it can:
|
|
5
|
+
* create video preview screenshots
|
|
6
|
+
* create screenlists (collage)
|
|
7
|
+
* more features soon!
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
#### Windows
|
|
12
|
+
|
|
13
|
+
Install Ruby 2.4 from [RubyInstaller](http://rubyinstaller.org).
|
|
14
|
+
Also, download [FFMpeg](http://ffmpeg.org/download.html) and [ImageMagick](http://imagemagick.org/script/download.php#windows).
|
|
15
|
+
FFMpeg from ImageMagick is not suitable since it doesn't have `ffprobe` program.
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install vrtk
|
|
20
|
+
|
|
21
|
+
If install succeeds,
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vrtk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
40
|
+
|
|
41
|
+
## Code of Conduct
|
|
42
|
+
|
|
43
|
+
Everyone interacting in the Vrtk project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/vrtk/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/setup
ADDED
data/bin/vrtk
ADDED
data/src/vrtk/app.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative 'config'
|
|
4
|
+
require_relative 'version'
|
|
5
|
+
|
|
6
|
+
Bundler.require :app
|
|
7
|
+
|
|
8
|
+
module VRTK
|
|
9
|
+
class App
|
|
10
|
+
def initialize(argv = ARGV)
|
|
11
|
+
@argv = argv
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
begin
|
|
16
|
+
__exec
|
|
17
|
+
rescue VRTKError => error
|
|
18
|
+
STDERR.print 'ERROR: '.colorize :red
|
|
19
|
+
STDERR.puts error.message.colorize :blue
|
|
20
|
+
STDERR.puts 'Exited.'.colorize :blue
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def __exec
|
|
25
|
+
|
|
26
|
+
opt_parse
|
|
27
|
+
|
|
28
|
+
applet = ARGV.shift
|
|
29
|
+
|
|
30
|
+
no_applet unless applet
|
|
31
|
+
|
|
32
|
+
raise VRTKError, "Applet '#{applet}' is unavailable!" unless VRTK::Config::APPLETS[applet]
|
|
33
|
+
|
|
34
|
+
applet = VRTK::Config::APPLETS[applet].new @argv
|
|
35
|
+
|
|
36
|
+
applet.run
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def opt_parse
|
|
40
|
+
OptionParser.new do |opts|
|
|
41
|
+
opts.banner = banner
|
|
42
|
+
|
|
43
|
+
opts.on('-?', '--help', 'See this help') do |_|
|
|
44
|
+
puts opts
|
|
45
|
+
exit 0
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
opts.on('-v', '--version', 'Print version') do |_|
|
|
49
|
+
puts "VRTK #{VRTK::VERSION}"
|
|
50
|
+
exit 0
|
|
51
|
+
end
|
|
52
|
+
end.parse!
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def banner
|
|
58
|
+
<<END
|
|
59
|
+
-== Video Releaser's toolkit ==-
|
|
60
|
+
Usage: #{$PROGRAM_NAME} <applet>
|
|
61
|
+
Applets:
|
|
62
|
+
#{get_applets}
|
|
63
|
+
Options:
|
|
64
|
+
END
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def no_applet
|
|
68
|
+
STDERR.print 'ERROR: '.colorize(:red)
|
|
69
|
+
STDERR.puts "invalid usage!\nCall #{$0} --help.".colorize :blue
|
|
70
|
+
exit 0
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def get_applets
|
|
74
|
+
text = []
|
|
75
|
+
VRTK::Config::APPLETS.each do |_, applet|
|
|
76
|
+
text << <<END
|
|
77
|
+
#{applet.id}
|
|
78
|
+
#{applet.name}
|
|
79
|
+
#{applet.desc}
|
|
80
|
+
END
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
text.join $\
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative '../../vrtk'
|
|
4
|
+
|
|
5
|
+
Bundler.require :applets
|
|
6
|
+
|
|
7
|
+
module VRTK::Applets
|
|
8
|
+
class BaseApplet
|
|
9
|
+
def initialize(argv = ARGV)
|
|
10
|
+
@argv = argv
|
|
11
|
+
|
|
12
|
+
@applet = {
|
|
13
|
+
name: name,
|
|
14
|
+
id: id,
|
|
15
|
+
desc: desc,
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
op = init_options
|
|
20
|
+
op.parse! argv
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def init_options
|
|
24
|
+
OptionParser.new do |opts|
|
|
25
|
+
opts.banner = "#{@applet.name}\n#{@applet.desc}\n\nUsage: vrtk #{@applet.id} [options]"
|
|
26
|
+
|
|
27
|
+
opts.on('-?', '--help') do |v|
|
|
28
|
+
puts opts
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def run
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.name
|
|
37
|
+
'Applet'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.id
|
|
41
|
+
'applet'
|
|
42
|
+
end
|
|
43
|
+
def self.desc
|
|
44
|
+
'The Applet gives no description.'
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative '../../vrtk'
|
|
4
|
+
require_relative 'base_applet'
|
|
5
|
+
require_relative '../clipper/video_clipper'
|
|
6
|
+
|
|
7
|
+
Bundler.require :applets
|
|
8
|
+
|
|
9
|
+
module VRTK::Applets
|
|
10
|
+
|
|
11
|
+
class ClipperApplet < BaseApplet
|
|
12
|
+
def init_options
|
|
13
|
+
|
|
14
|
+
@options = OpenStruct.new({})
|
|
15
|
+
|
|
16
|
+
OptionParser.new do |opts|
|
|
17
|
+
|
|
18
|
+
opts.banner = "-== #{name} ==-\n#{desc}\nUsage: #{$PROGRAM_NAME} #{id} [options]"
|
|
19
|
+
|
|
20
|
+
opts.on('-?', '--help', 'This message') do |_|
|
|
21
|
+
puts opts
|
|
22
|
+
exit 0
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
opts.on('-i', '--input <file>', 'File to get previews from') do |v|
|
|
26
|
+
@options.input = v
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
opts.on('-n', '--count <n>', 'Number of previews that will be generated (+-1)') do |v|
|
|
30
|
+
@options.count = v.to_i
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
opts.on('-q', '--silent', 'Do not generate additional output') do |v|
|
|
34
|
+
@options.silent = v
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
opts.on('-o', '--output <dir>', 'Dir where generated files will be stored') do |v|
|
|
38
|
+
@options.output_dir = v
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def run
|
|
45
|
+
|
|
46
|
+
raise VRTK::Clipper::ClipperError, 'no input file specified!' unless @options.input
|
|
47
|
+
|
|
48
|
+
VRTK::VideoClipper.new(
|
|
49
|
+
input_file: @options.input,
|
|
50
|
+
clips_count: @options.count,
|
|
51
|
+
output_dir: @options.output_dir,
|
|
52
|
+
logger: Logger.new(STDERR, level: (@options.silent ? Logger::Severity::FATAL : Logger::Severity::INFO))
|
|
53
|
+
)
|
|
54
|
+
.perform
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.name
|
|
59
|
+
'VideoClipper applet'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.desc
|
|
63
|
+
'Extracts screenshots from video.'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.id
|
|
67
|
+
'clipper'
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative '../../vrtk'
|
|
4
|
+
require_relative 'base_applet'
|
|
5
|
+
require_relative '../collager/collager'
|
|
6
|
+
|
|
7
|
+
Bundler.require :applets
|
|
8
|
+
|
|
9
|
+
module VRTK::Applets
|
|
10
|
+
|
|
11
|
+
class CollagerApplet < BaseApplet
|
|
12
|
+
|
|
13
|
+
include VRTK::Collage
|
|
14
|
+
|
|
15
|
+
WILDCARDS = "(wildcards allowed, '%' instead of '*', '\#' instead of '?')"
|
|
16
|
+
|
|
17
|
+
def init_options
|
|
18
|
+
|
|
19
|
+
@options = OpenStruct.new({})
|
|
20
|
+
|
|
21
|
+
OptionParser.new do |opts|
|
|
22
|
+
|
|
23
|
+
opts.banner = "-== #{name} ==-\n#{desc}\nUsage: #{$PROGRAM_NAME} #{id} [options]"
|
|
24
|
+
|
|
25
|
+
opts.on('-?', '--help', 'This message') do |v|
|
|
26
|
+
puts opts
|
|
27
|
+
exit 0
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
opts.on('-a', '--add <filemask>', "Add files to collage #{WILDCARDS}") do |v|
|
|
31
|
+
files = Dir[Utils.to_wildcard(v)]
|
|
32
|
+
@options.files += files
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
opts.on('-x', '--exclude <filemask>', "Exclude files from collage #{WILDCARDS}") do |v|
|
|
36
|
+
files = Dir[Utils.to_wildcard(v)]
|
|
37
|
+
@options.files -= files
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
opts.on('-l', '--file-limit <n>', "If specified, only first 'n' files are used.") do |v|
|
|
41
|
+
@options.file_limit = v.to_i
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
opts.on('-r', '--tile-ratio <size>', "One tile's side ratio. If not specified, 16x9 ratio is used.") do |v|
|
|
45
|
+
sz = v.split('x').map &:to_i
|
|
46
|
+
|
|
47
|
+
raise CollagerError, 'Invalid ratio!' if sz.size != 2
|
|
48
|
+
sz.each { |a| raise CollagerError, 'Invalid ratio!' unless a > 0 }
|
|
49
|
+
|
|
50
|
+
@options.ratio = sz
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
opts.on('-o', '--output <file>', 'Output file. If not specified, out.jpeg is used.') do |v|
|
|
54
|
+
@options.output = v
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
opts.on('-w', '--width <width>', 'Output collage width. If not specified, 1200 is used.') do |v|
|
|
58
|
+
@options.width = v.to_i
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def run
|
|
65
|
+
|
|
66
|
+
raise CollagerError, 'no input file specified!' unless @options.input
|
|
67
|
+
|
|
68
|
+
VRTK::Collager.new(
|
|
69
|
+
input_file: @options.files,
|
|
70
|
+
output_file: @options.output,
|
|
71
|
+
tile_ratio: @options.ratio,
|
|
72
|
+
collage_width: @options.width
|
|
73
|
+
)
|
|
74
|
+
.perform
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.name
|
|
78
|
+
'Collager applet'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.desc
|
|
82
|
+
'Generates grid-like collage from input images'
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def self.id
|
|
86
|
+
'collager'
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative '../../vrtk'
|
|
4
|
+
require_relative '../utils/utils'
|
|
5
|
+
|
|
6
|
+
Bundler.require :ffmpeg
|
|
7
|
+
|
|
8
|
+
module VRTK::Clipper
|
|
9
|
+
|
|
10
|
+
class FFMpegError < VRTK::VRTKError;
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class FFMpeg
|
|
14
|
+
include VRTK
|
|
15
|
+
|
|
16
|
+
PREDEF_PATHS = %W(#{Dir.pwd}/bin #{Dir.pwd}/ffmpeg #{Dir.pwd}/ffmpeg/bin)
|
|
17
|
+
|
|
18
|
+
def self.resolve
|
|
19
|
+
if ENV['OS'].downcase.start_with? 'windows'
|
|
20
|
+
resolve_ffmpeg_windows
|
|
21
|
+
else
|
|
22
|
+
resolve_ffmpeg_unknown
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.resolve_ffmpeg_unknown
|
|
27
|
+
raise FFMpegError, "Can't resolve FFMPEG correctly"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# noinspection RubyScope
|
|
33
|
+
def self.resolve_ffmpeg_windows
|
|
34
|
+
search = (Utils.get_binpath + PREDEF_PATHS).map { |v| File.absolute_path v }
|
|
35
|
+
|
|
36
|
+
mpeg = nil
|
|
37
|
+
probe = nil
|
|
38
|
+
|
|
39
|
+
search.each do |path|
|
|
40
|
+
mp = "#{path}/ffmpeg.exe" unless mpeg
|
|
41
|
+
pb = "#{path}/ffprobe.exe" unless probe
|
|
42
|
+
|
|
43
|
+
mpeg = mp if mp and File.exists? mp
|
|
44
|
+
probe = pb if pb and File.exists? pb
|
|
45
|
+
|
|
46
|
+
break if mpeg and probe
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
raise FFMpegError, "Can't resolve ffmpeg.exe" unless mpeg
|
|
50
|
+
raise FFMpegError, "Can't resolve ffprobe.exe" unless probe
|
|
51
|
+
|
|
52
|
+
OpenStruct.new ({
|
|
53
|
+
ffmpeg: Utils.to_wpath(mpeg),
|
|
54
|
+
ffprobe: Utils.to_wpath(probe)
|
|
55
|
+
})
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative '../../vrtk'
|
|
4
|
+
require_relative '../utils/utils'
|
|
5
|
+
|
|
6
|
+
Bundler.require :video_clipper
|
|
7
|
+
|
|
8
|
+
module VRTK::Clipper
|
|
9
|
+
|
|
10
|
+
class FontFinderError < VRTK::VRTKError;
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class FontFinder
|
|
14
|
+
|
|
15
|
+
DEFAULT_DIRS = ['.', File.dirname(__FILE__)]
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
#
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.find_font(name)
|
|
22
|
+
if ENV['OS'].downcase.strip.start_with? 'windows'
|
|
23
|
+
find_font_windows name
|
|
24
|
+
else
|
|
25
|
+
raise FontFinderError, "couldn't find font '#{name}'"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def self.find_font_windows(name)
|
|
32
|
+
dirs = DEFAULT_DIRS
|
|
33
|
+
dirs << (Utils.to_upath "#{ENV['WINDIR']}\\Fonts")
|
|
34
|
+
|
|
35
|
+
files = []
|
|
36
|
+
|
|
37
|
+
dirs.each do |dir|
|
|
38
|
+
files = Dir["#{dir}/*#{name}*.ttf"]
|
|
39
|
+
break if files.size > 0
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
raise FontFinderError, "couldn't find font '#{name}'" unless files.size > 0
|
|
43
|
+
|
|
44
|
+
(File.absolute_path(files[0]))
|
|
45
|
+
.gsub(':', '\\:')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative 'ffmpeg'
|
|
4
|
+
require_relative 'font_finder'
|
|
5
|
+
require_relative '../utils/utils'
|
|
6
|
+
require_relative 'clipper_error'
|
|
7
|
+
|
|
8
|
+
Bundler.require :video_clipper
|
|
9
|
+
|
|
10
|
+
STDNUL = (File.open(File::NULL, 'w'))
|
|
11
|
+
|
|
12
|
+
module VRTK
|
|
13
|
+
|
|
14
|
+
class VideoClipper
|
|
15
|
+
|
|
16
|
+
include VRTK::Clipper
|
|
17
|
+
include VRTK::Utils
|
|
18
|
+
|
|
19
|
+
CMD_DURATION = "%{ffprobe} -show_format -i \"%{input_file}\" -v 0 | sed -n \"s/duration=//p\""
|
|
20
|
+
CMD_CLIPS = "%{ffmpeg} -v 0 -i \"%{input_file}\" -vframes %{count} -vf \"drawtext=fontfile='%{font_file}': timecode='0\\:0\\:0\\:0': timecode_rate=60: x=100: y=50: fontsize=40: fontcolor=white@1: borderw=3: bordercolor=black@1\" -r %{freq} -f image2 \"%{output_dir}/sc%%06d.jpeg\""
|
|
21
|
+
|
|
22
|
+
def initialize(
|
|
23
|
+
input_file:,
|
|
24
|
+
clips_count: 16,
|
|
25
|
+
output_dir: nil,
|
|
26
|
+
logger: nil
|
|
27
|
+
)
|
|
28
|
+
@options = OpenStruct.new ({
|
|
29
|
+
input: mk_input(input_file),
|
|
30
|
+
count: clips_count,
|
|
31
|
+
output: output_dir || "#{input_file}.dir",
|
|
32
|
+
logger: logger || Logger.new(STDNUL)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
@ffmpeg = FFMpeg.resolve
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_duration
|
|
39
|
+
cmd = CMD_DURATION % {
|
|
40
|
+
ffprobe: @ffmpeg.ffprobe,
|
|
41
|
+
input_file: @options.input
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@options.logger.info "shell.exec #{cmd}"
|
|
45
|
+
|
|
46
|
+
`#{cmd}`.to_f
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def perform
|
|
50
|
+
FileUtils.mkdir_p @options.output
|
|
51
|
+
|
|
52
|
+
cmd = (CMD_CLIPS % {
|
|
53
|
+
ffmpeg: @ffmpeg.ffmpeg,
|
|
54
|
+
input_file: @options.input,
|
|
55
|
+
freq: get_clip_frequency(get_duration, @options.count),
|
|
56
|
+
output_dir: @options.output,
|
|
57
|
+
count: @options.count,
|
|
58
|
+
font_file: FontFinder.find_font('font')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
@options.logger.info "shell.exec #{cmd}"
|
|
62
|
+
|
|
63
|
+
print `#{cmd}`
|
|
64
|
+
|
|
65
|
+
OpenStruct.new ({
|
|
66
|
+
list: Dir["#{@options.output}/sc*.jpeg"],
|
|
67
|
+
mask: "#{@options.output}/sc*.jpeg"
|
|
68
|
+
})
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def get_clip_frequency(duration, sc_count)
|
|
74
|
+
sc_count.to_f / duration
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def mk_input(input_f)
|
|
78
|
+
input_f = File.absolute_path input_f
|
|
79
|
+
raise ClipperError, "Cannot locate file '#{input_f}'" unless File.exists? input_f
|
|
80
|
+
input_f
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative '../../vrtk'
|
|
4
|
+
require_relative '../utils/utils'
|
|
5
|
+
|
|
6
|
+
Bundler.require :collager
|
|
7
|
+
|
|
8
|
+
module VRTK
|
|
9
|
+
|
|
10
|
+
module Collage
|
|
11
|
+
class CollagerError < VRTK::VRTKError;
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Collager
|
|
16
|
+
|
|
17
|
+
def initialize(
|
|
18
|
+
input_files:,
|
|
19
|
+
output_file: nil,
|
|
20
|
+
tile_ratio: [16, 9],
|
|
21
|
+
file_limit: nil,
|
|
22
|
+
collage_width: 1200
|
|
23
|
+
)
|
|
24
|
+
file_limit = [file_limit || input_files.size, input_files.size].min
|
|
25
|
+
|
|
26
|
+
@options = OpenStruct.new({
|
|
27
|
+
files: input_files[0...file_limit],
|
|
28
|
+
output: output_file || "#{Dir.pwd}/out.jpeg",
|
|
29
|
+
dim: tile_ratio|| [16, 9],
|
|
30
|
+
width: collage_width || 1200
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
@tmp_dir = Dir.mktmpdir %w(VRTK.Collager rb)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def perform
|
|
37
|
+
|
|
38
|
+
@options.files.map! do |file|
|
|
39
|
+
File.absolute_path file
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
layout = generate_layout @options.files.size, @options.dim, @options.width
|
|
43
|
+
|
|
44
|
+
files = resize_each @options.files, *layout.tile_size
|
|
45
|
+
|
|
46
|
+
montage = MiniMagick::Tool::Montage.new
|
|
47
|
+
|
|
48
|
+
files.each { |image| montage << image }
|
|
49
|
+
|
|
50
|
+
montage << '-mode'
|
|
51
|
+
montage << 'Concatenate'
|
|
52
|
+
montage << '-background'
|
|
53
|
+
montage << 'none'
|
|
54
|
+
montage << '-geometry'
|
|
55
|
+
montage << "#{layout.tile_size.join('x')}+0+0"
|
|
56
|
+
montage << '-tile'
|
|
57
|
+
montage << layout.layout
|
|
58
|
+
montage << (@options.output)
|
|
59
|
+
|
|
60
|
+
montage.call
|
|
61
|
+
|
|
62
|
+
finalize
|
|
63
|
+
|
|
64
|
+
@options.output
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
# noinspection RubyResolve
|
|
70
|
+
def resize_to_fill(width, height, img, gravity='Center')
|
|
71
|
+
cols, rows = img[:dimensions]
|
|
72
|
+
img.combine_options do |cmd|
|
|
73
|
+
if width != cols || height != rows
|
|
74
|
+
scale_x = width/cols.to_f
|
|
75
|
+
scale_y = height/rows.to_f
|
|
76
|
+
if scale_x >= scale_y
|
|
77
|
+
cols = (scale_x * (cols + 0.5)).round
|
|
78
|
+
rows = (scale_x * (rows + 0.5)).round
|
|
79
|
+
cmd.resize "#{cols}"
|
|
80
|
+
else
|
|
81
|
+
cols = (scale_y * (cols + 0.5)).round
|
|
82
|
+
rows = (scale_y * (rows + 0.5)).round
|
|
83
|
+
cmd.resize "x#{rows}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
cmd.gravity gravity
|
|
88
|
+
cmd.background 'rgba(255,255,255,0.0)'
|
|
89
|
+
cmd.extent "#{width}x#{height}" if cols != width || rows != height
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def finalize
|
|
94
|
+
FileUtils.rm_rf @tmp_dir
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def generate_layout(files_count, orig_size, wanted_width)
|
|
98
|
+
ow, oh = orig_size
|
|
99
|
+
|
|
100
|
+
ch = Math.sqrt(files_count).to_i
|
|
101
|
+
cw = (files_count.to_f / ch.to_f).ceil.to_i
|
|
102
|
+
|
|
103
|
+
opw = cw * ow
|
|
104
|
+
oph = ch * oh
|
|
105
|
+
|
|
106
|
+
pw = wanted_width
|
|
107
|
+
ph = ((pw.to_f / opw.to_f) * oph).to_i
|
|
108
|
+
|
|
109
|
+
mw, mh = [pw / cw, ph / ch]
|
|
110
|
+
|
|
111
|
+
OpenStruct.new({
|
|
112
|
+
layout: [cw, ch].join('x'),
|
|
113
|
+
full_size: [pw, ph],
|
|
114
|
+
tile_size: [mw, mh]
|
|
115
|
+
})
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def resize_each(files, width, height)
|
|
119
|
+
FileUtils.rm_rf @tmp_dir
|
|
120
|
+
FileUtils.mkdir @tmp_dir
|
|
121
|
+
|
|
122
|
+
n_files = []
|
|
123
|
+
|
|
124
|
+
files.each do |f|
|
|
125
|
+
image = MiniMagick::Image.open(f)
|
|
126
|
+
resize_to_fill(width, height, image)
|
|
127
|
+
image.format "jpg"
|
|
128
|
+
|
|
129
|
+
xf = Digest::MD5.hexdigest f
|
|
130
|
+
xf = "#{@tmp_dir}/#{xf}.jpg"
|
|
131
|
+
image.write xf
|
|
132
|
+
n_files << xf
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
n_files
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
end
|
data/src/vrtk/config.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require_relative '../../vrtk'
|
|
4
|
+
|
|
5
|
+
Bundler.require :utils
|
|
6
|
+
|
|
7
|
+
module VRTK::Utils
|
|
8
|
+
def self.to_wpath(upath)
|
|
9
|
+
"\"#{upath.gsub('/', '\\')}\""
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.to_upath(wpath)
|
|
13
|
+
"#{wpath.gsub('\\', '/')}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.get_binpath
|
|
17
|
+
ENV['PATH'].split(';').map { |v| v }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.to_wildcard(str)
|
|
21
|
+
str
|
|
22
|
+
.gsub('%', '*')
|
|
23
|
+
.gsub('#', '?')
|
|
24
|
+
.gsub('\\', '/')
|
|
25
|
+
end
|
|
26
|
+
end
|
data/src/vrtk/version.rb
ADDED
data/src/vrtk.rb
ADDED
data/vrtk.gemspec
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
lib = File.expand_path('../src', __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
|
|
4
|
+
require 'vrtk/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'vrtk'
|
|
8
|
+
spec.version = VRTK::VERSION
|
|
9
|
+
spec.authors = ['MRAKOBEZE']
|
|
10
|
+
spec.email = 'mrakobeze@pm.me'
|
|
11
|
+
|
|
12
|
+
spec.summary = ''
|
|
13
|
+
spec.homepage = 'https://github.com/mrakobeze/vrtk'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split(/[\r\n]+/).map(&:strip)
|
|
17
|
+
|
|
18
|
+
spec.bindir = 'bin'
|
|
19
|
+
spec.executables = ['vrtk']
|
|
20
|
+
spec.require_paths = ['src']
|
|
21
|
+
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vrtk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- MRAKOBEZE
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-03-31 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email: mrakobeze@pm.me
|
|
15
|
+
executables:
|
|
16
|
+
- vrtk
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".gitignore"
|
|
21
|
+
- Gemfile
|
|
22
|
+
- Gemfile.lock
|
|
23
|
+
- LICENSE.txt
|
|
24
|
+
- README.md
|
|
25
|
+
- Rakefile
|
|
26
|
+
- bin/setup
|
|
27
|
+
- bin/vrtk
|
|
28
|
+
- src/vrtk.rb
|
|
29
|
+
- src/vrtk/app.rb
|
|
30
|
+
- src/vrtk/applets/all.rb
|
|
31
|
+
- src/vrtk/applets/base_applet.rb
|
|
32
|
+
- src/vrtk/applets/clipper_applet.rb
|
|
33
|
+
- src/vrtk/applets/collager_applet.rb
|
|
34
|
+
- src/vrtk/clipper/clipper_error.rb
|
|
35
|
+
- src/vrtk/clipper/ffmpeg.rb
|
|
36
|
+
- src/vrtk/clipper/font_finder.rb
|
|
37
|
+
- src/vrtk/clipper/video_clipper.rb
|
|
38
|
+
- src/vrtk/collager/collager.rb
|
|
39
|
+
- src/vrtk/config.rb
|
|
40
|
+
- src/vrtk/utils/utils.rb
|
|
41
|
+
- src/vrtk/version.rb
|
|
42
|
+
- vrtk.gemspec
|
|
43
|
+
homepage: https://github.com/mrakobeze/vrtk
|
|
44
|
+
licenses:
|
|
45
|
+
- MIT
|
|
46
|
+
metadata: {}
|
|
47
|
+
post_install_message:
|
|
48
|
+
rdoc_options: []
|
|
49
|
+
require_paths:
|
|
50
|
+
- src
|
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
requirements: []
|
|
62
|
+
rubyforge_project:
|
|
63
|
+
rubygems_version: 2.6.13
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 4
|
|
66
|
+
summary: ''
|
|
67
|
+
test_files: []
|