Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Recorder: matroskamux / webmmux don't support resolution changes #535

Closed

Description

@j1elo

Prerequisites

Issue description

Starting from GStreamer 1.14, variable resolution videos from Chrome cannot be recorded with KMS.

Kurento has traditionally allowed recording the dynamic resolution changes that come out of Chrome-encoded WebRTC videos, at least with WEBM and MKV recording formats. Internally, the GStreamer pipeline uses either webmmux or matroskamux, which are actually implemented from the same code base (makes sense, as WEBM is just a simplified subset of Matroska). This muxer allowed CAPS events which changed the resolution, but starting from GStreamer 1.14, some code was added to explicitly forbid any change in input caps to the muxer.

  • Originating bug report: Bug 782949 - matroskamux: reject H264 AVC on-the-fly codec_data changes (e.g. from rtph264depay).
  • GStreamer commit: fc37bf7 - matroska-mux: Refuse caps changes after starting to write headers.
  • Later updated by Merge Request 678 - matroskamux: Do caps renegotiation when it only adds fields.

However, VP8 and VP9 encoders do actually allow to change resolution dynamically, regardless of the final container format (e.g. see Does VP9 Support Multiple Resolution Encoding?), so I'm sure we should be able to somehow store to file an VP8 flow with dynamic changes in resolution.

Another lengthier discussion about this seems to imply that while VP8 does allow for dynamic resolution changes, the WEBM container format does not support it by default: Intrinsic dimensions of video; container or VP8 frame size?.

Update 2022/Apr/4: The solution to this issue could be the change proposed in GStreamer MR!1008: matroska/mux: support changing vp8/9 resolution and framerate (not accepted yet).

Context

Recording of WebRTC sessions.

How to reproduce?

In machine A (server):

  1. Run KMS (tested version: 7.0.0 experimental, which uses GStreamer 1.14 from Ubuntu 18.04 Bionic):
    docker run --rm -ti -p 8888:8888 kurento/kurento-media-server/dev-7.0.0
    
  2. Run the kurento-hello-world-recording:
    mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dkms.url=ws://localhost:8888/kurento"
    

In machine B:

  1. Configure some outbound packet loss, e.g. with tc. I've been using slow-network to set a rate limit of 500 kbps and a packet loss of 1.5%:
    sudo ./slow -i eth0 -r 500 -l 1.5
    
  2. Open Chrome and run the application from machine A.

Expected & current behavior

When Chrome decides to change its output resolution, an error message is printed by webmmux:

ERROR recorderendpoint kmsrecorderendpoint.c:1973:bus_sync_signal_handler:<kmsrecorderendpoint0> Error: error message: 0x7f8a04002b20, time 99:99:99.999999999, seq-num 1205, element 'webmmux0', GstMessageError, gerror=(GError)NULL, debug=(string)"matroska-mux.c\(986\):\ gst_matroska_mux_video_pad_setcaps\ \(\):\ /GstPipeline:pipeline1/GstWebMMux:webmmux0:\012Caps\ changes\ are\ not\ supported\ by\ Matroska";

Note the message, Caps changes are not supported by Matroska.

(Optional) Possible solution

Given that, with latest code in GStreamer, the muxer will reject any caps change that doesn't add new fields, we cannot do much here. We need to understand why WEBM/Matroska don't support dynamic resolution changes and reconcile that knowledge with the fact that it has been working for years. Why now suddenly consider it an error?

The dynamic resolution WEBM files that were produced by Kurento would play in all browsers perfectly, and also in other standalone players such as ffplay, so the changes in resolution were actually supported without issues.

Update 2022/Apr/4: The solution to this issue could be the change proposed in GStreamer MR!1008: matroska/mux: support changing vp8/9 resolution and framerate (not accepted yet).

INFO about Kurento Media Server

INFO about end-user clients

  • Device(s): PC
  • OS(es): Linux
  • Browser(s): Chrome >= 85

INFO about your environment

Local tests with a couple of machines connected in LAN, with some simulated packet loss.

