How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

About encoding, codec settings, muxers and filter usage
masasin
New Cone
New Cone
Posts: 5
Joined: 12 Jun 2019 14:59

How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby masasin » 12 Jun 2019 15:08

Hello! I'm trying to stream images from OpenCV to RTSP. The solution I'm working on right now creates the frames, then writes them to a fifo. VLC reads from the fifo, converts it from rawvid, and streams using `sout`. Here's the command:

Code: Select all

cvlc --demux=rawvid --rawvid-width={width:.0f} --rawvid-height={height:.0f} --rawvid-fps={fps:.1f} --rawvid-chroma=RV24 {path_in} --sout-keep --no-sout-all --sout {output!r}
When `output` is `#display`, it works and I can see it. However, if I'm trying to stream to RTSP, nothing appears on the other end.

Playing video files, as well as RTSP streams, allows me to stream to RTSP without a target. But going through OpenCV forces rawvideo. I tried different transcoding strings, but none of them worked. Some examples:

No video transcoding:

Code: Select all

[00007f350c000e80] main stream output error: stream chain failed for `transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:#display' [00007f3514000c40] main input error: cannot start stream output instance, aborting
With video transcoding:

Code: Select all

[00007f149c000e60] main stream output error: stream chain failed for `transcode{vcodec=h264,width=640,height=480,fps=30,vcodec=rawvideo}:#display' [00007f14a4000c40] main input error: cannot start stream output instance, aborting
Does anyone have any suggestions?

Also, I tried using `python-vlc` instead of using `subprocess`, but I wasn't sure where to start. [url=https://www.olivieraubert.net/vlc/python-ctypes/doc/]The API[/url] is huge. Does anyone have resources or examples, I might be able to use it more effectively.

Thanks!

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby unidan » 12 Jun 2019 15:13

Hi,

not sure what you're doing, having the complete command line each time without needing mental replacement would help if you can :)

masasin
New Cone
New Cone
Posts: 5
Joined: 12 Jun 2019 14:59

Re: How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby masasin » 12 Jun 2019 16:43

Hi,

not sure what you're doing, having the complete command line each time without needing mental replacement would help if you can :)

Code: Select all

cvlc --demux=rawvid --rawvid-width=640 --rawvid-height=480 --rawvid-fps=30.0 --rawvid-chroma=RV24 /tmp/tmplba4v8_r/40e68bf2-1876-4856-a195-0e2c925f095a.fifo --sout-keep --no-sout-all --sout '#display'
This is called from Python with subprocess:

Code: Select all

with subprocess.Popen(vlc_command, shell=True),\ open(fifo_path, 'wb') as vlc_input: for frame in reader: vlc_input.write(frame.tobytes())
edit: When I tried with transcoding, I have the section in the error after `--sout`. (i.e., transcode and send to `#display`.) When sending to RTSP, I use `#rtp{sdp=rtsp://:8554/}` as the destination instead of `#display`.

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby unidan » 12 Jun 2019 16:50

Hi, try with

#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:display

instead of

transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:#display

masasin
New Cone
New Cone
Posts: 5
Joined: 12 Jun 2019 14:59

Re: How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby masasin » 12 Jun 2019 17:18

Hi, try with

#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:display

instead of

transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:#display

Code: Select all

cvlc --demux=rawvid --rawvid-width=640 --rawvid-height=480 --rawvid-fps=30.0 --rawvid-chroma=RV24 /tmp/tmpu3fbzug7/0f4c5f64-c6bf-494f-91a2-a0bcb7e6f700.fifo --sout-keep --no-sout-all --sout '#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:display'
It sent what looked like a single frame, but then stopped.

Output without `-vvv`:

Code: Select all

