venus_video 0.1.1 → 0.3.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/venus.rb +109 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d68e7bda30458620073f7a6da9637b3f5dbcb42b1e59e099594e3d8ad817236
4
- data.tar.gz: 3acb27ed154f7de740878d9e44888bece3d32904c5c6552c20f74e93565a964f
3
+ metadata.gz: c5baf63783ab590a23d4a88870cd42ed127c50614141eb17ad5d29f5783e55e1
4
+ data.tar.gz: e72d5df9e471aab1d7e0d05a9326bb00fc4e45b23d40723e4dba9e81402f59d7
5
5
  SHA512:
6
- metadata.gz: ab4170473debd7a9ba36644ffa68487149db858e1d26840a1f5c4b939567027e1c22f1b99a4a15296485d8ba650a9fba672f23b8d9a5cd588337d245d4bc4d2a
7
- data.tar.gz: 9f1c45470d496275c48d20ff2f91cc8ff12329947cc2d37d00e3064e6a3177da2a3b194d6bf9cab5c01044d7a3b8c736477b8420646965727216b2c06e49c87c
6
+ metadata.gz: 8f01d55ad8f331500548384d86b454808618072bad24d5d79d6eda20bf5987bfe7c7b2bb4cfc75ecb342822e9a733a716b845eeb79e3dd22a9d615fcf23b1b82
7
+ data.tar.gz: 6d4737b9d4fe43fdd9731d04b203e39f8c14ca5c48738b3dd2d84df94b88f857a80971f8f153f7fba22c885571579253a84946d2bc9e6caaab93d3cb37598a94
data/lib/venus.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require 'open3'
2
+ require 'tempfile'
2
3
 
3
4
  module Venus
4
5
  class SplitVideo
5
6
  def self.split_video(input_file, output_prefix, format_segment, segment_duration, path: nil, format_video: nil)
6
- if format_segment == "min"
7
+ if format_segment == 'min'
7
8
  segment_duration = segment_duration.to_i * 60
8
- elsif format_segment == "hour"
9
+ elsif format_segment == 'hour'
9
10
  segment_duration = segment_duration.to_i * 3600
10
- elsif format_segment == "sek"
11
+ elsif format_segment == 'sek'
11
12
  segment_duration = segment_duration.to_i
12
13
  else
13
14
  puts "Invalid format. Use 'min', 'hour' or 'sek'."
@@ -18,12 +19,12 @@ module Venus
18
19
 
19
20
  if format_video
20
21
  case format_video
21
- when "first"
22
+ when 'first'
22
23
  output_path = path ? File.join(path, "#{output_prefix}_001.mp4") : "#{output_prefix}_001.mp4"
23
24
  command = "ffmpeg -i #{input_file} -c copy -map 0 -t #{segment_duration} #{output_path}"
24
- when "end"
25
+ when 'end'
25
26
  command = "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
26
- Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
27
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
27
28
  while line = stderr.gets
28
29
  puts line
29
30
  end
@@ -41,7 +42,7 @@ module Venus
41
42
  else
42
43
  range = eval(format_video)
43
44
  command = "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
44
- Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
45
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
45
46
  while line = stderr.gets
46
47
  puts line
47
48
  end
@@ -55,9 +56,7 @@ module Venus
55
56
  parts = Dir.glob("#{output_prefix}_*.mp4")
56
57
  parts.sort!
57
58
  parts.each_with_index do |part, index|
58
- unless range.include?(index + 1)
59
- File.delete(part)
60
- end
59
+ File.delete(part) unless range.include?(index + 1)
61
60
  end
62
61
  return
63
62
  end
@@ -65,7 +64,7 @@ module Venus
65
64
  command = "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
66
65
  end
67
66
 
68
- Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
67
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
69
68
  while line = stderr.gets
70
69
  puts line
71
70
  end
@@ -81,10 +80,108 @@ module Venus
81
80
  def self.process_arguments(args_string)
