elgalu / docker-selenium

[NOT MAINTAINED] Please use <https://github.com/SeleniumHQ/docker-selenium>
https://github.com/SeleniumHQ/docker-selenium
Other
1.42k stars 334 forks source link

USE FLV format for screen recording #385

Open kokorin opened 4 years ago

kokorin commented 4 years ago

Hello, thank you for this project.

I have pretty good experience with video/audio formats. I noticed that you use MKV for stream recording (because MP4 doesn't support it) and then convert MKV to MP4. Anyway there are issues if you try to copy MKV while recording.

FLV has no such drawbacks: it was developed essentially for streaming. And it's possible to copy a file during recording and watch it later without issues. FLV does support h264 (MP4 default video codec) so its possible to convert FLV to MP4 very fast: ffmpeg -i recrod.flv -c copy record.mp4.

Also since docker-selenium doesn't need anything except for video and audio tracks, FLV also fits for playback.

elgalu commented 4 years ago

Thanks @kokorin ! what about final file size, CPU usage and browser compatibility in comparison with the current setup?

kokorin commented 4 years ago

@elgalu Encdoded video & audio data occupies 99% of media file size. And it depends on codec and its configuration.

So if you use the same parameters FFMPEG_CODEC_ARGS="-vcodec libx264 -preset ultrafast -pix_fmt yuv420p" (or FFMPEG_CODEC_VA_ARGS="-vcodec libx264 -acodec copy -preset ultrafast") the will be no significant difference in size or in CPU consumption. Also notice please that in FFMPEG_CODEC_VA_ARGS there is no -pix_fmt yuv420p (it's used by default).

So you can only change VIDEO_TMP_FILE_EXTENSION="flv".

There is one more problem in fix_videos.sh: ffmpeg has no option -c copy, this leads to video re-encoding, which takes time. With -c copy conversion will be done approx 100 times faster.

But with FLV format you can entirely skip conversion FLV to MP4 and hence mp4box is also not required.

elgalubot commented 4 years ago

This looks good Denis!

Could you perhaps send a PR? That would be great

On Tue, Jun 2, 2020, 8:54 AM Denis Kokorin notifications@github.com wrote:

@elgalu https://github.com/elgalu Encdoded video & audio data occupies 99% of media file size. And it depends on codec and its configuration.

So if you use the same parameters FFMPEG_CODEC_ARGS="-vcodec libx264 -preset ultrafast -pix_fmt yuv420p" (or FFMPEG_CODEC_VA_ARGS="-vcodec libx264 -acodec copy -preset ultrafast") the will be no significant difference in size or in CPU consumption. Also notice please that in FFMPEG_CODEC_VA_ARGS there is no -pix_fmt yuv420p (it's used by default).

So you can only change VIDEO_TMP_FILE_EXTENSION="flv".

There is one more problem in fix_videos.sh: ffmpeg has no option -c copy, this leads to video re-encoding, which takes time. With -c copy conversion will be done approx 100 times faster.

But with FLV format you can entirely skip conversion FLV to MP4 and hence mp4box is also not required.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/elgalu/docker-selenium/issues/385#issuecomment-637325773, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABUBG5OETU2MZG3LAR43G3RUSO2DANCNFSM4NQCYJXA .

laithshadeed commented 4 years ago

@kokorin, thank you for sharing those tips. My knowledge of video transcoding and FFmpeg parameters is humble. I tried to go through FFmpeg docs:

https://trac.ffmpeg.org/wiki/Encode/H.264 https://ffmpeg.org/ffmpeg.html#Video-Options https://trac.ffmpeg.org/wiki/StreamingGuide https://trac.ffmpeg.org/wiki/Capture/Desktop

However, the results I got are not satisfying. Could you please provide more details?

Yesterday, I tried different combinations using flv/mkv/mp4 with different ffmpeg settings, I settled on:

      - VNC_START=true
      - VIDEO=true
      - SCREEN_WIDTH=1920
      - SCREEN_HEIGHT=1480
      - FFMPEG_FRAME_RATE=60
      - FFMPEG_CODEC_ARGS=-vcodec libx264 -preset medium -pix_fmt yuv420p -framerate 60
      - VIDEO_TMP_FILE_EXTENSION=flv
      - VIDEO_FILE_EXTENSION=flv

I tried to increase the frame rate & use a slower preset to give better quality for the FLV; however, it is still far worst than mp4. For example, check this video; it is severely distorted, especially after 30th seconds. I observed that such distortion is not predictable; sometimes, I got a black background (or shadow).

On the other hand, the current default with mkv->mp4 is predictable; the only problem I'm facing is videos sometimes get truncated (maybe because of what you mentioned about copying while recording). I'm not sure what I'm missing. Could you please provide a working example?

If I understand your ideas better, I could work on a PR for a wider audience; however, to make it useful for others, I have those open questions?

kokorin commented 4 years ago

Which version of FFmpeg is needed? (Right now we have ~2-years old version)

2 years old should work, but it is always better to stick to recent release.

Which scenarios FLV would be superior to MP4 (or vise versa) for video quality while keeping CPU usage & transcoding time comparable.

The quality should not be affected by container (MP4 or FLV)

In case we choose FLV as a default format, how we can avoid distorted videos, like the one I attached.

The issue seems to be caused by keyframes. I would recommend adding -x264-params keyint=20:scenecut=0 to ffmpeg options. Notice that keyint is specified in number of frames. So if you have framerate of 10 FPS, keyint=20 will insert keyframes every 2 seconds. To minimize file size one can put keyframes every 5-10 seconds

For FLV, do we need a particular CPU or GPU that supports specific hardware acceleration?

ffmpeg selects CPU or GPU encoding by specified codec: -c:v h264 uses CPU, -c:v h264_nvenc uses NVidia GPU (it should be available). Probably with docker you can't you GPU encoding.

docker-selenium is required mostly for desktop screen recording. Which settings like screen width/height, framerate or X window configs work best for FLV

It doesn't matter.