evideo 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fe87ef3039e980666caeead4fd819fca47f1afd538e604b10b880b7935b6a8d
4
- data.tar.gz: 66ca91c021e17d30222c027d0c7a7ae48965b6910cc21cc80bbde4f6de6275cf
3
+ metadata.gz: 1e28f124268b83c747ed748296d09491c6955cb1b679952e76d0c78c3926de76
4
+ data.tar.gz: e92e5ac092e29017ec65a4799de589109f4400723421360a46bbd35af8b6645e
5
5
  SHA512:
6
- metadata.gz: 47548decc1ff1af5ac40ec347e495def27ac353bd93a2ca05297d26e53aeb6f96fb24178a837f25ad683c2cd2a9eff03c3e21e1040e265a9706b0afcf5185eb2
7
- data.tar.gz: 9cc43cd70a17dddf46fcaa56c5cff8ec7d40d41d7ac460a95ac5b7874c5cfb01e2d28994fbb81057c988dfbcc57e9d5bfdee79f0ca176ab9ed1ad56f5cf60c14
6
+ metadata.gz: 7bb0acee95ef8a2307bdc1b525d82293fca925bc94cd8031dfa860affddeb40b6e52cca607f6315dacc343cf0b89ca79125112fe075d33a1cb7a1a36c1cfeb7b
7
+ data.tar.gz: a7803cb72e5ff2105c3939deb56960babafba44fce72f26e9001e0191ca27b549110c8e87b1f556e725d10a3461f5792ade603f33646753d34a337c0c16307b0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- evideo (0.2.3)
4
+ evideo (0.2.4)
5
5
  thor
6
6
 
7
7
  GEM
@@ -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) }
@@ -10,14 +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'
13
+ class_option :d, banner: 'DIR', type: :array, desc: 'Onde procurar videos',
14
+ default: ["/home/#{ID}/lust", "/media/#{ID}/hrv2"]
16
15
  class_option :i, banner: 'IN', default: 'ftv', desc: 'Pasta origem'
17
16
  class_option :o, banner: 'OUT', default: 'out', desc: 'Pasta destino'
17
+
18
18
  desc 'conv', 'converte videos'
19
19
  option :t, type: :boolean, default: false, desc: 'Processa somente segundos para teste'
20
- # Processa videos
21
20
  def conv
22
21
  Dir.glob("#{fin}/*.???").sort.each do |f|
23
22
  HRVideo.new(f).processa(options, fout)
@@ -25,13 +24,13 @@ module Evideo
25
24
  end
26
25
 
27
26
  desc 'test', 'testa videos'
28
- # Analisa videos
29
27
  def test
30
28
  Dir.glob("#{fin}/*.???").sort.each do |f|
31
29
  HRVideo.new(f).testa(options, fout)
32
30
  end
33
31
  end
34
- default_task :conv
32
+
33
+ default_task :test
35
34
  no_commands do
36
35
  # @return [String] pasta absoluta origem dos videos
37
36
  def fin
@@ -2,19 +2,17 @@
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
- # @return [String] frequencia audio do ficheiro video
17
- attr_reader :audio
18
16
 
19
17
  # Duration: 01:01:08.50, start: 0.000000, bitrate: 2228 kb/s
20
18
  R1 = /duration:\s+(\d\d:\d\d:\d\d).*bitrate:\s+(\d+)\s+kb/i.freeze
@@ -27,17 +25,17 @@ module Evideo
27
25
  # Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
28
26
  R4 = /stream.*audio:.*\s+(\d+)\s+hz/i.freeze
29
27
 
30
- def initialize(fvideo)
31
- @video = fvideo
32
- @ext = File.extname(fvideo)
33
- @base = File.basename(fvideo, @ext).downcase
34
- @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'
35
33
  @bitrate = 0
36
- @probe = `#{cmd_probe}` if File.exist?(fvideo)
34
+ @probe = `#{cmd_probe}` if File.exist?(fil)
37
35
  return unless @probe
38
36
 
39
37
  tr1 = @probe.scan(R1).flatten
40
- @duration = tr1[0].to_s
38
+ @tempo = tr1[0].to_s
41
39
  @bitrate = tr1[1].to_i
42
40
  end
43
41
 
@@ -4,36 +4,41 @@ 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
17
  # @param [String] aot pasta destino dos videos absoluta
18
- # @return [true, false] sim ou nao video esta ok
18
+ # @return [true, false] sim ou nao video original esta ok
19
19
  def ofok?(aot)
20
- return false unless (bitrate < 3000 && ext == '.mp4') || Time.parse(duration) < Time.parse('00:01:00')
21
- return false unless ratio == '16:9' && height > 480
22
- return false unless audio == 0
20
+ return false unless processa_of?
23
21
 
24
- puts "mv \"#{video} #{aot}/#{base}.mp4\" # #{show}"
22
+ puts "mv \"#{nome} #{aot}/#{base}.mp4\" # #{show}"
25
23
  true
26
24
  end
27
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
+
28
34
  # Testa validade video processado contra video original
29
35
  #
30
- # @param [String] file video processado a testar validade
36
+ # @param [String] hrv video processado a testar validade
31
37
  # @return [true, false] sim ou nao video esta ok
32
- def vfok?(file)
33
- return false unless File.exist?(file.video) &&
34
- file.bitrate < 3000 && 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
 
@@ -52,7 +57,7 @@ module Evideo
52
57
  # @return [String] aspect ratio comando conversao
53
58
  def aspect
54
59
  if ratio == '0:1' then height < 720 ? '' : ' -aspect 16:9'
55
- else " -aspect #{ratio}"
60
+ else " -aspect #{ratio}"
56
61
  end
57
62
  end
58
63
 
@@ -66,7 +71,7 @@ module Evideo
66
71
 
67
72
  # @return [String] comando analise
68
73
  def cmd_probe
69
- "ffprobe -hide_banner -show_streams \"#{video}\" 2>&1|grep -v title"
74
+ "ffprobe -hide_banner -show_streams \"#{nome}\" 2>&1|grep -v title"
70
75
  end
71
76
 
72
77
  # Comando para processar videos
@@ -74,17 +79,18 @@ module Evideo
74
79
  # @param [String] tempo do video processado
75
80
  # @return [String] comando conversao
76
81
  def cmd_mpeg(tempo)
77
- puts "processar #{base}.mp4 -r #{[fps, 25].min} -b:v #{[bitrate, 2000].min}k" + dimension + aspect + tempo
78
- "ffmpeg #{geral} -i \"#{video}\" -y -an " +
79
- # framerate & bitrate
80
- "-r #{[fps, 25].min} -b:v #{[bitrate, 2000].min}k" +
81
- dimension + aspect +
82
- ' -metadata title= -metadata artist= -metadata comment=' \
83
- ' -metadata major_brand= -metadata compatible_brands=' +
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=' +
84
85
  # para teste produz somente segundos
85
86
  tempo
86
87
  end
87
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
+
88
94
  # @return [String] opcoes gerais comando conversao
89
95
  def geral
90
96
  '-loglevel quiet -hide_banner' +
@@ -119,7 +125,7 @@ module Evideo
119
125
  def testa(opcoes, aot)
120
126
  return if ofok?(aot) || vdok?(opcoes[:d], opcoes[:o])
121
127
 
122
- puts "ls \"#{video}\" # #{show}"
128
+ puts "ls -lh \"#{nome}\" # #{show}"
123
129
  end
124
130
  end
125
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Evideo
4
- VERSION = '0.2.3'
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.2.3
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-07-20 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