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

Linux chromewebdriver only records top left hand corner of the screen #98

Closed weefunker closed 3 years ago

weefunker commented 3 years ago

Only the top left-hand portion of the screen is being recorded on Ubuntu 18.04

Here is a screenshot of the output

https://imgur.com/Me5iMBy

Apologies in advance if I am missing something really obvious but I have done a lot of digging and tinkering but could not get it to record more than the top left hand side of the desktop

I am running two monitors, though I did test by turning one of them off.

Thanks for this program btw, it is awesome.

weefunker commented 3 years ago

image

Dumb dumb, pasted image of screen instead of the output on imgur

kapoorlakshya commented 3 years ago

@weefunker Could you please copy-paste lines 7-20 (recorder config) here? Will need it to reproduce the issue. Thanks!

jozefvaclavik commented 3 years ago

Maybe its related, but for me on ubuntu 20 with xvfb it was recording only 640x480 resolution. It got resolved by setting advanced: { input: { video_size: '1280x1024' } }. After that it's recording full screen (1280x1024).

For me screenshot is still taken with 640x480.

Here is my configuration

recorder = ScreenRecorder::Desktop.new(
  input: ':1.0',
  output: "#{export_path}/recording.mkv",
  advanced: { input: { video_size: '1280x1024' } }
)
recorder.start
# do bunch of things
recorder.screenshot("#{export_path}/screenshot.png")
recorder.stop
recorder.video.transcode(...)

open-2fa35115-f3ea-463c-8207-324489fe00dd recording-cfcdb539-3c90-4aac-83b9-50bfba719204.m4v.zip

weefunker commented 3 years ago

Thank you buddy that solved it

kapoorlakshya commented 3 years ago

For me screenshot is still taken with 640x480.

@jozefvaclavik That's interesting! Do you know if this happen with xvfb only?

jozefvaclavik commented 3 years ago

@kapoorlakshya I have some more details about the screenshot issue. advanced: { input: { video_size: '1280x1024' } } is not passed to the screenshot command.

    #
    # Generates the command line arguments based on the given
    # options.
    #
    def ffmpeg_command
      "#{ffmpeg_bin} #{@options.parsed}"
    end

    #
    # Parameters to capture a single frame
    #
    def screenshot_cmd(filename)
      # -f overwrites existing file
      "#{ffmpeg_bin} -f #{options.capture_device} -i #{options.input} -framerate 1 -frames:v 1 #{filename}"
    end

The ffmpeg_command uses @options.parsed, but screenshot_cmd does not. screenshot_cmd uses few specific options. I did some debugging on our staging with monkeypatching these methods. First I tried to add @options.parsed to screenshot command, but that just added bunch of options that at the end crashed. I saw there -video_size 1280x1024. When I added that to the screenshot_cmd, it took properly sized screenshot.

      def screenshot_cmd(filename)
        # -f overwrites existing file
        "#{ffmpeg_bin} -video_size 1280x1024 -f #{options.capture_device} -i #{options.input} -framerate 1 -frames:v 1 #{filename}"
      end

Here is log output from regular screenshot command:

root@sidekiq-f9b748f77-hw9xs:/app# /usr/bin/ffmpeg -y -f x11grab -i :1.0 -framerate 1 -frames:v 1 /app/tmp/open-1.png
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, x11grab, from ':1.0':
  Duration: N/A, start: 1621616820.913329, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to '/app/tmp/open-1.png':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: png, rgb24, 640x480, q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc58.54.100 png
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=1.28x
video:4kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

root@sidekiq-f9b748f77-hw9xs:/app# ls -la tmp/
total 4
drwxr-xr-x 1 root root   49 May 21 21:07 .
drwxr-xr-x 1 root root   46 May 21 21:03 ..
drwxr-xr-x 3 root root   22 May 21 20:53 cache
-rw-r--r-- 1 root root    0 May 21 20:47 .keep
-rw-r--r-- 1 root root 3779 May 21 21:07 open-1.png
drwxr-xr-x 1 root root   25 May 21 20:49 pids
drwxr-xr-x 3 root root   31 May 21 21:03 test

And here is output when I add -video_size 1280x1024 to the cmd:

root@sidekiq-f9b748f77-hw9xs:/app# /usr/bin/ffmpeg -y -video_size 1280x1024 -f x11grab -i :1.0 -framerate 1 -frames:v 1 /app/tmp/open-2.png
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[x11grab @ 0x55d00fc1f800] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':1.0':
  Duration: N/A, start: 1621616849.060395, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1280x1024, 29.97 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to '/app/tmp/open-2.png':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: png, rgb24, 1280x1024, q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc58.54.100 png
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=0.396x
video:24kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
root@sidekiq-f9b748f77-hw9xs:/app# ls -la tmp/
total 28
drwxr-xr-x 1 root root    67 May 21 21:07 .
drwxr-xr-x 1 root root    46 May 21 21:03 ..
drwxr-xr-x 3 root root    22 May 21 20:53 cache
-rw-r--r-- 1 root root     0 May 21 20:47 .keep
-rw-r--r-- 1 root root  3779 May 21 21:07 open-1.png
-rw-r--r-- 1 root root 24317 May 21 21:07 open-2.png
drwxr-xr-x 1 root root    25 May 21 20:49 pids
drwxr-xr-x 3 root root    31 May 21 21:03 test

Hope this helps. I could open PR, but I'm not sure if just getting the video_size from advanced is all that needs to be done.

kapoorlakshya commented 3 years ago

@jozefvaclavik Thanks for the detailed info. I am thinking of adding an optional resolution arg to #screenshot:

What do you think?

jozefvaclavik commented 3 years ago

@kapoorlakshya sounds good to me.

Specifying resolution may later lead towards specifying position as well. For example take 300x400 screenshot at 1000x500. In my case just the resolution is enough. Thanks!

kapoorlakshya commented 3 years ago

@jozefvaclavik Just got a chance to work on this. Not sure why, but the resolution arg is not working (test fails) on macOS even though avfoundation (mac codec) supports it (see Options). Seems to work fine on Linux and Windows though.

I'll try to spend a little bit more time to troubleshoot it this week. Hopefully it's something simple.

kapoorlakshya commented 3 years ago

Just learned that -s '1024x768' is what works on macOS, but not on Windows (test failure). Windows wants -video_size instead... Will share an update soon.

kapoorlakshya commented 3 years ago

Just released v1.6.0 with support for screenshot resolution.