Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

USE FLV format for screen recording #385

Open
kokorin opened this issue Jun 1, 2020 · 5 comments
Open

USE FLV format for screen recording #385

kokorin opened this issue Jun 1, 2020 · 5 comments

Comments

@kokorin
Copy link

kokorin commented Jun 1, 2020

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
Copy link
Owner

elgalu commented Jun 1, 2020

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

@kokorin
Copy link
Author

kokorin commented Jun 2, 2020

@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
Copy link
Collaborator

elgalubot commented Jun 2, 2020 via email

@laithshadeed
Copy link

@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?

  • Which version of FFmpeg is needed? (Right now we have ~2-years old version)
  • Which scenarios FLV would be superior to MP4 (or vise versa) for video quality while keeping CPU usage & transcoding time comparable.
  • In case we choose FLV as a default format, how we can avoid distorted videos, like the one I attached.
  • For FLV, do we need a particular CPU or GPU that supports specific hardware acceleration?
  • docker-selenium is required mostly for desktop screen recording. Which settings like screen width/height, framerate or X window configs work best for FLV

@kokorin
Copy link
Author

kokorin commented Jun 13, 2020

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.

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

No branches or pull requests

4 participants