venus_video 0.1.1 → 0.2.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 +62 -13
  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: e3081b91e825af2e25590bf8f0986f91a4c0f8588089873dd9b4e0b039e8d366
4
+ data.tar.gz: 4c2e862ebaf55dd5cdd6e42d31967461c13748fc4eabbf8a802383555bf12eff
5
5
  SHA512:
6
- metadata.gz: ab4170473debd7a9ba36644ffa68487149db858e1d26840a1f5c4b939567027e1c22f1b99a4a15296485d8ba650a9fba672f23b8d9a5cd588337d245d4bc4d2a
7
- data.tar.gz: 9f1c45470d496275c48d20ff2f91cc8ff12329947cc2d37d00e3064e6a3177da2a3b194d6bf9cab5c01044d7a3b8c736477b8420646965727216b2c06e49c87c
6
+ metadata.gz: 94ffc262bb9c5ed8a9a0d8002b0d14dc667262bf904b93963ba1686bbe150bd833fbb9a44e101a1b4c5952b42d293222bbecf988e8ea7f2c8d0489a66dffa762
7
+ data.tar.gz: c0e39e8c3b60b0bf705d938951f5acbfce6dc9a553cec83775b65bb3ec3b2e1e491fe1e6c3b7133d3270a960d858492f33da18df8a5a35c0b33a12028207eac9
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,60 @@ 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
90
- 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
+ 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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - acm-wq