media_trim 0.2.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/media_trim/version.rb +1 -1
- data/lib/trim_class.rb +20 -7
- data/lib/trim_help.rb +4 -4
- data/lib/trim_main.rb +21 -16
- data/media_trim.gemspec +1 -0
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 37f7ed510ad90d35e85ef47e33fabf9d1994779512a6c6b4342c570e3a957048
|
|
4
|
+
data.tar.gz: b0f0aed439b2fe793be04f38ea30937a767f53c997bb1723c38d9b2357b23e63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de4ee11b00dfc2067a94f1da192d76940ca09d1baacd8ce3ddb215444a0dd45c1a4aac93c46399432e5818aa76efba4bc2ccadaeb8f51bb317f707b40c8f456f
|
|
7
|
+
data.tar.gz: 1bdea1d74ba69994bfaf7452c1fe1fe6cd9b9c9ecb76530c45bfb640c5624ae55456ab3012cb39157778cb5fc4d0532003285285218b3a64702b0035926fbd71
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -69,7 +69,7 @@ When run as a command, output files are named by adding a `trim.` prefix to the
|
|
|
69
69
|
e.g. `dir/trim.file.ext`.
|
|
70
70
|
By default, the `trim` command does not overwrite pre-existing output files.
|
|
71
71
|
When trimming is complete, the `trim` command displays the trimmed file,
|
|
72
|
-
unless the `-
|
|
72
|
+
unless the `-V` option is specified.
|
|
73
73
|
|
|
74
74
|
`OPTIONS` are:
|
|
75
75
|
|
data/lib/media_trim/version.rb
CHANGED
data/lib/trim_class.rb
CHANGED
|
@@ -13,13 +13,26 @@ class MediaTrim
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.time_format(elapsed_seconds)
|
|
16
|
-
elapsed_time = elapsed_seconds.
|
|
16
|
+
elapsed_time = elapsed_seconds.to_f
|
|
17
17
|
hours = (elapsed_time / (60 * 60)).to_i
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
remaining_after_hours = elapsed_time - (hours * 60 * 60)
|
|
19
|
+
minutes = (remaining_after_hours / 60).to_i
|
|
20
|
+
seconds = remaining_after_hours - (minutes * 60)
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
# Format seconds with proper padding
|
|
23
|
+
if seconds == seconds.to_i
|
|
24
|
+
# No decimal part
|
|
25
|
+
seconds_str = seconds.to_i.to_s.rjust(2, '0')
|
|
26
|
+
else
|
|
27
|
+
# Has decimal part
|
|
28
|
+
whole_seconds = seconds.to_i
|
|
29
|
+
decimal_part = seconds - whole_seconds
|
|
30
|
+
decimal_str = format('%.2f', decimal_part)[1..] # Remove leading "0" from "0.XX"
|
|
31
|
+
seconds_str = "#{whole_seconds.to_s.rjust(2, '0')}#{decimal_str}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
result = "#{minutes.to_s.rjust(2, '0')}:#{seconds_str}"
|
|
35
|
+
result = "#{hours}:#{result}" unless hours.zero?
|
|
23
36
|
result
|
|
24
37
|
end
|
|
25
38
|
|
|
@@ -52,9 +65,9 @@ class MediaTrim
|
|
|
52
65
|
end
|
|
53
66
|
|
|
54
67
|
def self.to_seconds(str)
|
|
55
|
-
array = str.split(':').map(&:
|
|
68
|
+
array = str.split(':').map(&:to_f).reverse
|
|
56
69
|
case array.length
|
|
57
|
-
when 1 then str.
|
|
70
|
+
when 1 then str.to_f
|
|
58
71
|
when 2 then array[0] + (array[1] * 60)
|
|
59
72
|
when 3 then array[0] + (array[1] * 60) + (array[2] * 60 * 60)
|
|
60
73
|
else raise TrimError, "Error: #{str} is not a valid time"
|
data/lib/trim_help.rb
CHANGED
|
@@ -10,7 +10,7 @@ class MediaTrim
|
|
|
10
10
|
- Can be used as a Ruby gem.
|
|
11
11
|
- Installs the 'trim' command.
|
|
12
12
|
|
|
13
|
-
When run as a command, output files are named by adding a 'trim.' prefix to the media file name, e.g
|
|
13
|
+
When run as a command, output files are named by adding a 'trim.' prefix to the media file name, e.g., 'dir/trim.file.ext'.
|
|
14
14
|
By default, the trim command does not overwrite pre-existing output files.
|
|
15
15
|
When trimming is complete, the trim command displays the trimmed file, unless the -q option is specified
|
|
16
16
|
|
|
@@ -43,11 +43,11 @@ class MediaTrim
|
|
|
43
43
|
trim demo/demo.mp4 3:25 for 6:10
|
|
44
44
|
|
|
45
45
|
Need a way to figure out the start and stop times to trim a video?
|
|
46
|
-
DJV is an excellent video viewer https://darbyjohnston.github.io/DJV/
|
|
46
|
+
DJV is an excellent video viewer. https://darbyjohnston.github.io/DJV/
|
|
47
47
|
- allows frame-by-frame stepping
|
|
48
|
-
- displays the current time
|
|
48
|
+
- displays the current time reliably
|
|
49
49
|
- F/OSS
|
|
50
|
-
- Mac, Windows, Linux
|
|
50
|
+
- Mac, Windows, and Linux
|
|
51
51
|
- High quality
|
|
52
52
|
END_HELP
|
|
53
53
|
exit 1
|
data/lib/trim_main.rb
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
|
-
TrimError
|
|
1
|
+
class TrimError < StandardError
|
|
2
|
+
end # Define a new StandardError subclass
|
|
2
3
|
|
|
3
4
|
class MediaTrim
|
|
4
|
-
attr_accessor :copy_filename, :fname, :interval, :msg_end, :overwrite, :quiet, :start, :view
|
|
5
|
+
attr_accessor :copy_filename, :debug, :fname, :interval, :msg_end, :overwrite, :quiet, :start, :view
|
|
5
6
|
|
|
6
7
|
# @param to [String] end timecode; duration not supported for API
|
|
7
8
|
def initialize(filename = nil, trimmed_filename = nil, start = '0', to = nil, **options)
|
|
8
9
|
@fname = MediaTrim.expand_env(filename) if filename
|
|
9
10
|
@copy_filename = MediaTrim.expand_env(trimmed_filename) if trimmed_filename
|
|
10
|
-
@start = MediaTrim.time_format
|
|
11
|
-
@interval = ['-ss',
|
|
11
|
+
@start = MediaTrim.time_format(MediaTrim.to_seconds(start))
|
|
12
|
+
@interval = ['-ss', @start]
|
|
13
|
+
@debug = options[:debug] || false
|
|
12
14
|
|
|
13
15
|
@overwrite = options[:overwrite] ? '-y' : '-n'
|
|
14
16
|
@quiet = options[:quiet].nil? || options[:quiet] ? ['-hide_banner', '-loglevel', 'error', '-nostats'] : []
|
|
15
|
-
@view = options[:view].nil?
|
|
17
|
+
@view = options[:view].nil? || options[:view]
|
|
16
18
|
|
|
17
19
|
prepare(@start, to, mode: :timecode) if to
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def options
|
|
21
23
|
OptionParser.new do |opts|
|
|
22
|
-
opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
|
24
|
+
opts.banner = "Usage: #{$PROGRAM_NAME} [options] file start [[to|for] end]"
|
|
23
25
|
|
|
24
|
-
opts.on('-f', '--
|
|
25
|
-
@overwrite =
|
|
26
|
+
opts.on('-f', '--overwrite', 'Overwrite any previous output') do
|
|
27
|
+
@overwrite = '-y'
|
|
28
|
+
end
|
|
29
|
+
opts.on('-v', '--verbose', 'Run verbosely') do
|
|
30
|
+
@quiet = []
|
|
26
31
|
end
|
|
27
|
-
opts.on('-
|
|
28
|
-
|
|
32
|
+
opts.on('-h', '--help', 'Display help') do
|
|
33
|
+
MediaTrim.help
|
|
29
34
|
end
|
|
30
|
-
opts.on('-
|
|
31
|
-
|
|
35
|
+
opts.on('-V', '--no-view', 'Do not view the trimmed file when complete') do
|
|
36
|
+
@view = false
|
|
32
37
|
end
|
|
33
|
-
opts.on('-
|
|
34
|
-
@
|
|
38
|
+
opts.on('-d', '--debug', 'Enable debug output') do
|
|
39
|
+
@debug = true
|
|
35
40
|
end
|
|
36
41
|
end.parse!
|
|
37
42
|
end
|
|
@@ -49,7 +54,7 @@ class MediaTrim
|
|
|
49
54
|
@copy_filename = "#{File.dirname @fname}/trim.#{original_filename}#{ext}"
|
|
50
55
|
|
|
51
56
|
MediaTrim.help 'Please specify the time to @start trimming the video file from' unless argv[1]
|
|
52
|
-
@start = MediaTrim.time_format
|
|
57
|
+
@start = MediaTrim.time_format(MediaTrim.to_seconds(argv[1]))
|
|
53
58
|
|
|
54
59
|
@interval = ['-ss', @start]
|
|
55
60
|
@msg_end = ''
|
|
@@ -72,7 +77,7 @@ class MediaTrim
|
|
|
72
77
|
|
|
73
78
|
def prepare(from, duration_or_timecode, mode: :duration)
|
|
74
79
|
if mode == :duration
|
|
75
|
-
timecode = MediaTrim.time_format
|
|
80
|
+
timecode = MediaTrim.time_format(MediaTrim.to_seconds(duration_or_timecode))
|
|
76
81
|
time_end = MediaTrim.add_times from, timecode
|
|
77
82
|
@interval += ['-t', time_end]
|
|
78
83
|
@msg_end = " for a duration of #{timecode} (until #{time_end})"
|
data/media_trim.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: media_trim
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Slinn
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: colorator
|
|
@@ -97,7 +96,7 @@ metadata:
|
|
|
97
96
|
source_code_uri: https://github.com/mslinn/media_trim
|
|
98
97
|
post_install_message: |2+
|
|
99
98
|
|
|
100
|
-
Thanks for installing media_trim v0.2.
|
|
99
|
+
Thanks for installing media_trim v0.2.1!
|
|
101
100
|
|
|
102
101
|
rdoc_options: []
|
|
103
102
|
require_paths:
|
|
@@ -113,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
113
112
|
- !ruby/object:Gem::Version
|
|
114
113
|
version: '0'
|
|
115
114
|
requirements: []
|
|
116
|
-
rubygems_version:
|
|
117
|
-
signing_key:
|
|
115
|
+
rubygems_version: 4.0.16
|
|
118
116
|
specification_version: 4
|
|
119
117
|
summary: Trim an audio or video file using ffmpeg
|
|
120
118
|
test_files: []
|