venus_video 0.1.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 +7 -0
- data/lib/venus.rb +90 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d68e7bda30458620073f7a6da9637b3f5dbcb42b1e59e099594e3d8ad817236
|
4
|
+
data.tar.gz: 3acb27ed154f7de740878d9e44888bece3d32904c5c6552c20f74e93565a964f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab4170473debd7a9ba36644ffa68487149db858e1d26840a1f5c4b939567027e1c22f1b99a4a15296485d8ba650a9fba672f23b8d9a5cd588337d245d4bc4d2a
|
7
|
+
data.tar.gz: 9f1c45470d496275c48d20ff2f91cc8ff12329947cc2d37d00e3064e6a3177da2a3b194d6bf9cab5c01044d7a3b8c736477b8420646965727216b2c06e49c87c
|
data/lib/venus.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'open3'
|
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
|
+
if format_segment == "min"
|
7
|
+
segment_duration = segment_duration.to_i * 60
|
8
|
+
elsif format_segment == "hour"
|
9
|
+
segment_duration = segment_duration.to_i * 3600
|
10
|
+
elsif format_segment == "sek"
|
11
|
+
segment_duration = segment_duration.to_i
|
12
|
+
else
|
13
|
+
puts "Invalid format. Use 'min', 'hour' or 'sek'."
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
output_path = path ? File.join(path, "#{output_prefix}_%03d.mp4") : "#{output_prefix}_%03d.mp4"
|
18
|
+
|
19
|
+
if format_video
|
20
|
+
case format_video
|
21
|
+
when "first"
|
22
|
+
output_path = path ? File.join(path, "#{output_prefix}_001.mp4") : "#{output_prefix}_001.mp4"
|
23
|
+
command = "ffmpeg -i #{input_file} -c copy -map 0 -t #{segment_duration} #{output_path}"
|
24
|
+
when "end"
|
25
|
+
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
|
+
while line = stderr.gets
|
28
|
+
puts line
|
29
|
+
end
|
30
|
+
|
31
|
+
exit_status = wait_thr.value
|
32
|
+
unless exit_status.success?
|
33
|
+
puts "Error executing command: #{command}"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
parts = Dir.glob("#{output_prefix}_*.mp4")
|
38
|
+
parts.sort!
|
39
|
+
File.delete(*parts[0...-1]) if parts.length > 1
|
40
|
+
return
|
41
|
+
else
|
42
|
+
range = eval(format_video)
|
43
|
+
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
|
+
while line = stderr.gets
|
46
|
+
puts line
|
47
|
+
end
|
48
|
+
|
49
|
+
exit_status = wait_thr.value
|
50
|
+
unless exit_status.success?
|
51
|
+
puts "Error executing command: #{command}"
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
parts = Dir.glob("#{output_prefix}_*.mp4")
|
56
|
+
parts.sort!
|
57
|
+
parts.each_with_index do |part, index|
|
58
|
+
unless range.include?(index + 1)
|
59
|
+
File.delete(part)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
return
|
63
|
+
end
|
64
|
+
else
|
65
|
+
command = "ffmpeg -i #{input_file} -c copy -map 0 -segment_time #{segment_duration} -f segment -reset_timestamps 1 #{output_path}"
|
66
|
+
end
|
67
|
+
|
68
|
+
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
|
69
|
+
while line = stderr.gets
|
70
|
+
puts line
|
71
|
+
end
|
72
|
+
|
73
|
+
exit_status = wait_thr.value
|
74
|
+
unless exit_status.success?
|
75
|
+
puts "Error executing command: #{command}"
|
76
|
+
exit 1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.process_arguments(args_string)
|
82
|
+
args = args_string.split
|
83
|
+
if args.length < 4 || args.length > 6
|
84
|
+
puts "Usage: ruby main.rb <input_file> <output_prefix> <format_segment> <segment_duration> [path] [format_video]"
|
85
|
+
exit 1
|
86
|
+
end
|
87
|
+
args
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: venus_video
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- acm-wq
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Venus is a Ruby gem that allows you to work with video using ffmpeg.
|
14
|
+
email:
|
15
|
+
- camisglhdadae@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/venus.rb
|
21
|
+
homepage: https://github.com/acm-wq/venus
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.5.21
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A gem for working with video.
|
44
|
+
test_files: []
|