Activity

  1. github-actions commented on Oct 7, 2020

    @github-actions

    Hello @j1elo! 👋 we're sorry you found a bug... so first of all, thank you very much for reporting it.

    To know about progress, check in Triage. All issues are considered Backlog Candidates until work priorities align and the issue is selected for development. It will then become part of our official Backlog.

  2. added
    regression
    on Oct 7, 2020
  3. j1elo commented on Oct 7, 2020

    @j1elo
    MemberAuthor

    Some example caps that could arrive to the RecorderEndpoint's CAPS event handler when Chrome changes its output resolution:

    video/x-vp8, framerate=(fraction)31/1, height=(int)480, width=(int)640, profile=(string)0
    video/x-vp8, framerate=(fraction)31/1, height=(int)360, width=(int)480, profile=(string)0
    video/x-vp8, framerate=(fraction)31/1, height=(int)240, width=(int)320, profile=(string)0
    
  4. RaistGH commented on Jun 10, 2021

    @RaistGH

    Has this issue been addressed in any way?
    What it was before an issue with recordings when resolution was changed by Chrome due to BW restrictions or high CPU usage, has become now a critical issue because since Chrome 91 ALL streams sent by Chrome have variable resolution, so right now we cannot record when using Chrome or recording quality gets down to 640x360px when using VP8 and WEBM. I think that the change it's related to this introduced feature to avoid "unnecessary" downscales.
    I'll be writing a bug report to them, but that will not solve the issue for all cases. I think the issue will be eventually solved when variable resolution is supported by the RecorderEndpoint either with a new change in GStreamer (any news about this?) or developing something like what @j1elo was proposing here.
    Regarding the latest, maybe you can guide me about Kurento code files where I can "play" and try to implement something like that? (I'll need to refresh my C++ skills tho :D ). I'd love also some insights about getting Kurento config to be used in code so the feature can be configured in KMS.
    Thanks.

    By the way, brainstorming: could be possible to record different streams for every resolution without waiting for GStreamer to do it when changing resolution? Then they would be packed in the same MKV/WEBM file. Although I wonder about audio sync and rendering changes... Well, actually... how is a variable resolution video stored? Is it indeed as different streams?

    P.S.: Alternatively I see JitSi developers are using a lower GStreamer version as a solution. Is it possible to get a Kurento docker version with GStreamer < 1.14 or do I need to recompile it from source?

  5. j1elo commented on Apr 4, 2022

    @j1elo
    MemberAuthor

    Update from today: The solution to this issue could be the change proposed in GStreamer MR!1008: matroska/mux: support changing vp8/9 resolution and framerate (not accepted yet). Sadly that MR hasn't been merged yet, and it's not clear to me if it will be accepted by the GStreamer maintainers.

    Another, more spec-compliant solution, suggested in GStreamer 1.14 Release Notes is to use the splitmuxsink which can start a new file when the caps change.

    Note that any solution to this problem should keep in mind that decoding the video is not desired and should be avoided whenever possible. When using WebRTC with VP8 video, we want to store the VP8 data as-is to the disk, without any RAW processing (i.e. without having to decode, rescale, and reencode the video).

  6. self-assigned this
    on Apr 8, 2022
  7. j1elo commented on Apr 8, 2022

    @j1elo
    MemberAuthor

    Fixed by Kurento/gst-plugins-good@3b3d2b0

    Use the changes from GStreamer MR!1008 to allow changes in resolution.

  8. j1elo commented on Oct 17, 2022

    @j1elo
    MemberAuthor

    Update: I had commented in support for allowing resolution changes: gst-plugins-good MR!1008, which finally got implemented in 9d0d001d (released with GStreamer 1.20)

  9. neilyoung commented on Nov 30, 2022

    @neilyoung

    The problem with "not supporting resolution changes" is not only a VP8/VP9 problem. Also with H.264 immanent. Makes recording of a variable H.264 video stream impossible. Breaks with the first resolution update

    EDIT: I updated to GST 1.21. The resolution change is now negotiated. The recording does not break anymore. But - after the first resolution change there is just garbage in the output file. It sucks that much...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GStreamerRecorderEndpointregression

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions