ammen99 / wf-recorder

MIT License
863 stars 63 forks source link

Is it possible to pipe captured video to another program? #265

Closed Botspot closed 3 months ago

Botspot commented 4 months ago

This is not a direct need in my case, but it would be worth knowing about if there is a way. This fails.

$ mkfifo /tmp/wayland_pipe
$ wf-recorder -f /tmp/wayland_pipe -c rawvideo
Output file "/tmp/wayland_pipe" exists. Overwrite? Y/n: y
selected region 0,0 0x0
[NULL @ 0x7f88000d30] Unable to find a suitable output format for '/tmp/wayland_pipe'
Failed to allocate output context

This is because wf-recorder seems to need a file-extension, and it actually removes the pipe file first and replaces it with a normal file which takes up space on disk.

I also tried:

pi@raspberrypi:~ $ wf-recorder -f /tmp/wayland_pipe.mkv -c rawvideo
selected region 0,0 0x0
Using video filter: null
Output #0, matroska, to '/tmp/wayland_pipe.mkv':
  Stream #0:0: Video: rawvideo (RGB[0] / 0x424752), rgb0(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 49766400000 kb/s
[matroska @ 0x7f84000d30] Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or
If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)
Failed to write file header
Invalid argument
pi@raspberrypi:~ $ wf-recorder -f /tmp/wayland_pipe.avi -c rawvideo
selected region 0,0 0x0
Using video filter: null
Output #0, avi, to '/tmp/wayland_pipe.avi':
  Stream #0:0: Video: rawvideo (RGB[0] / 0x424752), rgb0(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 49766400000 kb/s
[avi @ 0x7f94000d30] rgb0 rawvideo cannot be written to avi, output file will be unreadable
^C[avi @ 0x7f94000d30] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2012 >= 0
pi@raspberrypi:~ $ wf-recorder -f /tmp/wayland_pipe.avi -c rawvideo -x brga
Output file "/tmp/wayland_pipe.avi" exists. Overwrite? Y/n: 
selected region 0,0 0x0
Using video filter: null
Output #0, avi, to '/tmp/wayland_pipe.avi':
  Stream #0:0: Video: rawvideo (RGB[0] / 0x424752), rgb0(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 49766400000 kb/s
[avi @ 0x7f9c000d30] rgb0 rawvideo cannot be written to avi, output file will be unreadable
^C[avi @ 0x7f9c000d30] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2165 >= 0
^Cpi@raspberrypi:~ $ wf-recorder -f /tmp/wayland_pipe.mp4 -c rawvideo -x brga
selected region 0,0 0x0
Using video filter: null
Output #0, mp4, to '/tmp/wayland_pipe.mp4':
  Stream #0:0: Video: rawvideo (RGB[0] / 0x424752), rgb0(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 49766400000 kb/s
[mp4 @ 0x7f74000d30] Could not find tag for codec rawvideo in stream #0, codec not currently supported in container
Failed to write file header
Invalid argument
pi@raspberrypi:~ $ wf-recorder -f /tmp/wayland_pipe.raw -c rawvideo -x brga
selected region 0,0 0x0
[NULL @ 0x7f74000d30] Unable to find a suitable output format for '/tmp/wayland_pipe.raw'
Failed to allocate output context

In addition to silly things like setting /dev/stdout and - as the output file which also did not work.

soreau commented 4 months ago

Not sure if this helps but, this will pipe the raw video data to stdout: wf-recorder -o DP-3 -m rawvideo -f /dev/stdout 2>/dev/null <<< 'Y' | $process

hashworks commented 3 months ago

It seems wf-recorder will always output some lines to stdout before the video output starts:

wf-recorder -o DP-3 -m rawvideo -f /dev/stdout <<< 'Y' 2>/dev/null | head -6
Output file "/dev/stdout" exists. Overwrite? Y/n: selected region 0,0 0x0
Setting codec option: crf=20
Setting codec option: preset=ultrafast
Setting codec option: tune=zerolatency
Using video filter: null
g>x@!Ph\,x264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=6 threads=16 lookahead_threads=16 sliced_threads=1 slices=16 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0e@;   _89o@4MAS_ ;3c3.ԟMYfq`  +pY

Of course one can skip them with tail -n +6 but I wasn't able to pipe this into ffmpeg either way.

soreau commented 3 months ago

I think it might be because you reversed the order of <<< 'Y' and 2>/dev/null.

hashworks commented 3 months ago

No, this does not matter.