leonid-shevtsov / headless

Create a virtual X screen from Ruby, record videos and take screenshots.
http://leonid.shevtsov.me/en/headless
MIT License
968 stars 113 forks source link

Few ideas #88

Open mits87 opened 7 years ago

mits87 commented 7 years ago

Hello,

I have a few things about the headless gem and video recording.

  1. How can I hide the mouse cursor?
  2. In method stop_and_save in VideoRecorder class good option is add mkdir_p before mv
def stop_and_save(path)
  Recorder::CliUtil.kill_process(@pid_file_path, :wait => true)
  if File.exists? @tmp_file_path
    begin
      **FileUtils.mkdir_p(File.dirname(path))**
      FileUtils.mv(@tmp_file_path, path)
    rescue Errno::EINVAL
      nil
    end
  end
end

what do you think?

  1. In method command_line_for_capture in VideoRecorder class is a small bug:

Before (look on @devices position in array):

[
 CliUtil.path_to(provider_binary_path),
 "-y",
 "-r #{@frame_rate}",
 "-s #{dimensions}",
 "-f x11grab",
@devices,
 "-i :#{@display}",
 group_of_pic_size_option,
 "-vcodec #{@codec}",
 @extra,
 @tmp_file_path
].flatten.compact.join(' ')

After:

[
 CliUtil.path_to(provider_binary_path),
 "-y",
 "-r #{@frame_rate}",
 "-s #{dimensions}",
 "-f x11grab",
 "-i :#{@display}",
 @devices,
 group_of_pic_size_option,
 "-vcodec #{@codec}",
 @extra,
 @tmp_file_path
].flatten.compact.join(' ')

Could you fix it?

  1. Good idea is add something like post_processing_video method or yield that will be triggered in method stop_and_save before FileUtils.mv(@tmp_file_path, path) command. For instance:
def stop_and_save(path, &block)
  Recorder::CliUtil.kill_process(@pid_file_path, :wait => true)
  if File.exists? @tmp_file_path
    begin
      FileUtils.mkdir_p(File.dirname(path))
      yield(@tmp_file_path) if block_given?
      FileUtils.mv(@tmp_file_path, path)
    rescue Errno::EINVAL
      nil
    end
  end
end

This solution will be very helpful for add watermark or other operation after recording. What do you think?

  1. Last one question: how can I stop recording from bash or external script if I know screen number?

Best Regards Peter

orangethunder commented 6 years ago
  1. The mouse cursor can be hidden with:

video: { provider: :ffmpeg, devices: ["-draw_mouse 0"] }

I looked around the source code and found it in the specs. The devices key is not mentioned in the README.