<commit_before>== Video Recording
NOTE: This feature only works when browsers are run in containers. This can be both vnc or non-vnc containers.

Selenoid can capture browser screen and save it to https://en.wikipedia.org/wiki/MPEG-4[MPEG-4] video file using https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC[H264] codec.
Video recording works by attaching a separate container with https://www.ffmpeg.org/[video capturing software] to running browser container.

To setup this feature you should:

. Pull video recorder image once:
+
```
$ docker pull selenoid/video-recorder
```

. When running Selenoid **in Docker container**:
.. Mount from host a directory (e.g. `~/.aerokube/selenoid/video`) to store video files to `/opt/selenoid/video`.
.. Pass an additional `OVERRIDE_VIDEO_OUTPUT_DIR` environment variable with absolute path to video directory on host machine. This is required because video recorder container, automatically created by Selenoid should save video to host machine video storage directory.
. When running Selenoid **as a binary** - videos will be stored in `video` directory inside current working directory. 
+
.Example Docker Command
----
$ docker run -d
--name selenoid                                 \
-p 4444:4444                                    \
-v /var/run/docker.sock:/var/run/docker.sock    \
-v `pwd`/config/:/etc/selenoid/:ro              \
-v `pwd`/video/:/opt/selenoid/video/            \
-e OVERRIDE_VIDEO_OUTPUT_DIR=`pwd`/video/       \
aerokube/selenoid:latest-release
----

TIP: All these actions are automatically done when starting Selenoid via http://aerokube.com/cm/latest/[Configuration Manager] `selenoid start` command.

=== On Windows

With absolute path your command will look like:

.Windows PowerShell
[source,bash,subs="attributes+"]
----
> docker volume create selenoid-videos
> $current = $PWD -replace "\\", "/" -replace "C", "c"    <1>
> docker run -d                                         `
--name selenoid                                         `
-p 4444:4444                                            `
-v //var/run/docker.sock:/var/run/docker.sock           `
-v ${current}/config/:/etc/selenoid/:ro                 `
-v /c/selenoid/video/:/opt/selenoid/video/              ` <2>
-e OVERRIDE_VIDEO_OUTPUT_DIR=/c/selenoid/video/         ` <3>
aerokube/selenoid:latest-release
----
<1> Simple macros to get $PWD with compatible form assumed your directory located on `C:` drive
<2> Should be absolute path in compatible form
<3> Should be same as in (2)


=== Downloading Video Files from Selenoid

You can access recorded video files using the following URL:

.Direct Link to File
----
http://selenoid-host.example.com:4444/video/<filename>.mp4
----

NOTE: Direct link will works only after session has finished because Selenoid renames temporary filename to `<session-id>.mp4` (by default) at the session close.

To see all available files use:

.Listing All Video Files
----
http://selenoid-host.example.com:4444/video/
----<commit_msg>Added documentation about removing video files (related to #299)<commit_after>== Video Recording
NOTE: This feature only works when browsers are run in containers. This can be both vnc or non-vnc containers.

Selenoid can capture browser screen and save it to https://en.wikipedia.org/wiki/MPEG-4[MPEG-4] video file using https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC[H264] codec.
Video recording works by attaching a separate container with https://www.ffmpeg.org/[video capturing software] to running browser container.

To setup this feature you should:

. Pull video recorder image once:
+
```
$ docker pull selenoid/video-recorder
```

. When running Selenoid **in Docker container**:
.. Mount from host a directory (e.g. `~/.aerokube/selenoid/video`) to store video files to `/opt/selenoid/video`.
.. Pass an additional `OVERRIDE_VIDEO_OUTPUT_DIR` environment variable with absolute path to video directory on host machine. This is required because video recorder container, automatically created by Selenoid should save video to host machine video storage directory.
. When running Selenoid **as a binary** - videos will be stored in `video` directory inside current working directory. 
+
.Example Docker Command
----
$ docker run -d
--name selenoid                                 \
-p 4444:4444                                    \
-v /var/run/docker.sock:/var/run/docker.sock    \
-v `pwd`/config/:/etc/selenoid/:ro              \
-v `pwd`/video/:/opt/selenoid/video/            \
-e OVERRIDE_VIDEO_OUTPUT_DIR=`pwd`/video/       \
aerokube/selenoid:latest-release
----

TIP: All these actions are automatically done when starting Selenoid via http://aerokube.com/cm/latest/[Configuration Manager] `selenoid start` command.

=== On Windows

With absolute path your command will look like:

.Windows PowerShell
[source,bash,subs="attributes+"]
----
> docker volume create selenoid-videos
> $current = $PWD -replace "\\", "/" -replace "C", "c"    <1>
> docker run -d                                         `
--name selenoid                                         `
-p 4444:4444                                            `
-v //var/run/docker.sock:/var/run/docker.sock           `
-v ${current}/config/:/etc/selenoid/:ro                 `
-v /c/selenoid/video/:/opt/selenoid/video/              ` <2>
-e OVERRIDE_VIDEO_OUTPUT_DIR=/c/selenoid/video/         ` <3>
aerokube/selenoid:latest-release
----
<1> Simple macros to get $PWD with compatible form assumed your directory located on `C:` drive
<2> Should be absolute path in compatible form
<3> Should be same as in (2)


=== Downloading Video Files from Selenoid

You can access recorded video files using the following URL:

.Direct Link to File
----
http://selenoid-host.example.com:4444/video/<filename>.mp4
----

NOTE: Direct link will works only after session has finished because Selenoid renames temporary filename to `<session-id>.mp4` (by default) at the session close.

To see all available files use:

.Listing All Video Files
----
http://selenoid-host.example.com:4444/video/
----

=== Deleting Video Files

Selenoid intentionally has no built-in logic to automatically remove old video files. To limit storage space consumption you have two alternatives:

. Schedule scripts automatically removing files older than desired date and time. An example command under Unix operating systems can look like:

    $ find /path/to/video/dir -mindepth 1 -maxdepth 1 -mmin +120 -name '*.mp4' | xargs rm -rf

+
Notice `-mmin +120` argument meaning to only process files older than 2 hours (120 minutes).

. Send video removal requests (e.g. from passed test cases). Just use `DELETE` HTTP method and Selenoid video URL:

    $ curl -X DELETE http://selenoid-host.example.com:4444/video/<filename>.mp4
{'fraction_non_alphanumeric': 0.1085672082717873, 'fraction_numerical': 0.0155096011816839, 'mean_word_length': 2.7763524818739542, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 26, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6387626', 'n_tokens_mistral': 2044, 'n_tokens_neox': 1881, 'n_words': 703}