checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 748be0b35f01f572afab32926ec763c8dab5c8233a004a2fc5ef9ce15e25d92e
4
+ data.tar.gz: 7781d0034ade2dafab4a821f3373c460b0601dfff20e93861220e5360d714246
5
+ SHA512:
6
+ metadata.gz: e7cb728442ecfbe437de77d0b4373aa5dff1e063bb688f322a4662ed99e45291a269e430b3c3f3605c9e290d07624c0fc99d70a51dce68c54ea8771e07d78fe0
7
+ data.tar.gz: 931738616f352b897f625a2d5c1f7480d004fb1f209b0bf82a2ac06925b3b013293771c4332a26def12a5ab25c1de92fcf43871d96742b38132176409567a839
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in evideo.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ evideo (0.1.1)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ rake (10.5.0)
11
+ thor (0.20.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.17)
18
+ evideo!
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Hernâni Rodrigues Vaz
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,39 @@
1
+ # Evideo
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/evideo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'evideo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install evideo
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]/evideo.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "evideo"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=#x27;\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/evideo.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'evideo/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'evideo'
9
+ spec.version = Evideo::VERSION
10
+ spec.authors = ['Hernâni Rodrigues Vaz']
11
+ spec.email = ['hernanirvaz@gmail.com']
12
+ spec.homepage = 'https://github.com/hernanilr/evideo'
13
+ spec.license = 'MIT'
14
+
15
+ spec.summary = 'Processa ficheiros video para arquivo'
16
+ spec.description = spec.summary
17
+ spec.description += ' Pode alterar bitrate, framerate, height,' \
18
+ ' aspect ratio e elimina metadata'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['yard.run'] = 'yard'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been
25
+ # added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0")
28
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.17'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+
37
+ spec.add_dependency 'thor'
38
+ end
data/exe/ev ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'evideo'
5
+
6
+ Evideo::CLI.start(ARGV)
data/lib/evideo.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'evideo/version'
5
+ require 'evideo/hrvideo'
6
+
7
+ module Evideo
8
+ class Error < StandardError; end
9
+ ID = `whoami`.chomp
10
+ # CLI para processar videos
11
+ class CLI < Thor
12
+ class_option :d, banner: 'DIR', type: :array,
13
+ default: ["/home/#{ID}/lust", "/media/#{ID}/hrv2"],
14
+ desc: 'Onde procurar videos'
15
+ class_option :i, banner: 'IN', default: 'ftv',
16
+ desc: 'Pasta origem'
17
+ desc 'conv', 'converte videos'
18
+ option :o, banner: 'OUT', default: 'out',
19
+ desc: 'Pasta destino'
20
+ def conv
21
+ dar = options[:d]
22
+ Dir.glob(File.join(dar[0], options[:i], '*.???')).sort.each do |f|
23
+ HRVideo.new(f).processa(dar, dar[0], options[:o])
24
+ end
25
+ end
26
+ default_task :conv
27
+ end
28
+ end
data/lib/evideo/hrvideo.rb ADDED
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Evideo
6
+ # permite analizar string output do comando sonda video
7
+ class HRVideo < String
8
+ attr_reader :video, :ext, :base, :duration, :bitrate
9
+
10
+ # Duration: 01:01:08.50, start: 0.000000, bitrate: 2228 kb/s
11
+ R1 = /duration:\s+(\d\d:\d\d:\d\d).*bitrate:\s+(\d+)\s+kb/i.freeze
12
+ # Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720
13
+ # [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 180k tbc (default)
14
+ R2 = /stream.*video:.*x\s*(\d+).*\s+(\d+\.*\d*)\s+fps/i.freeze
15
+ # display_aspect_ratio=16:9
16
+ R3 = /display_aspect_ratio\s*=\s*(\d+:\d+)#x2F;i.freeze
17
+
18
+ def initialize(fvideo)
19
+ @video = fvideo
20
+ @ext = File.extname(fvideo)
21
+ @base = File.basename(fvideo, @ext).downcase
22
+ @duration = '00:00:00'
23
+ @bitrate = 0
24
+ @probe = `#{probe}` if File.exist?(fvideo)
25
+ return unless @probe
26
+
27
+ r1 = @probe.scan(R1).flatten
28
+ @duration = r1[0]
29
+ @bitrate = r1[1].to_i
30
+ end
31
+
32
+ def r2
33
+ return unless @probe
34
+
35
+ r2 = @probe.scan(R2).flatten
36
+ @height = r2[0].to_i
37
+ @fps = r2[1].to_f
38
+ end
39
+
40
+ def r3
41
+ return unless @probe
42
+
43
+ @ratio = @probe.scan(R3).flatten[0]
44
+ end
45
+
46
+ def height
47
+ r2 unless @height
48
+
49
+ @height
50
+ end
51
+
52
+ def fps
53
+ r2 unless @fps
54
+
55
+ @fps
56
+ end
57
+
58
+ def ratio
59
+ r3 unless @ratio
60
+
61
+ @ratio
62
+ end
63
+
64
+ def rm_show
65
+ return video unless @probe
66
+
67
+ "#{video} duration: #{duration} bitrate: #{bitrate}"
68
+ end
69
+
70
+ def vfok?(fout)
71
+ return false unless File.exist?(fout.video)
72
+
73
+ # tempo video processado < tempo original -60 segundos ou
74
+ # bitrate video processado > bitrate video origunal
75
+ return false unless Time.parse(fout.duration) >
76
+ Time.parse(duration) - 60 &&
77
+ fout.bitrate < 3000
78
+
79
+ puts "rm #{video} # #{fout.rm_show}"
80
+ true
81
+ end
82
+
83
+ def vdok?(ary, out)
84
+ if ary.empty? then false
85
+ elsif vfok?(HRVideo.new("#{ary[0]}/#{out}/#{base}.mp4")) then true
86
+ else vdok?(ary.drop(1), out)
87
+ end
88
+ end
89
+
90
+ def geral
91
+ # general options
92
+ '-loglevel quiet -hide_banner' +
93
+ # para ignorar segundos no inicio
94
+ # ' -ss 15' \
95
+ ''
96
+ end
97
+
98
+ def metadata
99
+ # clean metadata
100
+ ' -metadata title= -metadata artist= -metadata comment=' \
101
+ ' -metadata major_brand= -metadata compatible_brands=' +
102
+ # para teste produz somente segundos
103
+ # ' -t 20' \
104
+ ''
105
+ end
106
+
107
+ def aspect_ratio
108
+ # invalido aspect ratio 0:1
109
+ if ratio == '0:1' then bitrate < 720 ? '' : ' -aspect 16:9'
110
+ else " -aspect #{ratio}"
111
+ end
112
+ end
113
+
114
+ def dimension
115
+ # video dimensions
116
+ if bitrate < 480 then ' -s hd480'
117
+ elsif bitrate <= 720 then ' -s hd720'
118
+ else ' -s hd1080'
119
+ end
120
+ end
121
+
122
+ def probe
123
+ "ffprobe -hide_banner -show_streams \"#{video}\" 2>&1|grep -v title"
124
+ end
125
+
126
+ def mpeg
127
+ "ffmpeg #{geral} -i #{video} -y -an " +
128
+ # framerate & bitrate
129
+ "-r #{[fps, 25].min} -b:v #{[bitrate, 2000].min}k" +
130
+ dimension + aspect_ratio + metadata
131
+ end
132
+
133
+ def processa(dar, din, out)
134
+ return if (bitrate < 3000 && ext == '.mp4') ||
135
+ Time.parse(duration) < Time.parse('00:01:00') ||
136
+ vdok?(dar, out)
137
+
138
+ p mpeg + " #{din}/#{out}/#{base}.mp4"
139
+ vfok?(HRVideo.new("#{din}/#{out}/#{base}.mp4"))
140
+ end
141
+ end
142
+ end
data/lib/evideo/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evideo
4
+ VERSION = '0.1.1'
5
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evideo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Hernâni Rodrigues Vaz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Processa ficheiros video para arquivo Pode alterar bitrate, framerate,
56
+ height, aspect ratio e elimina metadata
57
+ email:
58
+ - hernanirvaz@gmail.com
59
+ executables:
60
+ - ev
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - evideo.gemspec
73
+ - exe/ev
74
+ - lib/evideo.rb
75
+ - lib/evideo/hrvideo.rb
76
+ - lib/evideo/version.rb
77
+ homepage: https://github.com/hernanilr/evideo
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ homepage_uri: https://github.com/hernanilr/evideo
82
+ yard.run: yard
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Processa ficheiros video para arquivo
102
+ test_files: []