ammen99 / wf-recorder

MIT License
888 stars 62 forks source link

Screencast? #167

Open TheChymera opened 2 years ago

TheChymera commented 2 years ago

Is there any way to use wf-recorder to cast my screen via HTTP? I was thinking perhaps the output could be piped via SSH to a publicly accessible video file... I haven't gotten that far yet, since even locally, the output file of wf-recorder -f myout.mp4 cannot be played before wf-recorder is closed.

Any ideas whether this could be done somehow? Screencasting soltuions for wayland tend to either not work or be quite convoluted, it would be really great if this could be done with a few chained bash commands.

git-bruh commented 2 years ago

You can output to v4l2 (virtual camera, search for v4l2loopback) with the following command:

yes | wf-recorder -t --muxer=v4l2 --codec=rawvideo --pixel-format=yuv420p --file=/dev/video0

Where /dev/video0 is the virtual device created by v4l2. This works for screen sharing in web apps like jitsi, so you can probably build on top of this.

TheChymera commented 2 years ago

@git-bruh I have tried that workaround for videoconferencing, but is there any way to do this without that extra bit of potentially unreliable infrastructure? (among other things web apps will messes up the resolution and apply compression formats which might be good for faces but not for text) Can I just select a remotely accessible file to upload to via SSH? What would be the formats that would allow viewing a file which is actively being written to?

soreau commented 2 years ago

This is only lightly tested but I am able to stream desktop to html page with v4l2loopback. Here's what worked for me:

Assumptions:

Insert the following html: Head:

<link href="https://vjs.zencdn.net/7.2.3/video-js.css" rel="stylesheet">

Body:

<video id='video-stream' class="video-js vjs-default-skin center" width="640" height="480" controls>
        <source type="application/x-mpegURL" src="streams/desktop-stream1.m3u8">
</video>

Scripts:

<script src="https://vjs.zencdn.net/ie8/ie8-version/videojs-ie8.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.14.1/videojs-contrib-hls.js"></script>
<script src="https://vjs.zencdn.net/7.2.3/video.js"></script>
<script>
    var player = videojs('video-stream');
    player.play();
</script>

where 'streams/desktop-stream1.m3u8' is a path relative to the html file. Then, setup the video stream by running these commands:

sudo modprobe v4l2loopback exclusive_caps=1 card_label=desktop_view1 wf-recorder --muxer=v4l2 --codec=rawvideo --file=/dev/video2 -x yuv420p -t ffmpeg -i /dev/video2 -an /var/www/website/streams/desktop-stream1.m3u8

At this point, you should be able to refresh the page and play the video.

ammen99 commented 2 years ago

As an alternative, you could try to set up an rtmp server and do something like what I tried to describe in #172

ghost commented 2 years ago

This is only lightly tested but I am able to stream desktop to html page with v4l2loopback. Here's what worked for me:

Assumptions:

  • apache or some way to serve a webpage
  • ffmpeg installed
  • v4l2loopback module installed
  • wf-recorder installed
  • the web server is running on the same machine running wayfire

Insert the following html: Head:

<link href="https://vjs.zencdn.net/7.2.3/video-js.css" rel="stylesheet">

Body:

<video id='video-stream' class="video-js vjs-default-skin center" width="640" height="480" controls>
        <source type="application/x-mpegURL" src="streams/desktop-stream1.m3u8">
</video>

Scripts:

<script src="https://vjs.zencdn.net/ie8/ie8-version/videojs-ie8.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.14.1/videojs-contrib-hls.js"></script>
<script src="https://vjs.zencdn.net/7.2.3/video.js"></script>
<script>
    var player = videojs('video-stream');
    player.play();
</script>

where 'streams/desktop-stream1.m3u8' is a path relative to the html file. Then, setup the video stream by running these commands:

sudo modprobe v4l2loopback exclusive_caps=1 card_label=desktop_view1 wf-recorder --muxer=v4l2 --codec=rawvideo --file=/dev/video2 -x yuv420p -t ffmpeg -i /dev/video2 -an /var/www/website/streams/desktop-stream1.m3u8

At this point, you should be able to refresh the page and play the video.

hi soreau, is there any latency in video playing ?

soreau commented 2 years ago

hi soreau, is there any latency in video playing ?

Yes, there is.

shymega commented 2 months ago

As an alternative, you could try to set up an rtmp server and do something like what I tried to describe in #172

@ammen99 This link is broken.

I'm looking to stream from Wayland to Nginx (RTMP),which then forwards onto Youtube, Twitch, and PeerTube. Are

Without a working link, I'm a bit stuck. Could you re-post the steps you took?

Cheers!

soreau commented 2 months ago

Hi, I recently got nginx rtmp + wf-recorder working, so I will outline the steps I took to use it:

1) Install nginx rtmp module and wf-recorder (suprise!) 2) Configure nginx rtmp and note the 'application' directive name. 3) Run wf-recorder with this command: wf-recorder -f rtmp://127.0.0.1/feed/wayfire 4) Test with ffplay rtmp://127.0.0.1/feed/wayfire

The trick for me was to make sure the application directive name matched the 'link' I was using. For example, if you have 'application live { ... }', then you must also use rtmp://127.0.0.1/live/your_stream_path. Example nginx rtmp config:

rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application feed {
                        live on;
                        record off;
                }
        }
}
soreau commented 2 months ago

I have taken the liberty of translating the instructions into the wiki.