russelltg / wl-screenrec

High performance wlroots screen recording, featuring hardware encoding
Apache License 2.0
305 stars 9 forks source link

A/V desync with rtmp output #75

Open russelltg opened 4 months ago

russelltg commented 4 months ago
          Thank you so much for the work @russelltg  ! I missed it because the issue was closed.

So it indeed works locally, there is sound and video working.

There are two caveats left.

When I read the stream in local host, mpv reports :

Audio/Video desynchronisation detected! Possible reasons include too slow
hardware, temporary CPU spikes, broken drivers, and broken files. Audio
position will not match to the video (see A-V status field).
Consider trying `--profile=fast` and/or `--hwdec=auto-safe` as they may help

Second, when trying to send the audio/video stream to an actual endpoint (twitch in my case), wl-screenrec reports:

[rtmp @ 0x610046453ac0] Cannot open connection tcp://live.twitch.tv:1935?listen&listen_timeout=-1000&tcp_nodelay=0
thread 'main' panicked at src/main.rs:1306:87:
called `Result::unwrap()` on an `Err` value: ffmpeg::Error(99: Cannot assign requested address)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Originally posted by @hraytilakhealthcare in https://github.com/russelltg/wl-screenrec/issues/73#issuecomment-2124121332

hraytilakhealthcare commented 4 months ago

Let me know if I can do anything else to add info to the issue. I tried looking at the code, but this is way above my head, sorry.

russelltg commented 4 months ago

No problem--I'm pretty sure this is because the file open command hangs until a client connects, and I think the A/V desync duration is the same as how long it took for someone to connect? Not totally sure :)

hraytilakhealthcare commented 2 months ago

Hey, I tested with the latest version you published. Running the command locally works perfectly, audio and video :

wl-screenrec --geometry "1920,0 1920x1080" --audio --ffmpeg-muxer flv --codec avc --ffmpeg-muxer-options "listen=1" --audio-codec aac --filename "rtmp://localhost:1234"

While the one I'd use to stream still produces an error:

wl-screenrec --geometry "1920,0 1920x1080" --audio --ffmpeg-muxer flv --codec avc --ffmpeg-muxer-options "listen=1" --audio-codec aac --filename "rtmp://live.twitch.tv/app/live_xxx_xxxx"

[rtmp @ 0x5bd7bb7dbdc0] Cannot open connection tcp://live.twitch.tv:1935?listen&listen_timeout=-1000&tcp_nodelay=0
thread 'main' panicked at src/main.rs:1323:87:
called `Result::unwrap()` on an `Err` value: ffmpeg::Error(99: Cannot assign requested address)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I tried with a remote client connected, but I assume twitch must do some kind of buffering or something. Maybe ? I don't know. Let me know if I can test more stuff !