-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[rust] Desktop recording with Selenium Manager and FFmpeg #15311
base: trunk
Are you sure you want to change the base?
Conversation
This reverts commit c67f281.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
CI Feedback 🧐(Feedback updated until commit 1e804c7)A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
This doesn't seem to be getting any attention, but FWIW... I think it's a cool feature. |
I think it's a great feature - very much missing - and I am waiting to use this. |
We are still talking to see if this is the approach we want to follow. |
@cgoldberg There are some comments about this PR in #selenium-tlc channel in Slack: https://seleniumhq.slack.com/archives/CBH302726/p1740050766269619 @nirtal85 Yes, FFmpeg also supports screencasting to MP4 and other container formats (e.g., MOV, MKV, etc.) and different video codecs (e.g., MPEG-4, etc.). I have selected AVI since it is pretty "safe" in the sense that the media chunks are always playable once they are written in the file. For instance, MP4 needs a proper termination of the recording media, or otherwise, the resulting video is not playable. However, this choice (AVI+MPEG-4) could be changed (or perhaps to be configurable) if we finally decide to land this feature. |
User description
Motivation and Context
This PR implements the first step for a new feature for Selenium users: desktop recording. The recording is done by Selenium Manager using FFmpeg. The idea is that bindings use this feature on demand. A possible way to enable this feature is as follows:
With this, the bindings will call Selenium Manager as follows:
With that call, in addition to managing the driver/browser, Selenium Manager will manage the static build of FFmpeg (version 7.1) for the local operating system (Windows, Linux, or macOS). Like the drives and browsers, the FFmpeg binary is stored in the cache and used from there. Then, when the bindings receive the session start request, all Selenium Manager again start the desktop recording, as follows:
An approach to this call is using a new thread in the bindings. The Selenium Manager process is called FFmpeg and records the desktop using different Windows, Linux, and macOS commands. Currently, the recording is stored in the cache folder as follows:
The created media files use MPEG-4 video codec since it balances size and quality well. The AVI container is suitable for creating playable media even when stopping the recording process abruptly.
When the Selenium session terminates (
driver.quit()
), the bindings will terminate the previous thread, ensuring the Selenium Manager process and its children process (i.e.,ffmpeg
) is terminated (like when executing Ctrl+C in the shell). This will stop the recording command, and the resulting AVI file should be in the cache.I created an automated test to verify this feature in Rust. It is executed in CI, and the resulting recordings are attached to the job execution. For example:
https://github.com/SeleniumHQ/selenium/actions/runs/13423599803
I cannot get the macOS recordings since, in macOS, desktop recording is an operation that requires explicit permission (see here). I double-checked:
After granting permission to the terminal to record the desktop, Selenium Manager can also record the macOS desktop. Unfortunately, I believe we cannot do this with the GitHub Actions runners.
What do you think?
There are still improvements that could be made in Rust. For example, to customize the output folder and record file name through some parameter. Also, some FFmpeg parameters (e.g., video codec, recording size, etc.) can be parameterized. But before doing that, I would like to discuss if we want to implement this across all bindings. In my opinion, it will be an appealing feature for Selenium users. Perhaps for Selenium 5.
Context
I proposed this PR some time ago: #14452
The main aim of this PR was to allow users to record the Selenium sessions, which is a very appealing feature for troubleshooting. But discussing this PR, @shs96c said that using Docker to provide recording was not the way since Docker is a dependency we don't want. And that is right. Ideally, we don't want to impose the use of Docker just to get records. So, I started to look for an alternative. I first tried to use a pure Rust implementation for desktop recording to do the recording from Selenium Manager. I found a promising project: https://github.com/CapSoftware/scap
But that crate is not mature enough. Then, I got another idea: to manage the static builds of FFmpeg (like we already do with the drivers) and call it from Selenium Manager to record the desktop. It should not be that difficult. So, I implemented it, and it seems to work nicely.
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
Introduced desktop recording functionality using FFmpeg in Selenium Manager.
Added support for downloading and managing FFmpeg binaries across platforms.
Implemented CLI options for enabling FFmpeg and desktop recording.
Added tests and CI workflows to validate recording functionality.
Changes walkthrough 📝
5 files
Implement FFmpeg integration for desktop recording
Refactor file handling for FFmpeg support
Integrate FFmpeg recording into Selenium Manager
Add CLI options for FFmpeg and recording
Extend shell command execution for FFmpeg
2 files
Add helper for Selenium Manager binary in tests
Add tests for desktop recording functionality
2 files
Update workflow to support recording artifacts
Enable recording tests in CI workflow
1 files
Add dependencies for FFmpeg and recording functionality