evideo 0.1.7 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8606bfbd9f0c7ba938bec7202751ad943b1ca67ee35099165d129d49a2897b0c
4
- data.tar.gz: e960f31a33ebed6c26d1295ecaa9c595c846242d335a157db0766d40b3b69155
3
+ metadata.gz: 1e28f124268b83c747ed748296d09491c6955cb1b679952e76d0c78c3926de76
4
+ data.tar.gz: e92e5ac092e29017ec65a4799de589109f4400723421360a46bbd35af8b6645e
5
5
  SHA512:
6
- metadata.gz: 37f629b884f5ba6872a4f28e274caa7e4dcc4dc06828b2a43cf7933d7d6b571a2eda2cbd30fb5e68795559932f32606efb5bd5413526cd219a75e21af4e4ccca
7
- data.tar.gz: 395e200817a3af2045535861d598bce990f654f2e730e271d6a7aeb52049a13ed87abfcdc98ee1a2aceffed32a79ff4107a5159cb0a78d4376241c3be97aab2a
6
+ metadata.gz: 7bb0acee95ef8a2307bdc1b525d82293fca925bc94cd8031dfa860affddeb40b6e52cca607f6315dacc343cf0b89ca79125112fe075d33a1cb7a1a36c1cfeb7b
7
+ data.tar.gz: a7803cb72e5ff2105c3939deb56960babafba44fce72f26e9001e0191ca27b549110c8e87b1f556e725d10a3461f5792ade603f33646753d34a337c0c16307b0
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- evideo (0.1.7)
5
- thor (~> 0.1)
4
+ evideo (0.2.4)
5
+ thor
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  rake (13.0.1)
11
- thor (0.20.3)
11
+ thor (1.0.1)
12
12
 
13
13
  PLATFORMS
14
14
  ruby
@@ -19,4 +19,4 @@ DEPENDENCIES
19
19
  rake
20
20
 
21
21
  BUNDLED WITH
22
- 1.17.2
22
+ 2.1.2
@@ -13,9 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.license = 'MIT'
14
14
 
15
15
  spec.summary = 'Processa ficheiros video.'
16
- spec.description = spec.summary +
17
- ' Pode alterar bitrate, framerate, height,' \
18
- ' aspect ratio e elimina metadata.'
16
+ spec.description = spec.summary + ' Pode alterar bitrate, framerate, height, aspect ratio e elimina metadata.'
19
17
 
20
18
  spec.metadata['homepage_uri'] = spec.homepage
21
19
  spec.metadata['yard.run'] = 'yard'
@@ -24,8 +22,7 @@ Gem::Specification.new do |spec|
24
22
  # The `git ls-files -z` loads the files in the RubyGem that have been
25
23
  # added into git.
26
24
  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)/}) }
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
26
  end
30
27
  spec.bindir = 'exe'
31
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -34,5 +31,5 @@ Gem::Specification.new do |spec|
34
31
  spec.add_development_dependency 'bundler'
35
32
  spec.add_development_dependency 'rake'
36
33
 
37
- spec.add_dependency 'thor', '~> 0.1'
34
+ spec.add_dependency 'thor'
38
35
  end
@@ -10,17 +10,13 @@ module Evideo
10
10
  ID = `whoami`.chomp
11
11
  # CLI para analisar/processar videos
12
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'
13
+ class_option :d, banner: 'DIR', type: :array, desc: 'Onde procurar videos',
14
+ default: ["/home/#{ID}/lust", "/media/#{ID}/hrv2"]
15
+ class_option :i, banner: 'IN', default: 'ftv', desc: 'Pasta origem'
16
+ class_option :o, banner: 'OUT', default: 'out', desc: 'Pasta destino'
17
+
18
18
  desc 'conv', 'converte videos'
19
- option :o, banner: 'OUT', default: 'out',
20
- desc: 'Pasta destino'
21
- option :t, type: :boolean, default: false,
22
- desc: 'Processa somente segundos para teste'
23
- # Processa videos
19
+ option :t, type: :boolean, default: false, desc: 'Processa somente segundos para teste'
24
20
  def conv
