AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
3.79k stars 309 forks source link

Airplay screen mirror #729

Open dts350z opened 8 months ago

dts350z commented 8 months ago

Is there functionality to receive Apple Airplay screen mirroring (and restream it)?

If so, how to turn it on?

If not, Feature Request.

Similar question for whatever technologies Android devices use for screen mirroring.

Doing both now via HDMI, but wireless would be a great option and avoid cables/adapters.

dts350z commented 8 months ago

I see https://github.com/antimof/UxPlay can be easily installed as a package and uses GStreamer, however I'm not sure how to make the connection between UxPlay and go2rtc (especially as I'm running go2rtc via docker).

AlexxIT commented 8 months ago

There's no such thing in the immediate plans. It's a lot of work, not much profit.

seydx commented 8 months ago

There's no such thing in the immediate plans. It's a lot of work, not much profit.

Any idea why its also not possible to stream a hls source via airplay?

HLS stream itself is working fine on safari, but as soon as i click on airplay, go2rtc receives a stop signal and closing the stream

dts350z commented 8 months ago

I have some progress on this but won't have a full up test until later today.

Uxplay for the airplay server, with:

-as 0 -vc "videorate ! video/x-raw,framerate=5/1 ! videoconvert" -vs "v4l2sink device=/dev/video8"

flags to send its output to a loopback device. I can play that device in VLC. The full up test will be to then use that as an input device for go2rtc. This is on a Pi 5 running bookworm.

dts350z commented 8 months ago

I Haven't yet found the right go2rtc configuration for the video I ended up with out the gstreamer to the loopback interface.

Here are the details:

$ sudo v4l2-ctl --device=/dev/video8 --all Driver Info: Driver name : v4l2 loopback Card type : Dummy video device (0x0000) Bus info : platform:v4l2loopback-000 Driver version : 6.1.58 Capabilities : 0x85200003 Video Capture Video Output Read/Write Streaming Extended Pix Format Device Capabilities Device Caps : 0x05200003 Video Capture Video Output Read/Write Streaming Extended Pix Format Priority: 2 Video input : 0 (loopback: ok) Video output: 0 (loopback in) Format Video Output: Width/Height : 608/1080 Pixel Format : 'YUYV' (YUYV 4:2:2) Field : None Bytes per Line : 1216 Size Image : 1313280 Colorspace : sRGB Transfer Function : sRGB YCbCr/HSV Encoding: ITU-R 601 Quantization : Limited Range Flags : Streaming Parameters Video Capture: Frames per second: 30.000 (30/1) Read buffers : 2 Streaming Parameters Video Output: Frames per second: 30.000 (30/1) Write buffers : 2

User Controls

                keep_format 0x0098f900 (bool)   : default=0 value=0
          sustain_framerate 0x0098f901 (bool)   : default=0 value=0
                    timeout 0x0098f902 (int)    : min=0 max=100000 step=1 default=0 value=0
           timeout_image_io 0x0098f903 (bool)   : default=0 value=0

I tried variations on this:

video8: ffmpeg:device?video=8#video=h264#hardware=v4l2m2m

and

video8: ffmpeg:device?video=8#video=YUYV or YUY2(?)

but no joy.

Would be great if someone has a solution.

AlexxIT commented 8 months ago

WebUI > Add > FFmpeg devices

dts350z commented 8 months ago

Thanks.

With that:

video4: ffmpeg:device?video=/dev/video4&input_format=yuyv422&video_size=1920x1080#video=h264#hardware

I do get an initial frame, but them: 17:20:10.208 WRN github.com/AlexxIT/go2rtc/internal/streams/producer.go:171 > error="read tcp 127.0.0.1:8554->127.0.0.1:50564: i/o timeout" url=ffmpeg:device?video=/dev/video4&input_format=yuyv422&video_size=1920x1080#video=h264#hardware

repeating

FYI If I open device video4 in VLC it plays OK.

AlexxIT commented 8 months ago

Are you sure it should be video4? There is video8 in your previous messages. Is it your Pi W? Maybe it can't transcode video to H264.

dts350z commented 8 months ago

Yes video4 (fewer HDMI USB devices plugged in now, vs. before), Again, I get an initial screen from the video, then "spinning" in the client browser, and the errors.

Also, Video4 plays correctly in VLC (on the Pi) as I mentioned.

No, this is not a Pi Zero 2 W (as in the other thread). This is a Pi 5, bookworm.

iPhone or IPad AirPlay screen mirror --> Uxplay --> gstreamer to video loopback device --> go2rtc

I can share the gstreamer pipline from Uxplay, if that would be helpful.

I suppose it might be possible to skip the loopback device. but as uxplay is running native and go2rtc is in docker I didn't know how else to do it, other than passing a device.

AlexxIT commented 8 months ago

Yes. You can share your setup in detail

dts350z commented 8 months ago

OK, after much effort to find a working pipeline, here is the gstreamer pipline i'm using in uxplay to get AirPlay screen share video into a loopback device:

"appsrc name=video_source ! queue ! h264parse ! decodebin ! videorate ! video/x-raw,framerate=5/1 ! videoconvert ! v4l2sink device=/dev/video4 name=video_sink sync=false"

It just occurred to me that maybe I should try with framerate=25/1 or 30/1 as 5/1 was arbitrary and I just thought it would be a good idea to keep it slow for hardware resource reasons.

The reason for videorate ! video/x-raw,framerate=5/1 , before video convert, is gstreamer was giving an error with a variable frame rate, with the V4l2sink and my video in.

To get the above gstreamer pipline, the uxplay command is:

uxplay -as 0 -vc "videorate ! video/x-raw,framerate=5/1 ! videoconvert" -vs "v4l2sink device=/dev/video8"

Where video8 is the loopback device. You can add -d for debug output (including the gstreamer pipeline.

Again, Uxplay is running native binary on Pi 5 bookwork, and go2rtc is in docker.

sudo docker run -p 1984:1984 -p 8554:8554 -p 8555:8555/tcp --device=/dev/video0 --device=/dev/video8 -v /home/glenn/go2rtc_config:/config alexxit/go2rtc

where video0 is an HDMI to USB adapter, and video8 is the loopback device, made with:

sudo apt install v4l2loopback-dkms sudo modprobe v4l2loopback <-- doesn't last across reboot looback test: gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video8 play /dev/video8 (advanced settings) in VLC

go2rtc config is:

streams: usb0: ffmpeg:device?video=0#video=mjpeg#hardware video8: ffmpeg:device?video=/dev/video0&input_format=yuyv422&video_size=1920x1080#video=h264#hardware

dts350z commented 8 months ago

faster or slower fame rates don't seem to help.