venus_video 0.3.0 → 0.3.1

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: c5baf63783ab590a23d4a88870cd42ed127c50614141eb17ad5d29f5783e55e1
4
- data.tar.gz: e72d5df9e471aab1d7e0d05a9326bb00fc4e45b23d40723e4dba9e81402f59d7
3
+ metadata.gz: a353f1e1c524fed2cd1eda2d913509c188f6b54de3be594245b88c5cacc58fbf
4
+ data.tar.gz: 438235dd90ee3768f3d45b5b57b8c4f9e7fb12ab4de93fa913a04735432da40c
5
5
  SHA512:
6
- metadata.gz: 8f01d55ad8f331500548384d86b454808618072bad24d5d79d6eda20bf5987bfe7c7b2bb4cfc75ecb342822e9a733a716b845eeb79e3dd22a9d615fcf23b1b82
7
- data.tar.gz: 6d4737b9d4fe43fdd9731d04b203e39f8c14ca5c48738b3dd2d84df94b88f857a80971f8f153f7fba22c885571579253a84946d2bc9e6caaab93d3cb37598a94
6
+ metadata.gz: e187116ba03a3b2cde7ea838c461078e0c8131b9db90f7a90174d72da8f352b3acdce3bf221c3a91b346fc118697b3d30b8f46e708a770bbcb644f79992250b8
7
+ data.tar.gz: 94f007804ef6e14fe919d8eb96b0661c8cbb04bbd4feb97599840f7f0c4b59a3036e9a675f70ee60cd7a358e15357dffa5299fbc54c10732d7b56a9501300cdd
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Venus
4
+ class BlurVideo
5
+ def self.blur_video(input_file, output_file, path: nil, blur_intensity: 20)
6
+ unless File.exist?(input_file)
7
+ puts "File not found: #{input_file}"
8
+ exit 1
9
+ end
10
+
11
+ unless blur_intensity.is_a?(Numeric) && blur_intensity >= 0
12
+ puts 'Invalid blur intensity. It should be a non-negative number.'
13
+ exit 1
14
+ end
15
+
16
+ output_file = "#{output_file}.mp4" unless output_file.end_with?('.mp4')
17
+ output_path = path ? File.join(path, output_file) : File.join(Dir.pwd, output_file)
18
+
19
+ command = "ffmpeg -i #{input_file} -vf 'boxblur=#{blur_intensity}:1' -c:a copy #{output_path}"
20
+ execute_command(command)
21
+ end
22
+
23
+ def self.execute_command(command)
24
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
25
+ while (line = stderr.gets)
26
+ puts line
27
+ end
28
+
29
+ exit_status = wait_thr.value
30
+ unless exit_status.success?
31
+ puts "Error executing command: #{command}"
32
+ exit 1
33
+ end
34
+ end
35
+ end
36
+
37
+ def self.process_arguments(args_string)
38
+ args = args_string.split
39
+
40
+ if args.length < 2 || args.length > 4
41
+ puts 'Usage: ruby main.rb <input_file> <output_file> [path] [blur_intensity]'
42
+ exit 1
43
+ end
44
+
45
+ args
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Venus
4
+ class JoinVideo
5
+ def self.join_video(input_file1, input_file2, output_file, path: nil)
6
+ [input_file1, input_file2].each do |file|
7
+ unless File.exist?(file)
8
+ puts "File not found: #{file}"
9
+ exit 1
10
+ end
11
+ end
12
+
13
+ output_file = "#{output_file}.mp4" unless output_file.end_with?('.mp4')
14
+ output_path = path ? File.join(path, output_file) : File.join(Dir.pwd, output_file)
15
+
16
+ temp_file = Tempfile.new('input_list')
17
+ temp_file.puts("file '#{File.absolute_path(input_file1)}'")
18
+ temp_file.puts("file '#{File.absolute_path(input_file2)}'")
19
+ temp_file.close
20
+
21
+ command = "ffmpeg -f concat -safe 0 -i #{temp_file.path} -c copy #{output_path}"
22
+ execute_command(command)
23
+
24
+ temp_file.unlink
25
+ end
26
+
27
+ def self.execute_command(command)
28
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
29
+ while (line = stderr.gets)
30
+ puts line
31
+ end
32
+
33
+ exit_status = wait_thr.value
34
+ unless exit_status.success?
35
+ puts "Error executing command: #{command}"
36
+ exit 1
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.process_arguments(args_string)
42
+ args = args_string.split
43
+ if args.length != 3
44
+ puts 'Usage: ruby main.rb <input_file1> <input_file2> <output_file>'
45
+ exit 1
46
+ end
47
+
48
+ args
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Venus
4
+ class SplitVideo
5
+ def self.split_video(input_file, output_prefix, format_segment, segment_duration, path: nil, format_video: nil)
6
+ segment_duration = convert_duration(format_segment, segment_duration)
7
+ return unless segment_duration
8
+
9
+ output_path = path ? File.join(path, "#{output_prefix}_%03d.mp4") : "#{output_prefix}_%03d.mp4"
10
+
11
+ command = build_command(input_file, output_path, segment_duration, format_video, path, output_prefix)
12
+ execute_command(command)
13
+
14
+ handle_format_video(format_video, output_prefix, segment_duration, path) if format_video
15
+ end
16
+
17
+ def self.convert_duration(format_segment, segment_duration)
18
+ case format_segment
19
+ when 'min'
20
+ segment_duration.to_i * 60
21
+ when 'hour'
22
+ segment_duration.to_i * 3600
23
+ when 'sek'
24
+ segment_duration.to_i
25
+ else
26
+ puts "Invalid format. Use 'min', 'hour' or 'sek'."
27
+ nil
28
+ end
29
+ end
30
+
31
+ def self.build_command(input_file, output_path, segment_duration, format_video, path, output_prefix)
32
+ if format_video == 'first'
33
+ output_path = path ? File.join(path, "#{output_prefix}_001.mp4") : "#{output_prefix}_001.mp4"
34
+ "ffmpeg -i #{input_file} -c copy -map 0 -t #{segment_duration} #{output_path}"
35
+ else
36
+ "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
37
+ end
38
+ end
39
+
40
+ def self.execute_command(command)
41
+ Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
42
+ while (line = stderr.gets)
43
+ puts line
44
+ end
45
+
46
+ exit_status = wait_thr.value
47
+ unless exit_status.success?
48
+ puts "Error executing command: #{command}"
49
+ exit 1
50
+ end
51
+ end
52
+ end
53
+
54
+ def self.handle_format_video(format_video, output_prefix, _segment_duration, _path)
55
+ parts = Dir.glob("#{output_prefix}_*.mp4").sort
56
+ case format_video
57
+ when 'end'
58
+ File.delete(*parts[0...-1]) if parts.length > 1
59
+ else
60
+ range = eval(format_video)
61
+ parts.each_with_index { |part, index| File.delete(part) unless range.include?(index + 1) }
62
+ end
63
+ end
64
+
65
+ def self.process_arguments(args_string)
66
+ args = args_string.split
67
+ if args.length < 4 || args.length > 6
68
+ puts 'Usage: ruby main.rb <input_file> <output_prefix> <format_segment> <segment_duration> [path] [format_video]'
69
+ exit 1
70
+ end
71
+ args
72
+ end
73
+ end
74
+ end
data/lib/venus.rb CHANGED
@@ -1,187 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open3'
2
4
  require 'tempfile'
