cef_browser: unconditionally write frame, start with transparent frame

This commit is contained in:
Shiz 2020-05-20 00:22:04 +02:00
parent cb210fcc3e
commit 577f35eca3
1 changed files with 8 additions and 5 deletions

View File

@ -38,7 +38,7 @@ class CEFBrowserCapturer:
self.dimensions = dimensions self.dimensions = dimensions
self.url = url self.url = url
self.outfile = outfile self.outfile = outfile
self.frame = None self.frame = b'\x00' * 4 * self.dimensions[0] * self.dimensions[1]
self.rate = rate self.rate = rate
settings = { settings = {
@ -58,20 +58,23 @@ class CEFBrowserCapturer:
window_info.SetAsOffscreen(0) window_info.SetAsOffscreen(0)
self.browser = cef.CreateBrowserSync(window_info=window_info, settings=browser_settings, url=self.url) self.browser = cef.CreateBrowserSync(window_info=window_info, settings=browser_settings, url=self.url)
def __del__(self):
self.browser.CloseBrowser()
cef.Shutdown()
def run_browser(self): def run_browser(self):
self.browser.SetClientHandler(CEFHandler(self)) self.browser.SetClientHandler(CEFHandler(self))
self.browser.SendFocusEvent(True) self.browser.SendFocusEvent(True)
self.browser.WasResized() self.browser.WasResized()
cef.MessageLoop() cef.MessageLoop()
cef.Shutdown()
def output_frames(self): def output_frames(self):
with open(self.outfile, 'wb') as f: with open(self.outfile, 'wb') as f:
frame_duration = 1.0 / self.rate
while True: while True:
t = time.monotonic() t = time.monotonic()
if self.frame: f.write(self.frame)
f.write(self.frame) time.sleep(max(0.0, frame_duration - (time.monotonic() - t)))
time.sleep(1.0 / self.rate - (time.monotonic() - t))
def exit(self, browser=None): def exit(self, browser=None):
browser = browser or self.browser browser = browser or self.browser