-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only save images from screencast: Images can be combined later
- Loading branch information
Showing
3 changed files
with
8 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# frozen_string_literal: true | ||
require "ferrum/screencaster" | ||
|
||
|
||
module Ferrum | ||
class Page | ||
module Screencast | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'open3' | ||
require 'stringio' | ||
#TODO these ^ need to be added to gemfile | ||
require 'concurrent-ruby' | ||
|
||
module Ferrum | ||
class Screencaster | ||
# attr_reader :message, :default_prompt | ||
include Concurrent::Async | ||
|
||
def initialize(page) | ||
@page = page #might be wrong | ||
@stdin = StringIO.new | ||
@stdout = StringIO.new | ||
@stderr = StringIO.new | ||
@wait_thr = nil | ||
@page = page | ||
end | ||
|
||
def add_frame(params) | ||
warn 'frame' | ||
@page.command("Page.screencastFrameAck", sessionId: params["sessionId"]) | ||
img = params["data"] | ||
img_decoded = Base64.decode64(img) | ||
@stdin.write(img_decoded) | ||
|
||
ts = (Time.now.to_f * 1000).to_i | ||
File.binwrite("img_#{ts}.jpeg", Base64.decode64(params["data"])) | ||
end | ||
|
||
def start_screencast #(options) | ||
cmd = "ffmpeg -y -f image2pipe -i - -c:v libx264 -preset slow -crf 22 -r 1 -an -f mp4 -movflags +faststart output_video2.mp4" | ||
@stdin, @stdout, @stderr, @wait_thr = Open3.popen3(cmd) | ||
@page.command("Page.startScreencast", format: "jpeg") #, **options) | ||
def start_screencast | ||
@page.command("Page.startScreencast", format: "jpeg") | ||
end | ||
|
||
def stop_screencast | ||
warn 'stopped' | ||
@page.command("Page.stopScreencast") | ||
@stdin.close | ||
@stdout.close | ||
@stderr.close | ||
@wait_thr.join | ||
end | ||
end | ||
end |