5
+ require_relative 'components/split_video'
6
+ require_relative 'components/join_video'
7
+ require_relative 'components/blur_video'
3
8
 
4
9
  module Venus
5
- class SplitVideo
6
- def self.split_video(input_file, output_prefix, format_segment, segment_duration, path: nil, format_video: nil)
7
- if format_segment == 'min'
8
- segment_duration = segment_duration.to_i * 60
9
- elsif format_segment == 'hour'
10
- segment_duration = segment_duration.to_i * 3600
11
- elsif format_segment == 'sek'
12
- segment_duration = segment_duration.to_i
13
- else
14
- puts "Invalid format. Use 'min', 'hour' or 'sek'."
15
- exit 1
16
- end
17
-
18
- output_path = path ? File.join(path, "#{output_prefix}_%03d.mp4") : "#{output_prefix}_%03d.mp4"
19
-
20
- if format_video
21
- case format_video
22
- when 'first'
23
- output_path = path ? File.join(path, "#{output_prefix}_001.mp4") : "#{output_prefix}_001.mp4"
24
- command = "ffmpeg -i #{input_file} -c copy -map 0 -t #{segment_duration} #{output_path}"
25
- when 'end'
26
- command = "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
27
- Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
28
- while line = stderr.gets
29
- puts line
30
- end
31
-
32
- exit_status = wait_thr.value
33
- unless exit_status.success?
34
- puts "Error executing command: #{command}"
35
- exit 1
36
- end
37
- end
38
- parts = Dir.glob("#{output_prefix}_*.mp4")
39
- parts.sort!
40
- File.delete(*parts[0...-1]) if parts.length > 1
41
- return
42
- else
43
- range = eval(format_video)
44
- command = "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
45
- Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
46
- while line = stderr.gets
47
- puts line
48
- end
49
-
50
- exit_status = wait_thr.value
51
- unless exit_status.success?
52
- puts "Error executing command: #{command}"
53
- exit 1
54
- end
55
- end
56
- parts = Dir.glob("#{output_prefix}_*.mp4")
57
- parts.sort!
58
- parts.each_with_index do |part, index|
59
- File.delete(part) unless range.include?(index + 1)
60
- end
61
- return
62
- end
63
- else
64
- command = "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
65
- end
66
-
67
- Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
68
- while line = stderr.gets
69
- puts line
70
- end
71
-
72
- exit_status = wait_thr.value
73
- unless exit_status.success?
74
- puts "Error executing command: #{command}"
75
- exit 1
76
- end
77
- end
78
- end
79
-
80
- def self.process_arguments(args_string)
81
- args = args_string.split
82
- if args.length < 4 || args.length > 6
83
- puts 'Usage: ruby main.rb <input_file> <output_prefix> <format_segment> <segment_duration> [path] [format_video]'
84
- exit 1
85
- end
86
- args
87
- end
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
187
- end
10
+ end
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: venus_video
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - acm-wq
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
10
  date: 2024-09-22 00:00:00.000000000 Z
@@ -17,12 +16,14 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
19
+ - lib/components/blur_video.rb
20
+ - lib/components/join_video.rb
21
+ - lib/components/split_video.rb
20
22
  - lib/venus.rb
21
23
  homepage: https://github.com/acm-wq/venus
22
24
  licenses:
23
25
  - MIT
24
26
  metadata: {}
25
- post_install_message:
26
27
  rdoc_options: []
27
28
  require_paths:
28
29
  - lib
@@ -37,8 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
38
  - !ruby/object:Gem::Version
38
39
  version: '0'
39
40
  requirements: []
40
- rubygems_version: 3.5.21
41
- signing_key:
41
+ rubygems_version: 3.6.2
42
42
  specification_version: 4
43
43
  summary: A gem for working with video.
44
44
  test_files: []