video_conv 0.1.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.
- checksums.yaml +7 -0
- data/lib/video_converter/version.rb +4 -0
- data/lib/video_converter.rb +64 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d48bb5273eda951a217f989a3731a37954b324b4f2396f3e89f056bae8c5bec7
|
4
|
+
data.tar.gz: 1739afe37ca0884ba36f788bbf9cbfac4899ed2ff576b7e6b2e6ce47f3f3a905
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36d68e3dca364c7d89094f51c2813debbac937745650e41305c842401c939e6a360ae1d7414d5a10379c33ec60b786ae4bc19ad94bf2359bc0d3c30571ca2ce0
|
7
|
+
data.tar.gz: e87a87ed948deb9016edff22d99c92c630b539b329dbb1fccf670b1c6a5d438419407785c227ab8ff1a9ce929042f8346951cc9184fb4b1dfec82c48e89853c7
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'streamio-ffmpeg'
|
3
|
+
require 'thread'
|
4
|
+
|
5
|
+
module VideoConverter
|
6
|
+
class Converter
|
7
|
+
attr_accessor :max_concurrency, :batch_size, :conversion_delay
|
8
|
+
|
9
|
+
def initialize(max_concurrency: 2, batch_size: 20, conversion_delay: 0.5)
|
10
|
+
@max_concurrency = max_concurrency
|
11
|
+
@batch_size = batch_size
|
12
|
+
@conversion_delay = conversion_delay
|
13
|
+
end
|
14
|
+
|
15
|
+
def convert_file(source_file, target_file)
|
16
|
+
movie = FFMPEG::Movie.new(source_file)
|
17
|
+
movie.transcode(target_file)
|
18
|
+
end
|
19
|
+
|
20
|
+
def rename_and_convert_files(dir, source_ext, target_ext)
|
21
|
+
source_files = []
|
22
|
+
Dir.foreach(dir) do |file|
|
23
|
+
next if file == '.' || file == '..'
|
24
|
+
|
25
|
+
current_path = File.join(dir, file)
|
26
|
+
if File.directory?(current_path)
|
27
|
+
rename_and_convert_files(current_path, source_ext, target_ext) # Recursively call for subdirectories
|
28
|
+
else
|
29
|
+
if file.end_with?(source_ext)
|
30
|
+
source_files << current_path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
source_files.each_slice(batch_size) do |file_batch|
|
36
|
+
convert_files_in_batch(file_batch, source_ext, target_ext)
|
37
|
+
sleep(conversion_delay)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def convert_files_in_batch(files, source_ext, target_ext)
|
42
|
+
threads = []
|
43
|
+
queue = Queue.new
|
44
|
+
|
45
|
+
files.each { |file| queue << file }
|
46
|
+
|
47
|
+
[max_concurrency, files.size].min.times do
|
48
|
+
threads << Thread.new do
|
49
|
+
while (file = queue.pop(true) rescue nil)
|
50
|
+
new_filename = file.gsub(source_ext, target_ext)
|
51
|
+
if !File.exist?(new_filename)
|
52
|
+
convert_file(file, new_filename)
|
53
|
+
puts "Converted: #{file} -> #{new_filename}"
|
54
|
+
else
|
55
|
+
puts "Skipped conversion (already exists): #{file}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
threads.each(&:join)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: video_conv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Webster
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: streamio-ffmpeg
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Convert video formats with custom concurrency, batch size, and conversion
|
28
|
+
delay
|
29
|
+
email:
|
30
|
+
- webster@asu.edu
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/video_converter.rb
|
36
|
+
- lib/video_converter/version.rb
|
37
|
+
homepage: https://github.com/avosa/video_converter
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.4.13
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: A Ruby gem for video format conversion with customizable options
|
60
|
+
test_files: []
|