Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 65 additions & 3 deletions lib/flick/video.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Video

attr_accessor :action, :platform, :driver, :image_count, :seconds, :rate, :extended, :udid, :format
attr_accessor :action, :platform, :driver, :image_count, :seconds, :rate, :extended, :udid, :format, :time_table

def initialize options
Flick::Checker.action options[:action]
Expand All @@ -20,6 +20,7 @@ def initialize options
self.extended = options[:extend].to_b
self.udid = self.driver.udid
self.format = options[:format]
self.time_table = Array.new
end

def android
Expand Down Expand Up @@ -109,12 +110,23 @@ def start_screenshot_record
Flick::System.kill_process "screenshot", udid
puts "Process will stop after #{image_count} screenshots.\n"
$0 = "flick-screenshot-#{udid}"

first_screenshot_time = Time.now

SimpleDaemon.daemonize!
command = -> do
count = "%03d" % 1
count = "%05d" % 1
first_screenshot_time

loop do
if count.to_i <= image_count
driver.screenshot "screenshot-#{udid}-#{count}"
if count.to_i == 0
@time_codes[count.to_i] = 0
first_screenshot_time = Time.now
else
@time_codes[count.to_i] = (Time.now - first_screenshot_time) * 1000
end
count.next!; sleep seconds
else
stop_screenshot_recording
Expand Down Expand Up @@ -144,12 +156,62 @@ def mp4

def convert_images_to_mp4
remove_zero_byte_images
%x(ffmpeg -loglevel quiet -framerate #{rate} -pattern_type glob -i '#{driver.flick_dir}/screenshot-#{udid}*.png' -c:v libx264 -pix_fmt yuv420p #{driver.flick_dir}/#{driver.name}.mp4)
# %x(ffmpeg -loglevel quiet -framerate #{rate} -pattern_type glob -i '#{driver.flick_dir}/screenshot-#{udid}*.png' -c:v libx264 -pix_fmt yuv420p #{driver.flick_dir}/#{driver.name}.mp4)

create_timecode_file

#MP4 Creation for constant framerate
puts "ffmpeg -pattern_type glob -i '#{driver.flick_dir}/screenshot-#{udid}*.png' -pix_fmt yuv420p #{driver.flick_dir}/record-#{udid}-cfr.mp4 \n"
command = Thread.new do
system("ffmpeg -pattern_type glob -i '#{driver.flick_dir}/screenshot-#{udid}*.png' -pix_fmt yuv420p #{driver.flick_dir}/record-#{udid}-cfr.mp4")
end
command.join
puts "===== Command was completed ===== \n"

#MP4 is converted variable frame rate against to the timecode.txt via mp4fpsmod command.
puts "mp4fpsmod -o #{driver.flick_dir}/record-#{udid}-vfr.mp4 -t #{driver.flick_dir}/timecode-#{udid}.txt #{driver.flick_dir}/record-#{udid}-cfr.mp4 \n"
command = Thread.new do
system("mp4fpsmod -o #{driver.flick_dir}/record-#{udid}-vfr.mp4 -t #{driver.flick_dir}/timecode-#{udid}.txt #{driver.flick_dir}/record-#{udid}-cfr.mp4")
end
command.join
puts "===== Command was completed ===== \n"

#MP4 is converted to vfr to cfr for proper playback.
puts "ffmpeg -i #{driver.flick_dir}/record-#{udid}-vfr.mp4 #{driver.flick_dir}/#{driver.name}.mp4 \n"
command = Thread.new do
system("ffmpeg -i #{driver.flick_dir}/record-#{udid}-vfr.mp4 #{driver.flick_dir}/#{driver.name}.mp4")
end
command.join
puts "===== Command was completed ===== \n"

end

def remove_zero_byte_images
Dir.glob("#{driver.flick_dir}/screenshot-#{udid}*.png").each do |f|
File.delete f if File.zero? f
end
end


def create_timecode_file
# files = Dir.glob("#{driver.flick_dir}/screenshot-#{udid}*.png")
# files = files.sort_by {|f| File.ctime(f)}

first_file_creation_time = @time_codes[0]

# files.each do |file|
# diff = File::ctime(file) - first_file_creation_time
# time_codes.insert(time_codes.length, (diff * 1000).to_i.to_s())
# end

@time_codes.each do |time|
diff
end

File.new(driver.flick_dir + "/timecode-#{udid}.txt", "w+")
File.open(driver.flick_dir + "/timecode-#{udid}.txt", "w+") do |f|
f.puts(time_codes)
end

end
end