25
21
  Dir.glob("#{fin}/*.???").sort.each do |f|
26
22
  HRVideo.new(f).processa(options, fout)
@@ -28,13 +24,13 @@ module Evideo
28
24
  end
29
25
 
30
26
  desc 'test', 'testa videos'
31
- # Analisa videos
32
27
  def test
33
28
  Dir.glob("#{fin}/*.???").sort.each do |f|
34
- HRVideo.new(f).testa(options)
29
+ HRVideo.new(f).testa(options, fout)
35
30
  end
36
31
  end
37
- default_task :conv
32
+
33
+ default_task :test
38
34
  no_commands do
39
35
  # @return [String] pasta absoluta origem dos videos
40
36
  def fin
@@ -2,15 +2,15 @@
2
2
 
3
3
  module Evideo
4
4
  # permite analizar string output do comando sonda video
5
- class HRVideo < String
5
+ class HRVideo
6
6
  # @return [String] nome do ficheiro video
7
- attr_reader :video
7
+ attr_reader :nome
8
8
  # @return [String] extensao do ficheiro video
9
9
  attr_reader :ext
10
10
  # @return [String] base do ficheiro video
11
11
  attr_reader :base
12
12
  # @return [String] duracao do ficheiro video
13
- attr_reader :duration
13
+ attr_reader :tempo
14
14
  # @return [String] bitrate do ficheiro video
15
15
  attr_reader :bitrate
16
16
 
@@ -21,18 +21,21 @@ module Evideo
21
21
  R2 = /stream.*video:.*x\s*(\d+).*\s+(\d+\.*\d*)\s+fps/i.freeze
22
22
  # display_aspect_ratio=16:9
23
23
  R3 = /display_aspect_ratio\s*=\s*(\d+:\d+)$/i.freeze
24
+ # Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
25
+ # Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
26
+ R4 = /stream.*audio:.*\s+(\d+)\s+hz/i.freeze
24
27
 
25
- def initialize(fvideo)
26
- @video = fvideo
27
- @ext = File.extname(fvideo)
28
- @base = File.basename(fvideo, @ext).downcase
29
- @duration = '00:00:00'
28
+ def initialize(fil)
29
+ @nome = fil
30
+ @ext = File.extname(fil)
31
+ @base = File.basename(fil, @ext).downcase
32
+ @tempo = '00:00:00'
30
33
  @bitrate = 0
31
- @probe = `#{probe}` if File.exist?(fvideo)
34
+ @probe = `#{cmd_probe}` if File.exist?(fil)
32
35
  return unless @probe
33
36
 
34
37
  tr1 = @probe.scan(R1).flatten
35
- @duration = tr1[0].to_s
38
+ @tempo = tr1[0].to_s
36
39
  @bitrate = tr1[1].to_i
37
40
  end
38
41
 
@@ -52,6 +55,20 @@ module Evideo
52
55
  @ratio = @probe.scan(R3).flatten[0]
53
56
  end
54
57
 
58
+ # Parametrizar audio
59
+ def r4
60
+ return unless @probe
61
+
62
+ @audio = @probe.scan(R4).flatten[0].to_i
63
+ end
64
+
65
+ # @return [String] audio
66
+ def audio
67
+ r4 unless @audio
68
+
69
+ @audio
70
+ end
71
+
55
72
  # @return [String] height
56
73
  def height
57
74
  r2 unless @height
@@ -4,63 +4,60 @@ require 'time'
4
4
 
5
5
  module Evideo
6
6
  # permite analizar/processar videos para arquivo
7
- class HRVideo < String
7
+ class HRVideo
8
8
  # @return [String] tempo: rate:
9
9
  def show
10
- return video unless @probe
10
+ return nome unless @probe
11
11
 
12
- "tempo: #{duration} rate: #{bitrate} ratio: #{ratio} height: #{height}"
12
+ "tempo: #{tempo} rate: #{bitrate} ratio: #{ratio} height: #{height}"
13
13
  end
