easyvideo_utils 0.2.1 → 0.3.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/easyvideo_utils.rb +72 -5
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a91b8ba51bbff313106e09945d19827ebaa2c462d97b3bf0102eaa07b2112e60
|
4
|
+
data.tar.gz: ae94c800fd3b1dfc8f60533845479d7b1b51d7828909172638159adf189b8d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d68326073bf0963ce7d3d5412315697ca154a9d1c3fd9194eb076ec057f8f0260468f6b7685b796b3d39ba05d09408d8738e1142b397e682d67fd8886485ba
|
7
|
+
data.tar.gz: 80ed22acbfa4ae9991480c0b9af42d5cf01fcc0e964fc8ce659c17aaf1d2daabb285e1c2a7acd025446662a34a9e412f58ce6a5ce1ccecfcd221d2a47d994f51
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/easyvideo_utils.rb
CHANGED
@@ -39,11 +39,16 @@ class EasyVideoUtils
|
|
39
39
|
* concat # concatenate 2 or more videos
|
40
40
|
* convert # alias for transcode
|
41
41
|
* capture # capture the desktop at 1024x768
|
42
|
+
* extract_images # Extracts images at 1 FPS by default
|
42
43
|
* play # plays the video using mplayer
|
43
44
|
* preview # plays the video using ffplay
|
44
45
|
* record # alias for capture
|
46
|
+
* remove_audio # removes the audio track from a video
|
47
|
+
* remove_video # removes the video track from a video. Output file would be an mp3.
|
45
48
|
* resize # resize to 720p
|
46
49
|
* scale # alias for resize
|
50
|
+
* slowdown # slows a viedo down. Defaults to x2 (half-speed)
|
51
|
+
* speedup # speed a video up. Defaults to x2 (twice as fast)
|
47
52
|
* transcode # converts 1 video format to another e.g. avi-> mp4
|
48
53
|
* trim # trims the beginning and ending of a video in hms format e.g. 1m 3s
|
49
54
|
".strip.lines.map {|x| x[/(?<=\* ).*/]}.sort
|
@@ -52,7 +57,13 @@ class EasyVideoUtils
|
|
52
57
|
def initialize(vid_in=nil, vid_out='video.mp4', out: vid_out,
|
53
58
|
working_dir: '/tmp', debug: false)
|
54
59
|
|
55
|
-
@
|
60
|
+
@file_out, @working_dir, @debug = out, working_dir, debug
|
61
|
+
|
62
|
+
if vid_in.is_a? String then
|
63
|
+
@file_in = vid_in
|
64
|
+
elsif vid_in.is_a? Array
|
65
|
+
@files_in = vid_in
|
66
|
+
end
|
56
67
|
|
57
68
|
end
|
58
69
|
|
@@ -90,7 +101,7 @@ class EasyVideoUtils
|
|
90
101
|
# * Video must be of same format and codec
|
91
102
|
# * Only video with no audio is currently supported
|
92
103
|
#
|
93
|
-
def concat(files
|
104
|
+
def concat(files=@files_in, show: false)
|
94
105
|
|
95
106
|
inputs = files.map {|file| "-i #{file}"}.join(' ')
|
96
107
|
filter = files.map.with_index {|file,i| "[%s:v]" % i}.join(' ')
|
@@ -123,6 +134,18 @@ class EasyVideoUtils
|
|
123
134
|
|
124
135
|
end
|
125
136
|
|
137
|
+
# Extract images from the video
|
138
|
+
#
|
139
|
+
# switches used:
|
140
|
+
#
|
141
|
+
# -r – Set the frame rate. I.e the number of frames to be extracted into images per second.
|
142
|
+
# -f – Indicates the output format i.e image format in our case.
|
143
|
+
#
|
144
|
+
def extract_images(show: false, ext: '.png', rate: 1)
|
145
|
+
command = "ffmpeg -i #{@file_in} -r #{rate} -f image2 image-%2d#{ext}"
|
146
|
+
run command, show
|
147
|
+
end
|
148
|
+
|
126
149
|
def play(show: false)
|
127
150
|
command = "mplayer #{@file_out}"
|
128
151
|
run command, show
|
@@ -131,15 +154,59 @@ class EasyVideoUtils
|
|
131
154
|
def preview(show: false)
|
132
155
|
command = "ffplay #{@file_out}"
|
133
156
|
run command, show
|
134
|
-
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def remove_audio(show: false)
|
160
|
+
command = "ffmpeg -i #{@file_in} -an #{@file_out}"
|
161
|
+
run command, show
|
162
|
+
end
|
163
|
+
|
164
|
+
# removes the video track which leaves the audio track
|
165
|
+
# e.g. ffmpeg -i input.mp4 -vn output.mp3
|
166
|
+
#
|
167
|
+
def remove_video(show: false)
|
168
|
+
command = "ffmpeg -i #{@file_in} -vn #{@file_out}"
|
169
|
+
run command, show
|
170
|
+
end
|
135
171
|
|
136
172
|
# Resize avi to 720p
|
137
173
|
#
|
138
|
-
def resize(show: false)
|
139
|
-
|
174
|
+
def resize(scale='720', show: false)
|
175
|
+
command = "ffmpeg -i #{@file_in} -vf scale=\"#{scale}:-1\" #{@file_out} -y"
|
176
|
+
run command, show
|
140
177
|
end
|
141
178
|
|
142
179
|
alias scale resize
|
180
|
+
|
181
|
+
# slow down a video
|
182
|
+
#
|
183
|
+
# note: presentation timestamp (PTS)
|
184
|
+
# 'x2' = half speed; 'x4' = quarter speed
|
185
|
+
|
186
|
+
def slowdown(speed=:x2, show: false)
|
187
|
+
|
188
|
+
factor = {x1_5: 1.5, x2: 2.0, x4: 4.0}[speed.to_s.sub('.','_').to_sym]
|
189
|
+
command = "ffmpeg -i #{@file_in} -vf \"setpts=#{factor}*PTS\" " +
|
190
|
+
"#{@file_out} -y"
|
191
|
+
run command, show
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
# speed up a video
|
196
|
+
#
|
197
|
+
# note: presentation timestamp (PTS)
|
198
|
+
# 'x2' = double speed; 'x4' = quadruple speed
|
199
|
+
|
200
|
+
def speedup(speed=:x2, show: false)
|
201
|
+
|
202
|
+
h = {x1_5: 0.75, x2: 0.5, x4: 0.25, x6: 0.166, x8: 0.125, x16: 0.0625,
|
203
|
+
x32: 0.03125, x64: 0.015625}
|
204
|
+
factor = h[speed.to_s.sub('.','_').to_sym]
|
205
|
+
command = "ffmpeg -i #{@file_in} -vf \"setpts=#{factor}*PTS\" " +
|
206
|
+
"#{@file_out} -y"
|
207
|
+
run command, show
|
208
|
+
|
209
|
+
end
|
143
210
|
|
144
211
|
# Transcodes avi -> mp4
|
145
212
|
#
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|