VLC media player 3.0.4 Vetinari (revision 3.0.4-0-gf615db6332) [000055ee7bb99a10] dummy interface: using the dummy interface module... [00007f2848009d30] x264 encoder: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [00007f2848009d30] x264 encoder: profile High, level 3.0 [00007f2848009d30] x264 encoder: using SAR=1/1 [00007f2848009d30] x264 encoder: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [00007f2848009d30] x264 encoder: profile High, level 3.0 [00007f2850000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 300 ms) [00007f2850000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 305 ms) [00007f28241eff10] avcodec decoder: Using NVIDIA VDPAU Driver Shared Library 410.104 Tue Feb 5 22:55:15 CST 2019 for hardware decoding [h264 @ 0x7f28491fc120] co located POCs unavailable [h264 @ 0x7f28495bd1e0] mmco: unref short failure [00007f2850000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 307 ms) [h264 @ 0x7f28495d9500] co located POCs unavailable [h264 @ 0x7f28495f5820] mmco: unref short failure [h264 @ 0x7f28491b4120] co located POCs unavailable [00007f2850000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 318 ms) [00007f2850000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 321 ms) [00007f28241eff10] avcodec decoder error: more than 5 seconds of late video -> dropping frame (computer too slow ?) ... [00007f28241eff10] avcodec decoder error: more than 5 seconds of late video -> dropping frame (computer too slow ?) [h264 @ 0x7f28495f5820] co located POCs unavailable [h264 @ 0x7f28491a4cc0] mmco: unref short failure [h264 @ 0x7f28491b4120] co located POCs unavailable [00007f2850000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 329 ms) [h264 @ 0x7f28495f5820] co located POCs unavailable [h264 @ 0x7f28495d9500] co located POCs unavailable [h264 @ 0x7f28495f5820] mmco: unref short failure [00007f2850000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 330 ms) [h264 @ 0x7f28491b4120] co located POCs unavailable [00007f2848009d30] x264 encoder: frame I:1 Avg QP:23.30 size: 8448 [00007f2848009d30] x264 encoder: frame P:57 Avg QP:23.90 size: 2771 [00007f2848009d30] x264 encoder: frame B:166 Avg QP:25.20 size: 627 [00007f2848009d30] x264 encoder: consecutive B-frames: 0.9% 0.9% 0.0% 98.2% [00007f2848009d30] x264 encoder: mb I I16..4: 15.8% 70.1% 14.1% [00007f2848009d30] x264 encoder: mb P I16..4: 0.7% 1.9% 0.2% P16..4: 35.4% 7.8% 6.4% 0.0% 0.0% skip:47.7% [00007f2848009d30] x264 encoder: mb B I16..4: 0.1% 0.2% 0.0% B16..8: 33.6% 0.0% 0.0% direct: 0.2% skip:65.9% L0:42.6% L1:56.8% BI: 0.6% [00007f2848009d30] x264 encoder: 8x8 transform intra:69.4% inter:81.9% [00007f2848009d30] x264 encoder: coded y,uvDC,uvAC intra: 45.1% 0.0% 0.0% inter: 6.5% 0.0% 0.0% [00007f2848009d30] x264 encoder: i16 v,h,dc,p: 10% 18% 6% 66% [00007f2848009d30] x264 encoder: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 15% 22% 7% 7% 7% 8% 8% 6% [00007f2848009d30] x264 encoder: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 16% 16% 9% 8% 9% 8% 6% 4% [00007f2848009d30] x264 encoder: i8c dc,h,v,p: 100% 0% 0% 0% [00007f2848009d30] x264 encoder: Weighted P-Frames: Y:1.8% UV:0.0% [00007f2848009d30] x264 encoder: ref P L0: 59.2% 10.9% 22.6% 7.4% [00007f2848009d30] x264 encoder: ref B L0: 86.5% 11.0% 2.6% [00007f2848009d30] x264 encoder: ref B L1: 95.1% 4.9% [00007f2848009d30] x264 encoder: kb/s:289.73

masasin
New Cone
New Cone
Posts: 5
Joined: 12 Jun 2019 14:59

Re: How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby masasin » 13 Jun 2019 11:19

Hi, try with

#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:display

instead of

transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:#display
Thank you! This worked for streaming to the remote server, but not display. Display is only for debugging, so that's fine. I can remove transcoding if sending to display.

masasin
New Cone
New Cone
Posts: 5
Joined: 12 Jun 2019 14:59

Re: How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby masasin » 13 Jun 2019 13:12

Question: Streaming a video with more than one colour channel generates:

Code: Select all

[00005654c9a6a5f0] dummy interface: using the dummy interface module... [00007fa3fc000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 300 ms) [00007fa3fc000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 322 ms) [00007fa3fc000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 361 ms) [00007fa3fc000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 409 ms) [00007fa3fc000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 414 ms) [00007fa3fc000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 426 ms) [00007fa3fc000c40] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 481 ms)
It still streams, but it's choppy. I get these even when scaling down to 640x360, and reducing the framerate to 3 fps. (There's also a large (5-ish second) delay, but that's not that important for this application.)

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: How to stream rawvideo via RTSP? (Or, how to transcode rawvideo to H264?)

Postby unidan » 13 Jun 2019 14:22

Do you have a reproductible environment for us so we can test your usecase ?


Return to “VLC stream-output (sout)”

Who is online

Users browsing this forum: No registered users and 30 guests