video_blur 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup_video_blur +7 -0
- data/bin/video_blur +5 -0
- data/lib/video_blur.rb +10 -0
- data/lib/video_blur/blur.rb +20 -0
- data/lib/video_blur/box.rb +27 -0
- data/lib/video_blur/cli.rb +58 -0
- data/lib/video_blur/runner.rb +33 -0
- data/lib/video_blur/screen.rb +21 -0
- data/lib/video_blur/version.rb +3 -0
- data/lib/video_blur/video.rb +30 -0
- data/video_blur.gemspec +25 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3605fb5a25e98cf3c09348ed06fb6ac0a7a32bc3
|
4
|
+
data.tar.gz: 67261df9c0cc5fefdda6346bc0056238ab260383
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b4e6cd4926832c4ab837290c70fc28072e6059024ba9c31f6d3860336a75965bd81a96d6e15fd3fb6af806c36094b5135f9b0289c739171042a5f49a70962f38
|
7
|
+
data.tar.gz: 45d9b51469942041ee2f8f0c62ac98afd466a21a746f38fd35c5e3f2cf59ab55167fc2065632c4e34a86233db87a4302fa997d34a76bc0c13b30a51cbb8e2f02
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Vincent Daubry
|
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,75 @@
|
|
1
|
+
# VideoBlur
|
2
|
+
|
3
|
+
Video_blur is a small ruby gem to blur a part of a video using FFmpeg. It automates the aspect ratio conversion and the FFmpeg filter parameters.
|
4
|
+
|
5
|
+
Input video :
|
6
|
+
|
7
|
+
![image](http://i.imgur.com/dUC5I3g.jpg)
|
8
|
+
|
9
|
+
|
10
|
+
Output video :
|
11
|
+
|
12
|
+
![image](http://i.imgur.com/O3L9iiP.jpg)
|
13
|
+
|
14
|
+
|
15
|
+
## Requirements :
|
16
|
+
|
17
|
+
[FFmpeg](https://www.ffmpeg.org/) must be installed. To ensure it is available, on your command line, run `which ffmpeg`.
|
18
|
+
This will give you the path where ffmpeg is installed. For example, it might return `/usr/local/bin/ffmpeg`.
|
19
|
+
|
20
|
+
Install FFmpeg on OS X : ``` brew install ffmpeg ```
|
21
|
+
|
22
|
+
Install FFmpeg on Linux : ``` apt-get install ffmpeg ffmpeg ```
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Add this line to your application's Gemfile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
gem 'video_blur'
|
32
|
+
```
|
33
|
+
|
34
|
+
And then execute:
|
35
|
+
|
36
|
+
$ bundle
|
37
|
+
|
38
|
+
Or install it yourself as:
|
39
|
+
|
40
|
+
$ gem install video_blur
|
41
|
+
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Example : Blur the video in.mp4 starting at (x=200, y=160) with blur box size (width=145, height=360)
|
46
|
+
|
47
|
+
video_blur in.mp4 -x 200 -y 160 -w 145 -e 360 -o out.mp4
|
48
|
+
|
49
|
+
|
50
|
+
For more information see help :
|
51
|
+
|
52
|
+
Usage: video_blur [options] [input_file]
|
53
|
+
-o, --output OUTPUT Set output directory
|
54
|
+
-W, --screen-width WIDTH Set screen width (default 1440)
|
55
|
+
-H, --screen-height HEIGHT Set screen width (default 1440)
|
56
|
+
-x, --box-x X-POSITION Set box x origin
|
57
|
+
-y, --box-y Y-POSITION Set box y origin
|
58
|
+
-w, --box-width WIDTH Set box width
|
59
|
+
-e, --box-height height Set box width
|
60
|
+
-h, --help Prints this help
|
61
|
+
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it ( https://github.com/[my-github-username]/video_blur/fork )
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup_video_blur"
|
4
|
+
require "video_blur"
|
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
|
data/bin/video_blur
ADDED
data/lib/video_blur.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module VideoBlur
|
2
|
+
class Blur
|
3
|
+
def initialize(video:, box:)
|
4
|
+
@video = video
|
5
|
+
@box = box
|
6
|
+
end
|
7
|
+
|
8
|
+
def perform
|
9
|
+
command = "ffmpeg -y -i '#{@video.input}' -filter_complex " \
|
10
|
+
"'[0:v]split=2[v0][v1]; " \
|
11
|
+
"[v0]crop=#{@box.width}:#{@box.height}:#{@box.x}:#{@box.y},boxblur=4[fg]; " \
|
12
|
+
"[v1][fg]overlay=#{@box.x}:#{@box.y}[v]' " \
|
13
|
+
"-map '[v]' -map 0:a -c:v libx264 -c:a copy -movflags +faststart '#{@video.output}'"
|
14
|
+
blur_ok = system(command)
|
15
|
+
unless blur_ok
|
16
|
+
abort("An error occured while blurring the video, see ffmpeg output for more details")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VideoBlur
|
2
|
+
class Box
|
3
|
+
def initialize(x:, y:, width:, height:, ratio: 1)
|
4
|
+
@x = x
|
5
|
+
@y = y
|
6
|
+
@width = width
|
7
|
+
@height = height
|
8
|
+
@ratio = ratio
|
9
|
+
end
|
10
|
+
|
11
|
+
def x
|
12
|
+
(@x * @ratio).to_i
|
13
|
+
end
|
14
|
+
|
15
|
+
def y
|
16
|
+
(@y * @ratio).to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def width
|
20
|
+
(@width * @ratio).to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def height
|
24
|
+
(@height * @ratio).to_i
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'singleton'
|
3
|
+
require 'byebug'
|
4
|
+
|
5
|
+
module VideoBlur
|
6
|
+
class CLI
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def run(args)
|
10
|
+
options, path = parse_cli_args(args)
|
11
|
+
VideoBlur::Runner.execute(path: path, options: options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse_cli_args(argv)
|
15
|
+
options = {}
|
16
|
+
opt_parser = OptionParser.new
|
17
|
+
opt_parser.banner = "Usage: video_blur [options] [input_file]"
|
18
|
+
options[:output] = "output.mp4"
|
19
|
+
|
20
|
+
opt_parser.on("-o", "--output OUTPUT", "Set output directory") do |o|
|
21
|
+
options[:output] = o
|
22
|
+
end
|
23
|
+
|
24
|
+
opt_parser.on("-W", "--screen-width WIDTH", "Set screen width (default 1440)") do |width|
|
25
|
+
options[:screen_width] = width.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
opt_parser.on("-H", "--screen-height HEIGHT", "Set screen width (default 1440)") do |height|
|
29
|
+
options[:screen_height] = height.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
opt_parser.on("-x", "--box-x X-POSITION", "Set box x origin") do |x|
|
33
|
+
options[:x] = x.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
opt_parser.on("-y", "--box-y Y-POSITION", "Set box y origin") do |y|
|
37
|
+
options[:y] = y.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
opt_parser.on("-w", "--box-width WIDTH", "Set box width") do |width|
|
41
|
+
options[:width] = width.to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
opt_parser.on("-e", "--box-height height", "Set box width") do |height|
|
45
|
+
options[:height] = height.to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
opt_parser.on("-h", "--help", "Prints this help") do
|
49
|
+
puts opt_parser
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
path = opt_parser.parse!(argv)
|
54
|
+
|
55
|
+
return options, path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module VideoBlur
|
2
|
+
module Runner
|
3
|
+
def self.execute(path:, options:)
|
4
|
+
path = path.first
|
5
|
+
validate(path: path, options: options)
|
6
|
+
|
7
|
+
screen = VideoBlur::Screen.new(width: options[:screen_width],
|
8
|
+
height: options[:screen_height])
|
9
|
+
|
10
|
+
video = VideoBlur::Video.new(input: path,
|
11
|
+
output: options[:output])
|
12
|
+
|
13
|
+
box = VideoBlur::Box.new(x: options[:x],
|
14
|
+
y: options[:y],
|
15
|
+
width: options[:width],
|
16
|
+
height: options[:height],
|
17
|
+
ratio: screen.ratio(video: video))
|
18
|
+
|
19
|
+
|
20
|
+
VideoBlur::Blur.new(video: video, box: box).perform
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.validate(path:, options:)
|
24
|
+
abort("Missing path to video") if path.nil? || path.empty?
|
25
|
+
abort("Video file not found: #{@input}") unless File.exists?(path)
|
26
|
+
|
27
|
+
abort("Missing box options") unless options[:x] &&
|
28
|
+
options[:y] &&
|
29
|
+
options[:width] &&
|
30
|
+
options[:height]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VideoBlur
|
2
|
+
class Screen
|
3
|
+
def initialize(width: 1440, height: 815)
|
4
|
+
@width = width && width.to_f || 1140
|
5
|
+
@height = height && height.to_f || 815
|
6
|
+
end
|
7
|
+
|
8
|
+
def ratio(video:)
|
9
|
+
#If video is re-dimensionned along x axis
|
10
|
+
if video.width > @width
|
11
|
+
video.width/@width
|
12
|
+
#If video is re-dimensionned along y axis
|
13
|
+
elsif video.height > @height
|
14
|
+
video.height/@height
|
15
|
+
#If video fits on screen
|
16
|
+
else
|
17
|
+
1.0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module VideoBlur
|
2
|
+
class Video
|
3
|
+
def initialize(input:, output:)
|
4
|
+
@input = input
|
5
|
+
@output = output
|
6
|
+
end
|
7
|
+
|
8
|
+
def width
|
9
|
+
size.split("x")[0].to_f
|
10
|
+
end
|
11
|
+
|
12
|
+
def height
|
13
|
+
size.split("x")[1].to_f
|
14
|
+
end
|
15
|
+
|
16
|
+
def input
|
17
|
+
File.absolute_path(@input)
|
18
|
+
end
|
19
|
+
|
20
|
+
def output
|
21
|
+
File.absolute_path(@output)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def size
|
27
|
+
@video_size ||= `ffmpeg -i '#{input}' 2>&1 | grep Stream | head -n 1`.match(/[0-9]{2,4}x[0-9]{2,4}/)[0]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/video_blur.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'video_blur/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "video_blur"
|
8
|
+
spec.version = VideoBlur::VERSION
|
9
|
+
spec.authors = ["Vincent Daubry"]
|
10
|
+
spec.email = ["vdaubry@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{FFmpeg Ruby wrapper to blur a part of a video }
|
13
|
+
spec.description = %q{video_blur gem is a small Ruby gem to blur a part of a video using FFmpeg. It automates the aspect ratio conversion and the FFmpeg filter parameters }
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "byebug"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: video_blur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vincent Daubry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-02 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.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: 'video_blur gem is a small Ruby gem to blur a part of a video using FFmpeg.
|
56
|
+
It automates the aspect ratio conversion and the FFmpeg filter parameters '
|
57
|
+
email:
|
58
|
+
- vdaubry@gmail.com
|
59
|
+
executables:
|
60
|
+
- console
|
61
|
+
- setup_video_blur
|
62
|
+
- video_blur
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- ".gitignore"
|
67
|
+
- ".rspec"
|
68
|
+
- ".travis.yml"
|
69
|
+
- CODE_OF_CONDUCT.md
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- bin/console
|
75
|
+
- bin/setup_video_blur
|
76
|
+
- bin/video_blur
|
77
|
+
- lib/video_blur.rb
|
78
|
+
- lib/video_blur/blur.rb
|
79
|
+
- lib/video_blur/box.rb
|
80
|
+
- lib/video_blur/cli.rb
|
81
|
+
- lib/video_blur/runner.rb
|
82
|
+
- lib/video_blur/screen.rb
|
83
|
+
- lib/video_blur/version.rb
|
84
|
+
- lib/video_blur/video.rb
|
85
|
+
- video_blur.gemspec
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.6
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: FFmpeg Ruby wrapper to blur a part of a video
|
110
|
+
test_files: []
|