-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.rb
40 lines (32 loc) · 852 Bytes
/
camera.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'streamio-ffmpeg'
class Camera
def initialize(snapshot_str, index)
@snapshot_str = snapshot_str
@index = index
end
def snapshot
Dir.mkdir(Dir.pwd + '/'+ @index) unless Dir.exist?(Dir.pwd + '/'+ @index)
`#{@snapshot_str.chomp} #{current_file}.jpg`
end
def create_daily_video
FFMPEG::Transcoder.new(
'',
"#{Dir.pwd}/#{@index}/#{today}_#{@index}.mp4",
{video_codec: 'libx264', x264_preset: 'slow', threads: 4},
input: "#{Dir.pwd}/#{@index}/*#{@index}.jpg",
input_options: {framerate: '16', pattern_type: 'glob'}
).run
end
def cleanup
`rm #{Dir.pwd}/#{@index}/*_#{@index}.jpg`
end
def today
`date +"%Y-%b-%d"`.chomp!
end
def current_file
"#{Dir.pwd}/#{@index}/#{now}_#{@index}"
end
def now
Time.now.strftime '%d-%b-%H-%M-%S'
end
end