82
81
  args = args_string.split
83
82
  if args.length < 4 || args.length > 6
84
- puts "Usage: ruby main.rb <input_file> <output_prefix> <format_segment> <segment_duration> [path] [format_video]"
83
+ puts 'Usage: ruby main.rb <input_file> <output_prefix> <format_segment> <segment_duration> [path] [format_video]'
85
84
  exit 1
86
85
  end
87
86
  args
88
87
  end
89
88
  end
89
+
90
+ class JoinVideo
91
+ def self.join_video(input_file1, input_file2, output_file, path: nil)
92
+ [input_file1, input_file2].each do |file|
93
+ unless File.exist?(file)
94
+ puts "File not found: #{file}"
95
+ exit 1
96
+ end
97
+ end
98
+
99
+ output_file = "#{output_file}.mp4" unless output_file.end_with?('.mp4')
100
+
101
+ output_path = path ? File.join(path, output_file) : File.join(Dir.pwd, output_file)
102
+
103
+ temp_file = Tempfile.new('input_list')
104
+ temp_file.puts("file '#{File.absolute_path(input_file1)}'")
105
+ temp_file.puts("file '#{File.absolute_path(input_file2)}'")
106
+ temp_file.close
107
+
108
+ command = "ffmpeg -f concat -safe 0 -i #{temp_file.path} -c copy #{output_path}"
109
+
110
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
111
+ while line = stderr.gets
112
+ puts line
113
+ end
114
+
115
+ exit_status = wait_thr.value
116
+ unless exit_status.success?
117
+ puts "Error executing command: #{command}"
118
+ exit 1
119
+ end
120
+ end
121
+
122
+ temp_file.unlink
123
+ end
124
+
125
+ def self.process_arguments(args_string)
126
+ args = args_string.split
127
+ if args.length != 3
128
+ puts 'Usage: ruby main.rb <input_file1> <input_file2> <output_file>'
129
+ exit 1
130
+ end
131
+
132
+ input_file1 = args[0]
133
+ input_file2 = args[1]
134
+ output_file = args[2]
135
+
136
+ [input_file1, input_file2, output_file]
137
+ end
138
+ end
139
+
140
+ class BlurVideo
141
+ def self.blur_video(input_file, output_file, path: nil, blur_intensity: 20)
142
+ unless File.exist?(input_file)
143
+ puts "File not found: #{input_file}"
144
+ exit 1
145
+ end
146
+
147
+ # Проверка на допустимость blur_intensity
148
+ unless blur_intensity.is_a?(Numeric) && blur_intensity >= 0
149
+ puts "Invalid blur intensity. It should be a non-negative number."
150
+ exit 1
151
+ end
152
+
153
+ output_file = "#{output_file}.mp4" unless output_file.end_with?('.mp4')
154
+
155
+ output_path = path ? File.join(path, output_file) : File.join(Dir.pwd, output_file)
156
+
157
+ command = "ffmpeg -i #{input_file} -vf 'boxblur=#{blur_intensity}:1' -c:a copy #{output_path}"
158
+
159
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
160
+ while line = stderr.gets
161
+ puts line
162
+ end
163
+
164
+ exit_status = wait_thr.value
165
+ unless exit_status.success?
166
+ puts "Error executing command: #{command}"
167
+ exit 1
168
+ end
169
+ end
170
+ end
171
+
172
+ def self.process_arguments(args_string)
173
+ args = args_string.split
174
+
175
+ # Проверяем количество аргументов
176
+ if args.length < 2 || args.length > 4
177
+ puts 'Usage: ruby main.rb <input_file> <output_file> [path] [blur_intensity]'
178
+ exit 1
179
+ end
180
+
181
+ input_file = args[0]
182
+ output_file = args[1]
183
+
184
+ [input_file, output_file]
185
+ end
186
+ end
90
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: venus_video
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - acm-wq