14
14
 
15
15
  # Testa validade video original
16
16
  #
17
- # @return [true, false] sim ou nao video esta ok
18
- def ofok?
19
- return false unless (bitrate < 3000 && ext == '.mp4') ||
20
- Time.parse(duration) < Time.parse('00:01:00')
21
- return false unless ratio == '16:9' && height > 480
17
+ # @param [String] aot pasta destino dos videos absoluta
18
+ # @return [true, false] sim ou nao video original esta ok
19
+ def ofok?(aot)
20
+ return false unless processa_of?
22
21
 
23
- puts "rm \"#{video}\" # #{show}"
22
+ puts "mv \"#{nome} #{aot}/#{base}.mp4\" # #{show}"
24
23
  true
25
24
  end
26
25
 
26
+ # @return [true, false] video original precisa ser processado?
27
+ def processa_of?
28
+ # prossecar somente videos grandes (>1 min) ou extensao errada ou bitrate >= 3000
29
+ ((bitrate < 3000 && ext == '.mp4') || Time.parse(tempo) < Time.parse('00:01:00')) &&
30
+ # prossecar somente videos com ratio, height, audio errados
31
+ ratio == '16:9' && height > 480 && audio.zero?
32
+ end
33
+
27
34
  # Testa validade video processado contra video original
28
35
  #
29
- # @param [String] file video processado a testar validade
36
+ # @param [String] hrv video processado a testar validade
30
37
  # @return [true, false] sim ou nao video esta ok
31
- def vfok?(file)
32
- return false unless File.exist?(file.video) &&
33
- file.bitrate < 3000 &&
34
- Time.parse(file.duration) > Time.parse(duration) - 60
38
+ def vfok?(hrv)
39
+ return false unless File.exist?(hrv.nome) && hrv.bitrate < 3000 && Time.parse(hrv.tempo) > Time.parse(tempo) - 60
35
40
 
36
- puts "rm \"#{video}\" # #{file.video} #{file.show}"
41
+ puts "rm \"#{nome}\" # #{hrv.nome} #{hrv.show}"
37
42
  true
38
43
  end
39
44
 
40
45
  # Testa validade videos processados em todos locais contra video original
41
46
  #
42
47
  # @param [Array<String>] ary array locais onde procurar videos
43
- # @param [String] out pasta destino dos videos
48
+ # @param [String] pot pasta destino dos videos
44
49
  # @return [true, false] sim ou nao <local>/<video> esta ok
45
- def vdok?(ary, out)
50
+ def vdok?(ary, pot)
46
51
  if ary.empty? then false
47
- elsif vfok?(HRVideo.new("#{ary.first}/#{out}/#{base}.mp4")) then true
48
- else vdok?(ary.drop(1), out)
52
+ elsif vfok?(HRVideo.new("#{ary.first}/#{pot}/#{base}.mp4")) then true
53
+ else vdok?(ary.drop(1), pot)
49
54
  end
50
55
  end
51
56
 
52
- # @return [String] opcoes gerais comando conversao
53
- def geral
54
- '-loglevel quiet -hide_banner' +
55
- # para ignorar segundos no inicio
56
- # ' -ss 15' \
57
- ''
58
- end
59
-
60
57
  # @return [String] aspect ratio comando conversao
61
58
  def aspect
62
59
  if ratio == '0:1' then height < 720 ? '' : ' -aspect 16:9'
63
- else " -aspect #{ratio}"
60
+ else " -aspect #{ratio}"
64
61
  end
65
62
  end
66
63
 
@@ -73,25 +70,35 @@ module Evideo
73
70
  end
74
71
 
75
72
  # @return [String] comando analise
76
- def probe
77
- "ffprobe -hide_banner -show_streams \"#{video}\" 2>&1|grep -v title"
73
+ def cmd_probe
74
+ "ffprobe -hide_banner -show_streams \"#{nome}\" 2>&1|grep -v title"
78
75
  end
79
76
 
80
77
  # Comando para processar videos
81
78
  #
