Sha256: 03363d1c7e2d6d6b0868d54463faaf9589bc4951ea465c1ef4fff668e6f91442
Contents?: true
Size: 1.55 KB
Versions: 9
Compression:
Stored size: 1.55 KB
Contents
module Ffmprb class File def sample( at: 0.01, video: true, audio: true, &blk ) audio = File.temp('.wav') if audio == true video = File.temp('.png') if video == true Ffmprb.logger.debug "Snap shooting files, video path: #{video ? video.path : 'NONE'}, audio path: #{audio ? audio.path : 'NONE'}" fail Error, "Incorrect output extname (must be image)" unless !video || video.channel?(:video) && !video.channel?(:audio) fail Error, "Incorrect audio extname (must be sound)" unless !audio || audio.channel?(:audio) && !audio.channel?(:video) fail Error, "Can sample either video OR audio UNLESS a block is given" unless block_given? || !!audio != !!video cmd = %W[-i #{path}] cmd.concat %W[-deinterlace -an -ss #{at} -r 1 -vcodec mjpeg -f mjpeg #{video.path}] if video cmd.concat %W[-vn -ss #{at} -t 1 #{audio.path}] if audio Util.ffmpeg *cmd return video || audio unless block_given? begin yield *[video || nil, audio || nil].compact ensure begin video.remove if video audio.remove if audio Ffmprb.logger.debug "Removed sample files" rescue Ffmprb.logger.warn "Error removing sample files: #{$!.message}" end end end def sample_video(*video, at: 0.01, &blk) sample at: at, video: (video.first || true), audio: false, &blk end def sample_audio(*audio, at: 0.01, &blk) sample at: at, video: false, audio: (audio.first || true), &blk end end end
Version data entries
9 entries across 9 versions & 1 rubygems