evideo 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d52282fceffa14ff50d2b6d0807b1f04757c19b512ad15779f6d34ab27c5443e
4
+ data.tar.gz: 7cdb3ce10ea1c11e7228f2f871e7618c05a6e1a9c7046b5bc4b1d67488103ea5
5
+ SHA512:
6
+ metadata.gz: 353c32cf6373ea45831f8595fef15b264fd304c30f8676dc53437b45c3e25bbf89f6f6fc5c27a9cb24b42369f2737b7d84b259e7212ee46a0b3455364a6a5a48
7
+ data.tar.gz: 5f1bdc4f3bb6609360b60b4148fb55e8d9ac84fdec80f7dd59b212d90d72345d8ca7b651ab26f261506498cf1f1ebe0d1f9f314c33695c49658000542ce264e1
@@ -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
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ evideo (0.1.3)
5
+ thor (~> 0.1)
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
@@ -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.
@@ -0,0 +1,34 @@
1
+ # Evideo
2
+
3
+ Processa ficheiros video. Pode alterar bitrate, framerate, height, aspect ratio e elimina metadata.
4
+
5
+ ## Installation
6
+
7
+ $ gem install evideo
8
+
9
+ ## Usage
10
+
11
+ $ ev conv # converte videos
12
+ $ ev test # testa videos
13
+
14
+ Options:
15
+ [-d=DIR] # Onde procurar videos
16
+ # Default: ["/home/eu/lust", "/media/eu/hrv2"]
17
+ [-i=IN] # Pasta origem
18
+ # Default: ftv
19
+ [-o=OUT] # Pasta destino
20
+ # Default: out
21
+
22
+ ## Development
23
+
24
+ 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.
25
+
26
+ 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).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/evideo.
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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.'
16
+ spec.description = spec.summary +
17
+ ' 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', '~> 0.1'
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)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'evideo/version'
5
+ require 'evideo/hrvideo'
6
+ require 'evideo/hrvprocessa'
7
+
8
+ module Evideo
9
+ class Error < StandardError; end
10
+ ID = `whoami`.chomp
11
+ # CLI para analisar/processar videos
12
+ class CLI < Thor
13
+ class_option :d, banner: 'DIR', type: :array,
14
+ default: ["/home/#{ID}/lust", "/media/#{ID}/hrv2"],
15
+ desc: 'Onde procurar videos'
16
+ class_option :i, banner: 'IN', default: 'ftv',
17
+ desc: 'Pasta origem'
18
+ desc 'conv', 'converte videos'
19
+ option :o, banner: 'OUT', default: 'out',
20
+ desc: 'Pasta destino'
21
+ # Processa videos
22
+ def conv
23
+ dar = options[:d]
24
+ Dir.glob("#{dar.first}/#{options[:i]}/*.???").sort.each do |f|
25
+ HRVideo.new(f).processa(dar, dar.first, options[:o])
26
+ end
27
+ end
28
+
29
+ desc 'test', 'testa videos'
30
+ # Analisa videos
31
+ def test
32
+ Dir.glob("#{options[:d].first}/#{options[:i]}/*.???").sort.each do |f|
33
+ p HRVideo.new(f).testa
34
+ end
35
+ end
36
+ default_task :conv
37
+ end
38
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evideo
4
+ # permite analizar string output do comando sonda video
5
+ class HRVideo < String
6
+ # @return [String] nome do ficheiro video
7
+ attr_reader :video
8
+ # @return [String] extensao do ficheiro video
9
+ attr_reader :ext
10
+ # @return [String] base do ficheiro video
11
+ attr_reader :base
12
+ # @return [String] duracao do ficheiro video
13
+ attr_reader :duration
14
+ # @return [String] bitrate do ficheiro video
15
+ attr_reader :bitrate
16
+
17
+ # Duration: 01:01:08.50, start: 0.000000, bitrate: 2228 kb/s
18
+ R1 = /duration:\s+(\d\d:\d\d:\d\d).*bitrate:\s+(\d+)\s+kb/i.freeze
19
+ # Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720
20
+ # [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 180k tbc (default)
21
+ R2 = /stream.*video:.*x\s*(\d+).*\s+(\d+\.*\d*)\s+fps/i.freeze
22
+ # display_aspect_ratio=16:9
23
+ R3 = /display_aspect_ratio\s*=\s*(\d+:\d+)$/i.freeze
24
+
25
+ def initialize(fvideo)
26
+ @video = fvideo
27
+ @ext = File.extname(fvideo)
28
+ @base = File.basename(fvideo, @ext).downcase
29
+ @duration = '00:00:00'
30
+ @bitrate = 0
31
+ @probe = `#{probe}` if File.exist?(fvideo)
32
+ return unless @probe
33
+
34
+ r1 = @probe.scan(R1).flatten
35
+ @duration = r1[0]
36
+ @bitrate = r1[1].to_i
37
+ end
38
+
39
+ # Parametrizar height e frame rate
40
+ def r2
41
+ return unless @probe
42
+
43
+ r2 = @probe.scan(R2).flatten
44
+ @height = r2[0].to_i
45
+ @fps = r2[1].to_f
46
+ end
47
+
48
+ # Parametrizar aspect ratio
49
+ def r3
50
+ return unless @probe
51
+
52
+ @ratio = @probe.scan(R3).flatten[0]
53
+ end
54
+
55
+ # @return [String] height
56
+ def height
57
+ r2 unless @height
58
+
59
+ @height
60
+ end
61
+
62
+ # @return [String] frame rate
63
+ def fps
64
+ r2 unless @fps
65
+
66
+ @fps
67
+ end
68
+
69
+ # @return [String] aspect ratio
70
+ def ratio
71
+ r3 unless @ratio
72
+
73
+ @ratio
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Evideo
6
+ # permite analizar/processar videos para arquivo
7
+ class HRVideo < String
8
+ # Testa validade video
9
+ #
10
+ # @param [String] file video a testar validade
11
+ # @return [true, false] sim ou nao video esta ok
12
+ def vfok?(file)
13
+ return false unless File.exist?(file.video)
14
+
15
+ # tempo video processado < tempo original -60 segundos ou
16
+ # bitrate video processado > bitrate video origunal
17
+ return false unless Time.parse(file.duration) >
18
+ Time.parse(duration) - 60 &&
19
+ file.bitrate < 3000
20
+
21
+ puts "rm #{video} # #{file.rm_show}"
22
+ true
23
+ end
24
+
25
+ # Testa validade <locais>/<video>
26
+ #
27
+ # @param [Array<String>] ary array locais onde procurar videos
28
+ # @param [String] out pasta destino dos videos
29
+ # @return [true, false] sim ou nao <local>/<video> esta ok
30
+ def vdok?(ary, out)
31
+ if ary.empty? then false
32
+ elsif vfok?(HRVideo.new("#{ary.first}/#{out}/#{base}.mp4")) then true
33
+ else vdok?(ary.drop(1), out)
34
+ end
35
+ end
36
+
37
+ # @return [String] opcoes gerais comando conversao
38
+ def geral
39
+ '-loglevel quiet -hide_banner' +
40
+ # para ignorar segundos no inicio
41
+ # ' -ss 15' \
42
+ ''
43
+ end
44
+
45
+ # @return [String] metadata comando conversao
46
+ def metadata
47
+ ' -metadata title= -metadata artist= -metadata comment=' \
48
+ ' -metadata major_brand= -metadata compatible_brands=' +
49
+ # para teste produz somente segundos
50
+ # ' -t 20' \
51
+ ''
52
+ end
53
+
54
+ # @return [String] aspect ratio comando conversao
55
+ def aspect_ratio
56
+ if ratio == '0:1' then bitrate < 720 ? '' : ' -aspect 16:9'
57
+ else " -aspect #{ratio}"
58
+ end
59
+ end
60
+
61
+ # @return [String] video dimensions comando conversao
62
+ def dimension
63
+ if bitrate < 480 then ' -s hd480'
64
+ elsif bitrate <= 720 then ' -s hd720'
65
+ else ' -s hd1080'
66
+ end
67
+ end
68
+
69
+ # @return [String] comando analise
70
+ def probe
71
+ "ffprobe -hide_banner -show_streams \"#{video}\" 2>&1|grep -v title"
72
+ end
73
+
74
+ # @return [String] comando conversao
75
+ def mpeg
76
+ "ffmpeg #{geral} -i #{video} -y -an " +
77
+ # framerate & bitrate
78
+ "-r #{[fps, 25].min} -b:v #{[bitrate, 2000].min}k" +
79
+ dimension + aspect_ratio + metadata
80
+ end
81
+
82
+ # Processa video
83
+ #
84
+ # @param [Array<String>] dar locais onde procurar videos
85
+ # @param [String] din pasta origem dos videos
86
+ # @param [String] out pasta destino dos videos
87
+ def processa(dar, din, out)
88
+ return if (bitrate < 3000 && ext == '.mp4') ||
89
+ Time.parse(duration) < Time.parse('00:01:00') ||
90
+ vdok?(dar, out)
91
+
92
+ system mpeg + " #{din}/#{out}/#{base}.mp4"
93
+ vfok?(HRVideo.new("#{din}/#{out}/#{base}.mp4"))
94
+ end
95
+
96
+ # @return [String] video: tempo: rate:
97
+ def rm_show
98
+ return video unless @probe
99
+
100
+ "#{video} tempo: #{duration} rate: #{bitrate} "
101
+ end
102
+
103
+ # @return [String] video: tempo: rate: y: framerate: ratio:
104
+ def testa
105
+ return video unless @probe
106
+
107
+ "#{base}#{ext} tempo: #{duration} rate: #{bitrate} " \
108
+ "y: #{height} framerate: #{fps} ratio: #{ratio}"
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evideo
4
+ VERSION = '0.1.3'
5
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evideo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
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.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ description: Processa ficheiros video. Pode alterar bitrate, framerate, height, aspect
56
+ 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/hrvprocessa.rb
77
+ - lib/evideo/version.rb
78
+ homepage: https://github.com/hernanilr/evideo
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ homepage_uri: https://github.com/hernanilr/evideo
83
+ yard.run: yard
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Processa ficheiros video.
103
+ test_files: []