82
- # @param [String] tempo do video processato
79
+ # @param [String] tempo do video processado
83
80
  # @return [String] comando conversao
84
- def mpeg(tempo)
85
- "ffmpeg #{geral} -i \"#{video}\" -y -an " +
86
- # framerate & bitrate
87
- "-r #{[fps, 25].min} -b:v #{[bitrate, 2000].min}k" +
88
- dimension + aspect +
89
- ' -metadata title= -metadata artist= -metadata comment=' \
90
- ' -metadata major_brand= -metadata compatible_brands=' +
81
+ def cmd_mpeg(tempo)
82
+ puts "processar #{base}.mp4 " + join_opcoes
83
+ "ffmpeg #{geral} -i \"#{nome}\" -y -an " + join_opcoes +
84
+ ' -metadata title= -metadata artist= -metadata comment= -metadata major_brand= -metadata compatible_brands=' +
91
85
  # para teste produz somente segundos
92
86
  tempo
93
87
  end
94
88
 
89
+ # @return [String] opcoes para trabalho framerate & bitrate & dimenssoes
90
+ def join_opcoes
91
+ "-r #{[fps, 25].min} -b:v #{[bitrate, 2000].min}k" + dimension + aspect
92
+ end
93
+
94
+ # @return [String] opcoes gerais comando conversao
95
+ def geral
96
+ '-loglevel quiet -hide_banner' +
97
+ # para ignorar segundos no inicio
98
+ # ' -ss 15' \
99
+ ''
100
+ end
101
+
95
102
  # Processa videos
96
103
  #
97
104
  # @param [Hash] opcoes parametrizacao
@@ -99,12 +106,12 @@ module Evideo
99
106
  # @option opcoes [<String>] :i pasta origem dos videos
100
107
  # @option opcoes [<String>] :o pasta destino dos videos
101
108
  # @option opcoes [<Boolean>] :t processa somente segundos para teste
102
- # @param [String] out pasta destino dos videos absoluta
103
- def processa(opcoes, out)
104
- return if ofok? || vdok?(opcoes[:d], opcoes[:o])
109
+ # @param [String] aot pasta destino dos videos absoluta
110
+ def processa(opcoes, aot)
111
+ return if ofok?(aot) || vdok?(opcoes[:d], opcoes[:o])
105
112
 
106
- system mpeg(opcoes[:t] ? ' -t 20' : '') + " #{out}/#{base}.mp4"
107
- vfok?(HRVideo.new("#{out}/#{base}.mp4"))
113
+ system cmd_mpeg(opcoes[:t] ? ' -t 20' : '') + " #{aot}/#{base}.mp4"
114
+ vfok?(HRVideo.new("#{aot}/#{base}.mp4"))
108
115
  end
109
116
 
110
117
  # Testa videos
@@ -114,10 +121,11 @@ module Evideo
114
121
  # @option opcoes [<String>] :i pasta origem dos videos
115
122
  # @option opcoes [<String>] :o pasta destino dos videos
116
123
  # @option opcoes [<Boolean>] :t processa somente segundos para teste
117
- def testa(opcoes)
118
- return if ofok? || vdok?(opcoes[:d], opcoes[:o])
124
+ # @param [String] aot pasta destino dos videos absoluta
125
+ def testa(opcoes, aot)
126
+ return if ofok?(aot) || vdok?(opcoes[:d], opcoes[:o])
119
127
 
120
- puts "ls \"#{video}\" # #{show}"
128
+ puts "ls -lh \"#{nome}\" # #{show}"
121
129
  end
122
130
  end
123
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Evideo
4
- VERSION = '0.1.7'
4
+ VERSION = '0.2.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evideo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-04 00:00:00.000000000 Z
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0.1'
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0.1'
54
+ version: '0'
55
55
  description: Processa ficheiros video. Pode alterar bitrate, framerate, height, aspect
56
56
  ratio e elimina metadata.
57
57
  email:
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.0.3
101
+ rubygems_version: 3.1.2
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Processa ficheiros video.