Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Video < ActiveRecord::Base
- has_attached_file :clip
- has_attached_file :screenshot, :styles => { :small => '96x96#'}
- before_save :make_screenshot
- def make_screenshot
- return if clip.queued_for_write.empty?
- video_file = clip.queued_for_write[:original].path
- filename = temp_file_name
- cmd = "ffmpeg -i #{video_file} -an -ss 00:00:10 -an -r 1 -vframes 1 -y -f mjpeg #{filename} >/dev/null 2>&1"
- Rails.logger.info "Running cmd: #{cmd}"
- system cmd
- self.screenshot = File.open(filename)
- end
- private
- def temp_file_name
- tempdir = Dir::tmpdir || '/tmp'
- t = Time.now.strftime("%Y%m%d")
- path = "clip#{t}-#{$$}-#{rand(0x100000000).to_s(36)}.jpg"
- File.join(tempdir, path)
- end
- end
Add Comment
Please, Sign In to add comment