moshy 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +22 -22
- data/DEVNOTES.md +7 -0
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +94 -87
- data/Rakefile +2 -2
- data/bin/moshy +106 -104
- data/lib/moshy/bake.rb +68 -68
- data/lib/moshy/inspect.rb +110 -110
- data/lib/moshy/isplit.rb +129 -129
- data/lib/moshy/pdupe.rb +85 -85
- data/lib/moshy/ppulse.rb +153 -153
- data/lib/moshy/prep.rb +78 -78
- data/lib/moshy/version.rb +3 -3
- data/lib/moshy.rb +13 -13
- data/moshy.gemspec +27 -27
- metadata +22 -22
data/lib/moshy/pdupe.rb
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
-
module Moshy
|
2
|
-
class PDupe
|
3
|
-
def cli(args)
|
4
|
-
opts = Slop::Options.new
|
5
|
-
opts.banner = "Usage: moshy -m pdupe -i file.avi -o file_out.avi -f <integer>\nmoshy -m pdupe --help for details"
|
6
|
-
opts.separator 'Required Parameters:'
|
7
|
-
opts.string '-i', '--input', 'Input file path - must be an .avi.'
|
8
|
-
opts.string '-o', '--output', 'Output file path, should be an .avi.'
|
9
|
-
opts.integer '-f', '--frame', 'Index of the frame that should be duplicated'
|
10
|
-
opts.separator 'Optional Parameters:'
|
11
|
-
opts.integer '-d', '--dupes', 'Number of times to multiply the frame (default: 30)'
|
12
|
-
opts.on '-h', '--help' do
|
13
|
-
puts opts
|
14
|
-
puts "\n"
|
15
|
-
puts \
|
16
|
-
"Duplicates a P-frame at a given frame a certain amount. To find
|
17
|
-
out which frames are P-frames, use software like avidemux to look at the
|
18
|
-
frame type. WARNING: This mode is a little glitchy. You may need to set
|
19
|
-
the interval 1 or 2 above or below the frame number you actually want to
|
20
|
-
duplicate. I'm not sure why this happens, but try it with a small
|
21
|
-
duplication amount first. NOTE: This can mode take a while to process
|
22
|
-
over 60-90 frame dupes.
|
23
|
-
|
24
|
-
You can specify the number of duplicates that you want with the -d parameter."
|
25
|
-
exit
|
26
|
-
end
|
27
|
-
|
28
|
-
default = {
|
29
|
-
:dupes => 30
|
30
|
-
}
|
31
|
-
|
32
|
-
parser = Slop::Parser.new(opts)
|
33
|
-
slop_options = parser.parse(ARGV)
|
34
|
-
@options = default.merge(slop_options) { |key, oldval, newval|
|
35
|
-
if newval.nil?
|
36
|
-
oldval
|
37
|
-
else
|
38
|
-
newval
|
39
|
-
end
|
40
|
-
}
|
41
|
-
|
42
|
-
# Check mandatory params
|
43
|
-
mandatory = [:input, :output, :frame]
|
44
|
-
missing = mandatory.select{ |param| @options[param].nil? }
|
45
|
-
unless missing.empty?
|
46
|
-
puts "Missing options: #{missing.join(', ')}"
|
47
|
-
puts slop_options
|
48
|
-
exit
|
49
|
-
end
|
50
|
-
|
51
|
-
puts "Opening file " + @options[:input] + "..."
|
52
|
-
a = AviGlitch.open @options[:input] # Rewrite this line for your file.
|
53
|
-
puts "Opened!"
|
54
|
-
|
55
|
-
pdupe(a, @options[:output], @options[:frame], @options[:dupes])
|
56
|
-
end
|
57
|
-
|
58
|
-
def pdupe(clip, output, frame, duplicate_amount)
|
59
|
-
|
60
|
-
puts "Size: " + clip.frames.size_of('videoframe').to_s
|
61
|
-
|
62
|
-
frames = nil
|
63
|
-
video_frame_counter = 0
|
64
|
-
|
65
|
-
clip.frames.each_with_index do |f, i|
|
66
|
-
if f.is_videoframe?
|
67
|
-
video_frame_counter += 1
|
68
|
-
if video_frame_counter == frame
|
69
|
-
puts "On frame " + frame.to_s + ", duping " + duplicate_amount.to_s + " times"
|
70
|
-
clipped = clip.frames[0..(i + 5)]
|
71
|
-
dupe_clip = clip.frames[(i + 4), 1] * duplicate_amount
|
72
|
-
frames = clipped + dupe_clip
|
73
|
-
puts "Added dupe, grabbing rest..."
|
74
|
-
frames = frames + clip.frames[i..-1]
|
75
|
-
puts "Done. Output frame count: " + frames.size.to_s
|
76
|
-
break
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
o = AviGlitch.open frames
|
82
|
-
o.output output
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
1
|
+
module Moshy
|
2
|
+
class PDupe
|
3
|
+
def cli(args)
|
4
|
+
opts = Slop::Options.new
|
5
|
+
opts.banner = "Usage: moshy -m pdupe -i file.avi -o file_out.avi -f <integer>\nmoshy -m pdupe --help for details"
|
6
|
+
opts.separator 'Required Parameters:'
|
7
|
+
opts.string '-i', '--input', 'Input file path - must be an .avi.'
|
8
|
+
opts.string '-o', '--output', 'Output file path, should be an .avi.'
|
9
|
+
opts.integer '-f', '--frame', 'Index of the frame that should be duplicated'
|
10
|
+
opts.separator 'Optional Parameters:'
|
11
|
+
opts.integer '-d', '--dupes', 'Number of times to multiply the frame (default: 30)'
|
12
|
+
opts.on '-h', '--help' do
|
13
|
+
puts opts
|
14
|
+
puts "\n"
|
15
|
+
puts \
|
16
|
+
"Duplicates a P-frame at a given frame a certain amount. To find
|
17
|
+
out which frames are P-frames, use software like avidemux to look at the
|
18
|
+
frame type. WARNING: This mode is a little glitchy. You may need to set
|
19
|
+
the interval 1 or 2 above or below the frame number you actually want to
|
20
|
+
duplicate. I'm not sure why this happens, but try it with a small
|
21
|
+
duplication amount first. NOTE: This can mode take a while to process
|
22
|
+
over 60-90 frame dupes.
|
23
|
+
|
24
|
+
You can specify the number of duplicates that you want with the -d parameter."
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
default = {
|
29
|
+
:dupes => 30
|
30
|
+
}
|
31
|
+
|
32
|
+
parser = Slop::Parser.new(opts)
|
33
|
+
slop_options = parser.parse(ARGV)
|
34
|
+
@options = default.merge(slop_options) { |key, oldval, newval|
|
35
|
+
if newval.nil?
|
36
|
+
oldval
|
37
|
+
else
|
38
|
+
newval
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
# Check mandatory params
|
43
|
+
mandatory = [:input, :output, :frame]
|
44
|
+
missing = mandatory.select{ |param| @options[param].nil? }
|
45
|
+
unless missing.empty?
|
46
|
+
puts "Missing options: #{missing.join(', ')}"
|
47
|
+
puts slop_options
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "Opening file " + @options[:input] + "..."
|
52
|
+
a = AviGlitch.open @options[:input] # Rewrite this line for your file.
|
53
|
+
puts "Opened!"
|
54
|
+
|
55
|
+
pdupe(a, @options[:output], @options[:frame], @options[:dupes])
|
56
|
+
end
|
57
|
+
|
58
|
+
def pdupe(clip, output, frame, duplicate_amount)
|
59
|
+
|
60
|
+
puts "Size: " + clip.frames.size_of('videoframe').to_s
|
61
|
+
|
62
|
+
frames = nil
|
63
|
+
video_frame_counter = 0
|
64
|
+
|
65
|
+
clip.frames.each_with_index do |f, i|
|
66
|
+
if f.is_videoframe?
|
67
|
+
video_frame_counter += 1
|
68
|
+
if video_frame_counter == frame
|
69
|
+
puts "On frame " + frame.to_s + ", duping " + duplicate_amount.to_s + " times"
|
70
|
+
clipped = clip.frames[0..(i + 5)]
|
71
|
+
dupe_clip = clip.frames[(i + 4), 1] * duplicate_amount
|
72
|
+
frames = clipped + dupe_clip
|
73
|
+
puts "Added dupe, grabbing rest..."
|
74
|
+
frames = frames + clip.frames[i..-1]
|
75
|
+
puts "Done. Output frame count: " + frames.size.to_s
|
76
|
+
break
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
o = AviGlitch.open frames
|
82
|
+
o.output output
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/moshy/ppulse.rb
CHANGED
@@ -1,153 +1,153 @@
|
|
1
|
-
module Moshy
|
2
|
-
class PPulse
|
3
|
-
def cli(args)
|
4
|
-
opts = Slop::Options.new
|
5
|
-
opts.banner = "Usage: moshy -m ppulse -i file.avi -o file_out.avi [options]\nmoshy -m inspect --help for details"
|
6
|
-
opts.separator 'Required Parameters:'
|
7
|
-
opts.string '-i', '--input', 'Input file path - must be an .avi. Clip to split in split mode, first clip in stitch mode'
|
8
|
-
opts.string '-o', '--output', 'Output file path - will be appended with -#.avi for each frame in split mode'
|
9
|
-
opts.separator 'Optional Parameters:'
|
10
|
-
opts.string '-k', '--keep', 'Whether or not to keep standard frames. (default: true)', default: "true"
|
11
|
-
opts.integer '-c', '--count', 'How many frames to grab forward from each interval. (default: 1)', default: 1
|
12
|
-
opts.integer '-d', '--dupes', 'Number of times to multiply the frame (default: 30)', default: 30
|
13
|
-
opts.integer '-n', '--interval', 'Which nth frames should be duplicated (default: 30)', default: 30
|
14
|
-
opts.on '-h', '--help' do
|
15
|
-
puts opts
|
16
|
-
puts "\n"
|
17
|
-
puts \
|
18
|
-
"Takes c number of frames and every n frames and duplicates them a
|
19
|
-
given amount, resulting in a consistent P-duplication datamosh that's
|
20
|
-
good for creating rhythmic effects. This was originally created to
|
21
|
-
create mosh effects in sync with a beat for a music video.
|
22
|
-
|
23
|
-
You can specify what interval to get frames at with -n (--interval).
|
24
|
-
You can specify how many frames to get from the current interval with
|
25
|
-
-c (--count). You can specify how many times to duplicate a given
|
26
|
-
frame with -d (--dupes). You can then specify whether or not to keep
|
27
|
-
the original video's frames between the end of the duplication and
|
28
|
-
where the next interval occurs with -k (--keep). Keeping original
|
29
|
-
frames causes the original motion to continue after the P-frame dupe
|
30
|
-
effect, whereas dropping original frames causes the video to snap
|
31
|
-
into the motion of the frames at each interval. This is a more complex
|
32
|
-
effect so I recommend experimenting with it!"
|
33
|
-
exit
|
34
|
-
end
|
35
|
-
|
36
|
-
default = {
|
37
|
-
:dupes => 30,
|
38
|
-
:interval => 30,
|
39
|
-
:count => 1,
|
40
|
-
:keep => true
|
41
|
-
}
|
42
|
-
|
43
|
-
parser = Slop::Parser.new(opts)
|
44
|
-
slop_options = parser.parse(ARGV)
|
45
|
-
@options = default.merge(slop_options) { |key, oldval, newval|
|
46
|
-
if newval.nil?
|
47
|
-
oldval
|
48
|
-
else
|
49
|
-
newval
|
50
|
-
end
|
51
|
-
}
|
52
|
-
|
53
|
-
if @options[:keep] == "false"
|
54
|
-
@options[:keep] = false
|
55
|
-
else
|
56
|
-
@options[:keep] = true
|
57
|
-
end
|
58
|
-
|
59
|
-
# Check mandatory params
|
60
|
-
mandatory = [:input, :output]
|
61
|
-
missing = mandatory.select{ |param| @options[param].nil? }
|
62
|
-
unless missing.empty?
|
63
|
-
puts "Missing options: #{missing.join(', ')}"
|
64
|
-
puts slop_options
|
65
|
-
exit
|
66
|
-
end
|
67
|
-
|
68
|
-
puts "Opening file " + @options[:input] + "..."
|
69
|
-
a = AviGlitch.open @options[:input] # Rewrite this line for your file.
|
70
|
-
puts "Opened!"
|
71
|
-
|
72
|
-
ppulse(a, @options[:output], @options[:interval], @options[:count], @options[:dupes], @options[:keep])
|
73
|
-
end
|
74
|
-
|
75
|
-
# Loops through a video file and grabs every `interval` frames then duplicates them
|
76
|
-
# `duplicate_amount` times
|
77
|
-
#
|
78
|
-
# `leave_originals` will copy standard frames and only p-frame the last one every `interval`
|
79
|
-
def ppulse(clip, output, interval = 30, count = 1, duplicate_amount = 30, leave_originals = true)
|
80
|
-
|
81
|
-
puts "Size: " + clip.frames.size_of('videoframe').to_s
|
82
|
-
|
83
|
-
frames = nil
|
84
|
-
|
85
|
-
video_frame_counter = 0
|
86
|
-
|
87
|
-
have_iframe = false
|
88
|
-
|
89
|
-
if leave_originals
|
90
|
-
first_index = 0
|
91
|
-
second_index = 0
|
92
|
-
clip.frames.each_with_index do |f, i|
|
93
|
-
if f.is_videoframe?
|
94
|
-
video_frame_counter += 1
|
95
|
-
if video_frame_counter % interval == 0
|
96
|
-
second_index = i
|
97
|
-
puts "first index: " + first_index.to_s
|
98
|
-
puts "second index: " + second_index.to_s
|
99
|
-
|
100
|
-
clipped = clip.frames[first_index..(i + 5)]
|
101
|
-
dupe_clip = clip.frames[i, count] * duplicate_amount
|
102
|
-
if frames.nil?
|
103
|
-
frames = clipped + dupe_clip
|
104
|
-
else
|
105
|
-
frames = frames + clipped + dupe_clip
|
106
|
-
end
|
107
|
-
puts "Current expected output frame count: " + frames.size.to_s
|
108
|
-
|
109
|
-
first_index = i + 5
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
else
|
114
|
-
# Harvest clip details
|
115
|
-
clip.frames.each_with_index do |f, i|
|
116
|
-
if f.is_videoframe?
|
117
|
-
if !have_iframe && f.is_keyframe?
|
118
|
-
puts "Added first iframe (necessary to avoid total corruption)"
|
119
|
-
# no idea why i need to get 5
|
120
|
-
frames = clip.frames[i, 1]
|
121
|
-
have_iframe = true
|
122
|
-
end
|
123
|
-
|
124
|
-
# +1 to offset the first iframe
|
125
|
-
if video_frame_counter % interval == 0 && f.is_deltaframe?
|
126
|
-
puts "Processing frame " + video_frame_counter.to_s + " at index " + i.to_s
|
127
|
-
# You might ask why we need to check if frames are nil when we already check
|
128
|
-
# whether or not we have an i frame and if the above is a keyframe - that's
|
129
|
-
# because datamoshers are crazy and might pass use clip with no leading iframe :)
|
130
|
-
if frames.nil?
|
131
|
-
puts "First frame, setting"
|
132
|
-
clipped = clip.frames[i, count]
|
133
|
-
frames = frames.concat( clipped * duplicate_amount )
|
134
|
-
puts "Frame size"
|
135
|
-
puts frames.size_of('videoframe')
|
136
|
-
else
|
137
|
-
puts "Current i: " + i.to_s
|
138
|
-
puts "Duping frame " + i.to_s + " " + duplicate_amount.to_s + " times"
|
139
|
-
frames = frames.concat( clip.frames[i, count] * duplicate_amount )
|
140
|
-
puts "Next frame, size: " + frames.size.to_s
|
141
|
-
end
|
142
|
-
end
|
143
|
-
video_frame_counter += 1
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
o = AviGlitch.open frames
|
149
|
-
o.output output
|
150
|
-
puts "Done! File processed to: " + output
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
1
|
+
module Moshy
|
2
|
+
class PPulse
|
3
|
+
def cli(args)
|
4
|
+
opts = Slop::Options.new
|
5
|
+
opts.banner = "Usage: moshy -m ppulse -i file.avi -o file_out.avi [options]\nmoshy -m inspect --help for details"
|
6
|
+
opts.separator 'Required Parameters:'
|
7
|
+
opts.string '-i', '--input', 'Input file path - must be an .avi. Clip to split in split mode, first clip in stitch mode'
|
8
|
+
opts.string '-o', '--output', 'Output file path - will be appended with -#.avi for each frame in split mode'
|
9
|
+
opts.separator 'Optional Parameters:'
|
10
|
+
opts.string '-k', '--keep', 'Whether or not to keep standard frames. (default: true)', default: "true"
|
11
|
+
opts.integer '-c', '--count', 'How many frames to grab forward from each interval. (default: 1)', default: 1
|
12
|
+
opts.integer '-d', '--dupes', 'Number of times to multiply the frame (default: 30)', default: 30
|
13
|
+
opts.integer '-n', '--interval', 'Which nth frames should be duplicated (default: 30)', default: 30
|
14
|
+
opts.on '-h', '--help' do
|
15
|
+
puts opts
|
16
|
+
puts "\n"
|
17
|
+
puts \
|
18
|
+
"Takes c number of frames and every n frames and duplicates them a
|
19
|
+
given amount, resulting in a consistent P-duplication datamosh that's
|
20
|
+
good for creating rhythmic effects. This was originally created to
|
21
|
+
create mosh effects in sync with a beat for a music video.
|
22
|
+
|
23
|
+
You can specify what interval to get frames at with -n (--interval).
|
24
|
+
You can specify how many frames to get from the current interval with
|
25
|
+
-c (--count). You can specify how many times to duplicate a given
|
26
|
+
frame with -d (--dupes). You can then specify whether or not to keep
|
27
|
+
the original video's frames between the end of the duplication and
|
28
|
+
where the next interval occurs with -k (--keep). Keeping original
|
29
|
+
frames causes the original motion to continue after the P-frame dupe
|
30
|
+
effect, whereas dropping original frames causes the video to snap
|
31
|
+
into the motion of the frames at each interval. This is a more complex
|
32
|
+
effect so I recommend experimenting with it!"
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
default = {
|
37
|
+
:dupes => 30,
|
38
|
+
:interval => 30,
|
39
|
+
:count => 1,
|
40
|
+
:keep => true
|
41
|
+
}
|
42
|
+
|
43
|
+
parser = Slop::Parser.new(opts)
|
44
|
+
slop_options = parser.parse(ARGV)
|
45
|
+
@options = default.merge(slop_options) { |key, oldval, newval|
|
46
|
+
if newval.nil?
|
47
|
+
oldval
|
48
|
+
else
|
49
|
+
newval
|
50
|
+
end
|
51
|
+
}
|
52
|
+
|
53
|
+
if @options[:keep] == "false"
|
54
|
+
@options[:keep] = false
|
55
|
+
else
|
56
|
+
@options[:keep] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
# Check mandatory params
|
60
|
+
mandatory = [:input, :output]
|
61
|
+
missing = mandatory.select{ |param| @options[param].nil? }
|
62
|
+
unless missing.empty?
|
63
|
+
puts "Missing options: #{missing.join(', ')}"
|
64
|
+
puts slop_options
|
65
|
+
exit
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "Opening file " + @options[:input] + "..."
|
69
|
+
a = AviGlitch.open @options[:input] # Rewrite this line for your file.
|
70
|
+
puts "Opened!"
|
71
|
+
|
72
|
+
ppulse(a, @options[:output], @options[:interval], @options[:count], @options[:dupes], @options[:keep])
|
73
|
+
end
|
74
|
+
|
75
|
+
# Loops through a video file and grabs every `interval` frames then duplicates them
|
76
|
+
# `duplicate_amount` times
|
77
|
+
#
|
78
|
+
# `leave_originals` will copy standard frames and only p-frame the last one every `interval`
|
79
|
+
def ppulse(clip, output, interval = 30, count = 1, duplicate_amount = 30, leave_originals = true)
|
80
|
+
|
81
|
+
puts "Size: " + clip.frames.size_of('videoframe').to_s
|
82
|
+
|
83
|
+
frames = nil
|
84
|
+
|
85
|
+
video_frame_counter = 0
|
86
|
+
|
87
|
+
have_iframe = false
|
88
|
+
|
89
|
+
if leave_originals
|
90
|
+
first_index = 0
|
91
|
+
second_index = 0
|
92
|
+
clip.frames.each_with_index do |f, i|
|
93
|
+
if f.is_videoframe?
|
94
|
+
video_frame_counter += 1
|
95
|
+
if video_frame_counter % interval == 0
|
96
|
+
second_index = i
|
97
|
+
puts "first index: " + first_index.to_s
|
98
|
+
puts "second index: " + second_index.to_s
|
99
|
+
|
100
|
+
clipped = clip.frames[first_index..(i + 5)]
|
101
|
+
dupe_clip = clip.frames[i, count] * duplicate_amount
|
102
|
+
if frames.nil?
|
103
|
+
frames = clipped + dupe_clip
|
104
|
+
else
|
105
|
+
frames = frames + clipped + dupe_clip
|
106
|
+
end
|
107
|
+
puts "Current expected output frame count: " + frames.size.to_s
|
108
|
+
|
109
|
+
first_index = i + 5
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
else
|
114
|
+
# Harvest clip details
|
115
|
+
clip.frames.each_with_index do |f, i|
|
116
|
+
if f.is_videoframe?
|
117
|
+
if !have_iframe && f.is_keyframe?
|
118
|
+
puts "Added first iframe (necessary to avoid total corruption)"
|
119
|
+
# no idea why i need to get 5
|
120
|
+
frames = clip.frames[i, 1]
|
121
|
+
have_iframe = true
|
122
|
+
end
|
123
|
+
|
124
|
+
# +1 to offset the first iframe
|
125
|
+
if video_frame_counter % interval == 0 && f.is_deltaframe?
|
126
|
+
puts "Processing frame " + video_frame_counter.to_s + " at index " + i.to_s
|
127
|
+
# You might ask why we need to check if frames are nil when we already check
|
128
|
+
# whether or not we have an i frame and if the above is a keyframe - that's
|
129
|
+
# because datamoshers are crazy and might pass use clip with no leading iframe :)
|
130
|
+
if frames.nil?
|
131
|
+
puts "First frame, setting"
|
132
|
+
clipped = clip.frames[i, count]
|
133
|
+
frames = frames.concat( clipped * duplicate_amount )
|
134
|
+
puts "Frame size"
|
135
|
+
puts frames.size_of('videoframe')
|
136
|
+
else
|
137
|
+
puts "Current i: " + i.to_s
|
138
|
+
puts "Duping frame " + i.to_s + " " + duplicate_amount.to_s + " times"
|
139
|
+
frames = frames.concat( clip.frames[i, count] * duplicate_amount )
|
140
|
+
puts "Next frame, size: " + frames.size.to_s
|
141
|
+
end
|
142
|
+
end
|
143
|
+
video_frame_counter += 1
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
o = AviGlitch.open frames
|
149
|
+
o.output output
|
150
|
+
puts "Done! File processed to: " + output
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/lib/moshy/prep.rb
CHANGED
@@ -1,78 +1,78 @@
|
|
1
|
-
module Moshy
|
2
|
-
class Prep
|
3
|
-
def cli(args)
|
4
|
-
opts = Slop::Options.new
|
5
|
-
opts.banner = "Usage: moshy.rb -m prep -i <file> -o <output> [options]\n"
|
6
|
-
opts.separator 'Required Parameters:'
|
7
|
-
opts.string '-i', '--input', 'Input file path - can be anything that ffmpeg supports.'
|
8
|
-
opts.string '-o', '--output', 'File output path - should end in .avi.'
|
9
|
-
opts.separator 'Optional Parameters:'
|
10
|
-
opts.integer '-b', '--bitrate', 'Bitrate amount (kb/s). Defaults to 4196. Larger number means higher quality, but larger size.'
|
11
|
-
opts.on '-h', '--help' do
|
12
|
-
puts opts
|
13
|
-
puts "\n"
|
14
|
-
puts \
|
15
|
-
"Preps a video file for datamoshing with moshy by converting it into an
|
16
|
-
AVI with no B-Frames (they're not good for moshing), and placing as
|
17
|
-
few I-Frames as possible. Requires ffmpeg be installed locally. Check
|
18
|
-
the repository's README.md for more information on how to install ffmpeg.
|
19
|
-
|
20
|
-
This command is meant to be a simple one-liner that makes your datamoshing
|
21
|
-
workflow faster. Under the covers, it runs the following ffmpeg command:
|
22
|
-
|
23
|
-
ffmpeg -i <moshy input> -bf 0 -g 600 -b:v <moshy bitrate> -o <moshy output>
|
24
|
-
|
25
|
-
This takes in an input file (it should theoretically work with any video
|
26
|
-
file type that ffmpeg supports), makes sure that no B-Frames are rendered,
|
27
|
-
and sets the ideal I-frame interval to 600 (ffmpeg's max). This seems to
|
28
|
-
mean that an I-frame will only show up every 30 to 25 seconds
|
29
|
-
(600f / 30fps = 20s or 600f / 24fps = 25s), but I-Frames must be deposited
|
30
|
-
wherever there is a hard cut or transition in a video where a P-frame would
|
31
|
-
not be able to properly predict the motion of pixels."
|
32
|
-
exit
|
33
|
-
end
|
34
|
-
|
35
|
-
default = {
|
36
|
-
:bitrate => 4196
|
37
|
-
}
|
38
|
-
|
39
|
-
parser = Slop::Parser.new(opts)
|
40
|
-
slop_options = parser.parse(ARGV)
|
41
|
-
@options = default.merge(slop_options) { |key, oldval, newval|
|
42
|
-
if newval.nil?
|
43
|
-
oldval
|
44
|
-
else
|
45
|
-
newval
|
46
|
-
end
|
47
|
-
}
|
48
|
-
|
49
|
-
# Check mandatory params
|
50
|
-
mandatory = [:input, :output]
|
51
|
-
missing = mandatory.select{ |param| @options[param].nil? }
|
52
|
-
unless missing.empty?
|
53
|
-
puts "Missing options: #{missing.join(', ')}"
|
54
|
-
puts slop_options
|
55
|
-
exit
|
56
|
-
end
|
57
|
-
|
58
|
-
prep @options[:input], @options[:output], @options[:bitrate]
|
59
|
-
end
|
60
|
-
|
61
|
-
def prep(input, output, bitrate)
|
62
|
-
ffmpeg = Av::Commands::Ffmpeg.new
|
63
|
-
ffmpeg.add_source input
|
64
|
-
ffmpeg.add_destination output
|
65
|
-
|
66
|
-
# Ensures all frames come out as P-frames, B-frames don't
|
67
|
-
# dupe or mosh properly
|
68
|
-
ffmpeg.add_output_param ['bf', 0]
|
69
|
-
# Keyframe interval, sets as few I-frames as possible.
|
70
|
-
# ffmpeg will complain about anything over 600 and cap it.
|
71
|
-
ffmpeg.add_output_param ['g', 600]
|
72
|
-
# Bitrate
|
73
|
-
ffmpeg.add_output_param ['b:v', bitrate.to_s + 'k']
|
74
|
-
|
75
|
-
ffmpeg.run
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
module Moshy
|
2
|
+
class Prep
|
3
|
+
def cli(args)
|
4
|
+
opts = Slop::Options.new
|
5
|
+
opts.banner = "Usage: moshy.rb -m prep -i <file> -o <output> [options]\n"
|
6
|
+
opts.separator 'Required Parameters:'
|
7
|
+
opts.string '-i', '--input', 'Input file path - can be anything that ffmpeg supports.'
|
8
|
+
opts.string '-o', '--output', 'File output path - should end in .avi.'
|
9
|
+
opts.separator 'Optional Parameters:'
|
10
|
+
opts.integer '-b', '--bitrate', 'Bitrate amount (kb/s). Defaults to 4196. Larger number means higher quality, but larger size.'
|
11
|
+
opts.on '-h', '--help' do
|
12
|
+
puts opts
|
13
|
+
puts "\n"
|
14
|
+
puts \
|
15
|
+
"Preps a video file for datamoshing with moshy by converting it into an
|
16
|
+
AVI with no B-Frames (they're not good for moshing), and placing as
|
17
|
+
few I-Frames as possible. Requires ffmpeg be installed locally. Check
|
18
|
+
the repository's README.md for more information on how to install ffmpeg.
|
19
|
+
|
20
|
+
This command is meant to be a simple one-liner that makes your datamoshing
|
21
|
+
workflow faster. Under the covers, it runs the following ffmpeg command:
|
22
|
+
|
23
|
+
ffmpeg -i <moshy input> -bf 0 -g 600 -b:v <moshy bitrate> -o <moshy output>
|
24
|
+
|
25
|
+
This takes in an input file (it should theoretically work with any video
|
26
|
+
file type that ffmpeg supports), makes sure that no B-Frames are rendered,
|
27
|
+
and sets the ideal I-frame interval to 600 (ffmpeg's max). This seems to
|
28
|
+
mean that an I-frame will only show up every 30 to 25 seconds
|
29
|
+
(600f / 30fps = 20s or 600f / 24fps = 25s), but I-Frames must be deposited
|
30
|
+
wherever there is a hard cut or transition in a video where a P-frame would
|
31
|
+
not be able to properly predict the motion of pixels."
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
default = {
|
36
|
+
:bitrate => 4196
|
37
|
+
}
|
38
|
+
|
39
|
+
parser = Slop::Parser.new(opts)
|
40
|
+
slop_options = parser.parse(ARGV)
|
41
|
+
@options = default.merge(slop_options) { |key, oldval, newval|
|
42
|
+
if newval.nil?
|
43
|
+
oldval
|
44
|
+
else
|
45
|
+
newval
|
46
|
+
end
|
47
|
+
}
|
48
|
+
|
49
|
+
# Check mandatory params
|
50
|
+
mandatory = [:input, :output]
|
51
|
+
missing = mandatory.select{ |param| @options[param].nil? }
|
52
|
+
unless missing.empty?
|
53
|
+
puts "Missing options: #{missing.join(', ')}"
|
54
|
+
puts slop_options
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
prep @options[:input], @options[:output], @options[:bitrate]
|
59
|
+
end
|
60
|
+
|
61
|
+
def prep(input, output, bitrate)
|
62
|
+
ffmpeg = Av::Commands::Ffmpeg.new
|
63
|
+
ffmpeg.add_source input
|
64
|
+
ffmpeg.add_destination output
|
65
|
+
|
66
|
+
# Ensures all frames come out as P-frames, B-frames don't
|
67
|
+
# dupe or mosh properly
|
68
|
+
ffmpeg.add_output_param ['bf', 0]
|
69
|
+
# Keyframe interval, sets as few I-frames as possible.
|
70
|
+
# ffmpeg will complain about anything over 600 and cap it.
|
71
|
+
ffmpeg.add_output_param ['g', 600]
|
72
|
+
# Bitrate
|
73
|
+
ffmpeg.add_output_param ['b:v', bitrate.to_s + 'k']
|
74
|
+
|
75
|
+
ffmpeg.run
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/moshy/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Moshy
|
2
|
-
VERSION = "
|
3
|
-
end
|
1
|
+
module Moshy
|
2
|
+
VERSION = "2.0.0"
|
3
|
+
end
|
data/lib/moshy.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require "aviglitch"
|
2
|
-
require "av"
|
3
|
-
require_relative "moshy/version"
|
4
|
-
require_relative "moshy/inspect"
|
5
|
-
require_relative "moshy/isplit"
|
6
|
-
require_relative "moshy/pdupe"
|
7
|
-
require_relative "moshy/bake"
|
8
|
-
require_relative "moshy/prep"
|
9
|
-
require_relative "moshy/ppulse"
|
10
|
-
|
11
|
-
module Moshy
|
12
|
-
# Empty skeleton - just used to include the others
|
13
|
-
end
|
1
|
+
require "aviglitch"
|
2
|
+
require "av"
|
3
|
+
require_relative "moshy/version"
|
4
|
+
require_relative "moshy/inspect"
|
5
|
+
require_relative "moshy/isplit"
|
6
|
+
require_relative "moshy/pdupe"
|
7
|
+
require_relative "moshy/bake"
|
8
|
+
require_relative "moshy/prep"
|
9
|
+
require_relative "moshy/ppulse"
|
10
|
+
|
11
|
+
module Moshy
|
12
|
+
# Empty skeleton - just used to include the others
|
13
|
+
end
|