Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recording headless selenium tests to mp4 with Xvfb and ffmpeg #4

Open
afterdesign opened this issue Feb 7, 2016 · 8 comments
Open
Labels

Comments

@afterdesign
Copy link
Owner

If you found error in my post or have new interesting insights on this topic please leave your comment here.

Thanks !

@kjagiello
Copy link

I just wonder if you know if it would be possible to achieve 60 fps using this method? I'm looking for a way to convert a page with a bit of CSS animations to a video file and I came across your post and it seemed promising!

@afterdesign
Copy link
Owner Author

@kjagiello I think you can try to set -r parameter to 60 and check the end result.
From documentation:

-r[:stream_specifier] fps (input/output,per-stream)
Set frame rate (Hz value, fraction or abbreviation).

As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps. This is not the same as the -framerate option used for some input formats like image2 or v4l2 (it used to be the same in older versions of FFmpeg). If in doubt use -framerate instead of the input option -r.

As an output option, duplicate or drop input frames to achieve constant output frame rate fps.

@kot-ch
Copy link

kot-ch commented May 14, 2017

Hi Rafał! Thank you very much for the nice post!

I've used your post while writing an article about converting SWF into MP4 (I'm not very good at English so the article has been written in Russian). In few details: I've played SWF video on virtual screen and captured it with aid of FFmpeg.


Let me put my two cents in. It's possible to stop FFmpeg politely without tmux but with aid of Bash co-process. All you need is just to run ffmpeg via coproc. The following script:

#!/usr/bin/env bash

coproc ffmpeg -f x11grab -video_size 1680x1050 -i :0 -codec:v libx264 -r 5 ./test.mp4 &
sleep 10
echo 'q' >&"${COPROC[1]}"

captures screen for about 10 seconds. I tried to play the resultant test.mp4 file in VLC - everything is OK. And FFmpeg reports that the file has correct duration, e.g.:

$ ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 test.mp4
10.200000

@afterdesign
Copy link
Owner Author

@flaz14 This is really cool ! Thanks for the info :)

@Tejareddy1
Copy link

Hi,
I have a question regarding parallel tests running in a single docker container.

I am using parallel_tests(https://github.com/grosser/parallel_tests/tree/master/lib/parallel_tests) gem to run the RSpec tests parallelly. Currently, we have a mechanism to record the video using xvfb where it records complete screen. So here it is recording multiple test runs in a single frame buffer I feel. I want to run the tests parallelly with parallel recordings for each browser which opens. Can you please help me with this?

@kot-ch
Copy link

kot-ch commented May 8, 2019

Hi @Tejareddy1,

Sure, you need separate virtual screen for each test & Xvfb instance. Look at Linux screen command. It may help.

@ghost
Copy link

ghost commented Jan 21, 2020

I loved it ! It Gave me hope to complete a job

@Vito300187
Copy link

Vito300187 commented Jun 3, 2020

@afterdesign hello! I have a similar task, only tests need to be written locally, in headless mode. My Xvfb startup command Xfvb :99 -screen 0 1600x1200x24+32 & RECORD_VIDEO=true rspec spec/processor_spec.rb specifying the variable, RECORD_VIDEO, if true, the screen recording command is enabled - ffmpeg -f x11grab -i :99 -c:v libx264 -preset ultrafast -tune zerolatency -crf 25 //tmp/file.mkv. The command itself is in the test. Can you tell please, why my video file has a black screen ? The tests are passed locally, but the video is not recorded. If I run tests without Xvfb, the video is written perfectly. I run tests with Xvfb support on the server machine by logging in to the server machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants