cherry_picking_moments 0.1.0
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 +1 -0
- data/.travis.yml +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cherry_picking_moments.gemspec +31 -0
- data/lib/cherry_picking_moments.rb +8 -0
- data/lib/cherry_picking_moments/hamming_distance.rb +10 -0
- data/lib/cherry_picking_moments/image.rb +27 -0
- data/lib/cherry_picking_moments/movie.rb +29 -0
- data/lib/cherry_picking_moments/parapara.rb +21 -0
- data/lib/cherry_picking_moments/version.rb +3 -0
- metadata +128 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0371a6dc6012d3c47ac466aaaab55a4efae9f8e029d8175103ec095850f60669
|
|
4
|
+
data.tar.gz: b5bdce31eaf889eef270b9e825630347c7a5ea26810303ea7bd967ebcc63982f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2e118ac6c83692c8fa64e7ac5f73fe7e2f61567c646de1c07641de413705c49d993ed6d65d24df15c199ac5ce05239f2057c2cfa2fafe9f99ce4c8e7f21ad8f1
|
|
7
|
+
data.tar.gz: 72bdddd9aac20294424e73da5e27cd17bc70b382dd428726ddb3a921a3164b88d89d32dfd3bb6288ce78721906c60677a55088475925a50983410dcd154a9035
|
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.idea
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
sudo: false
|
|
2
|
+
language: ruby
|
|
3
|
+
rvm:
|
|
4
|
+
- 2.6.3
|
|
5
|
+
before_install:
|
|
6
|
+
- export PATH="$(pyenv root)/bin:$PATH"
|
|
7
|
+
- eval "$(pyenv init -)"
|
|
8
|
+
- gem install bundler -v 2.0.1
|
|
9
|
+
install:
|
|
10
|
+
- pyenv install -f miniconda-3.7.0
|
|
11
|
+
- conda config --set always_yes yes --set changeps1 no
|
|
12
|
+
- conda update -q conda
|
|
13
|
+
- conda info -a
|
|
14
|
+
- conda create -q -n test-environment python=3.7 imagehash
|
|
15
|
+
- source $(pyenv prefix)/bin/activate test-environment
|
|
16
|
+
- pip install --user imagehash
|
|
17
|
+
- bundle install
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 yensaki
|
|
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,59 @@
|
|
|
1
|
+
# CherryPickingMoments
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/yensaki/cherry_picking_moments)
|
|
4
|
+
|
|
5
|
+
This generates uniquish images from a movie file.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
1. Install ffmpeg
|
|
10
|
+
1. Install python
|
|
11
|
+
```
|
|
12
|
+
$ CONFIGURE_OPTS="--enable-shared" pyenv install 3.7.1
|
|
13
|
+
```
|
|
14
|
+
1. Install imagehash from pip
|
|
15
|
+
```
|
|
16
|
+
$ pip install ImageHash
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
1. gem install this
|
|
20
|
+
Add this line to your application's Gemfile:
|
|
21
|
+
```ruby
|
|
22
|
+
gem 'cherry_picking_moments', github: 'yensaki/cherry_picking_moments'
|
|
23
|
+
```
|
|
24
|
+
And then execute:
|
|
25
|
+
```
|
|
26
|
+
$ bundle
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or install it yourself as:
|
|
30
|
+
|
|
31
|
+
$ gem install cherry_picking_moments
|
|
32
|
+
|
|
33
|
+
# Usage
|
|
34
|
+
|
|
35
|
+
You can get sliced images of a movie.
|
|
36
|
+
Their images have hamming_distance compared with next index image.
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
movie = CherryPickingMoments.movie('/path/to/a/movie.mp4')
|
|
40
|
+
images = movie.images
|
|
41
|
+
images.map(&:following_distance)
|
|
42
|
+
# => [12, 6, 8, 18, 14, 20, 26, 20, 20, 26, 8, nil]
|
|
43
|
+
images.map(&:filepath)
|
|
44
|
+
# => ['/path/to/0001.png', '/path/to/0002.png', '/path/to/0003.png', ..., '/path/to/0012.png']
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Development
|
|
48
|
+
|
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
50
|
+
|
|
51
|
+
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).
|
|
52
|
+
|
|
53
|
+
## Contributing
|
|
54
|
+
|
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cherry_picking_moments.
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "cherry_picking_moments"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "cherry_picking_moments/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "cherry_picking_moments"
|
|
7
|
+
spec.version = CherryPickingMoments::VERSION
|
|
8
|
+
spec.authors = ["yensaki"]
|
|
9
|
+
spec.email = ["mov.an.double@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = %q{Generate uniquish images from a movie}
|
|
12
|
+
spec.description = %q{Generate uniquish images from a movie}
|
|
13
|
+
spec.homepage = "https://github.com/yensaki/cherry_picking_moments"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
end
|
|
21
|
+
spec.bindir = "exe"
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_dependency "pycall", "1.2.1"
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency "bundler", ">=1.17.2"
|
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
30
|
+
spec.add_development_dependency "pry-byebug"
|
|
31
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class CherryPickingMoments::HammingDistance
|
|
2
|
+
def initialize(source, compared)
|
|
3
|
+
@source = source
|
|
4
|
+
@compared = compared
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def hamming_distance
|
|
8
|
+
@source.to_binary.split('').zip(@compared.to_binary.split('')).count { |i, j| i.to_i ^ j.to_i == 1 }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'pycall/import'
|
|
2
|
+
include PyCall::Import
|
|
3
|
+
|
|
4
|
+
class CherryPickingMoments::Image
|
|
5
|
+
attr_reader :filepath
|
|
6
|
+
attr_accessor :following_distance
|
|
7
|
+
pyfrom :PIL, import: :Image
|
|
8
|
+
|
|
9
|
+
def initialize(filepath)
|
|
10
|
+
@filepath = filepath
|
|
11
|
+
pyimport :imagehash
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def phash
|
|
15
|
+
@phash ||= imagehash.phash(pyimage).to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_binary
|
|
19
|
+
sprintf("%064b", phash.to_i(16))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def pyimage
|
|
25
|
+
@pyimage ||= Image.open(@filepath)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'cherry_picking_moments/parapara'
|
|
2
|
+
require 'cherry_picking_moments/image'
|
|
3
|
+
require 'cherry_picking_moments/hamming_distance'
|
|
4
|
+
|
|
5
|
+
class CherryPickingMoments::Movie
|
|
6
|
+
def initialize(moviepath)
|
|
7
|
+
@moviepath = moviepath
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def images
|
|
11
|
+
return @images if @images
|
|
12
|
+
|
|
13
|
+
@images = []
|
|
14
|
+
Dir.glob(File.join(parapara!.output_path, '*.png')).sort.each do |filepath|
|
|
15
|
+
image = CherryPickingMoments::Image.new(filepath)
|
|
16
|
+
prev_image = @images.last
|
|
17
|
+
prev_image.following_distance = CherryPickingMoments::HammingDistance.new(prev_image, image).hamming_distance if prev_image
|
|
18
|
+
|
|
19
|
+
@images << image
|
|
20
|
+
end
|
|
21
|
+
@images
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def parapara!
|
|
27
|
+
@parapara ||= CherryPickingMoments::Parapara.new(@moviepath).tap(&:slice!)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "open3"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
|
|
5
|
+
module CherryPickingMoments
|
|
6
|
+
class Parapara
|
|
7
|
+
attr_reader :output_path
|
|
8
|
+
|
|
9
|
+
def initialize(file, rate: 3)
|
|
10
|
+
@file = file
|
|
11
|
+
@rate = rate
|
|
12
|
+
@output_path = Dir.tmpdir
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def slice!
|
|
16
|
+
FileUtils.mkdir_p(@output_path)
|
|
17
|
+
cmd = "ffmpeg -ss 0 -i #{@file} -vsync 2 -r #{@rate} -an -f image2 '#{File.join(@output_path, "%04d.png")}'"
|
|
18
|
+
Open3.capture3(cmd)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cherry_picking_moments
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- yensaki
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-06-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: pycall
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 1.2.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.2.1
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.17.2
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.17.2
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry-byebug
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Generate uniquish images from a movie
|
|
84
|
+
email:
|
|
85
|
+
- mov.an.double@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- ".travis.yml"
|
|
92
|
+
- Gemfile
|
|
93
|
+
- LICENSE.txt
|
|
94
|
+
- README.md
|
|
95
|
+
- Rakefile
|
|
96
|
+
- bin/console
|
|
97
|
+
- bin/setup
|
|
98
|
+
- cherry_picking_moments.gemspec
|
|
99
|
+
- lib/cherry_picking_moments.rb
|
|
100
|
+
- lib/cherry_picking_moments/hamming_distance.rb
|
|
101
|
+
- lib/cherry_picking_moments/image.rb
|
|
102
|
+
- lib/cherry_picking_moments/movie.rb
|
|
103
|
+
- lib/cherry_picking_moments/parapara.rb
|
|
104
|
+
- lib/cherry_picking_moments/version.rb
|
|
105
|
+
homepage: https://github.com/yensaki/cherry_picking_moments
|
|
106
|
+
licenses:
|
|
107
|
+
- MIT
|
|
108
|
+
metadata: {}
|
|
109
|
+
post_install_message:
|
|
110
|
+
rdoc_options: []
|
|
111
|
+
require_paths:
|
|
112
|
+
- lib
|
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0'
|
|
123
|
+
requirements: []
|
|
124
|
+
rubygems_version: 3.0.3
|
|
125
|
+
signing_key:
|
|
126
|
+
specification_version: 4
|
|
127
|
+
summary: Generate uniquish images from a movie
|
|
128
|
+
test_files: []
|