kapoorlakshya / screen-recorder

A Ruby gem to video record and take screenshots of your desktop or specific application window. Works on Windows, Linux, and macOS.
MIT License
192 stars 17 forks source link

Video fails to stop #81

Closed aaron-humerickhouse closed 4 years ago

aaron-humerickhouse commented 5 years ago

Summary

My video file saves and is persisted. When I try to open it, it cannot be played.

RSpec.configure do |config|
  config.prepend_before :each do |config|
    full_description = config.metadata[:full_description]
    @browser = Watir::Browser.new

    recording_name = full_description.gsub(/\s/, '-').downcase + '.mp4'
    ScreenRecorder.logger.level = Logger::DEBUG
    @recorder = ScreenRecorder::Desktop.new(output: "spec/artifacts/recordings/#{recording_name}")
    @recorder.start
  end

  config.after :each do |config|
    @recorder.stop
    @recorder.delete unless config.exception
    @browser.close if @browser
  end
end

Debug Info

Please provide the following information for bug reports:

Expected Behavior

Recording to stop appropriately. Able to watch the video

Actual Behavior

Recording fails to stop. Unable to watch the video

kapoorlakshya commented 4 years ago

Hey @aaron-humerickhouse, thanks for the detailed bug report. The logs are showing that ffmpeg is failing to stop normally for some reason. As a result, the gem is force killing it to avoid having a zombie process. This ultimately is causing the unplayable video.

2019-10-30 18:04:14 ScreenRecorder - ERROR - FFmpeg failed to stop. Force killing it...
2019-10-30 18:04:17 ScreenRecorder - ERROR - Check 'ffmpeg.log' for more information.

Now we need to figure out why ffmpeg is not stopping normally, and for that I looked at the ffmpeg.log and found out that the input stream is being captured at 1000k fps for some reason. Let's initialize the recorder with an input FPS and see if that fixes the problem:

advanced = { input: { framerate: 15 } }
out_file = "spec/artifacts/recordings/#{recording_name}"
@recorder = ScreenRecorder::Desktop.new(output: out_file, advanced: advanced)

Also, are you using the latest version of this gem?

kapoorlakshya commented 4 years ago

@aaron-humerickhouse I was able to reproduce and actually fix the issue by passing vsync 0 for the input on macOS:

advanced = { input: { vsync: 0 } }
out_file = "spec/artifacts/recordings/#{recording_name}"
@recorder = ScreenRecorder::Desktop.new(output: out_file, advanced: advanced)

Feel free to reopen this issue if that doesn't work for you.