Multi-Camera in WebRTC application with Gstreamer C++ - c++

In my pipeline I would like to use 2 different v4l2 source. But When I used like code 1 with double v4l2src , I can get some error like "ERROR GST_PIPELINE grammar.y:740:gst_parse_perform_link: could not link h264parse1 to payloader"
pipe1 =
gst_parse_launch ("webrtcbin name=sendrecv stun-server=stun://" STUN_SERVER " "
"v4l2src device=/dev/video0 "
"! videorate "
"! video/x-raw,width=640,height=360,framerate=15/1 "
"! videoconvert "
"! queue max-size-buffers=1 "
"! x264enc bitrate=600 speed-preset=ultrafast tune=zerolatency key-int-max=15 "
"! video/x-h264,profile=constrained-baseline "
"! queue max-size-time=100000000 ! h264parse "
"! rtph264pay config-interval=-1 name=payloader "
"! sendrecv. ", &error);
I can also use directly gstreamer multi camera run codes, And I can recorded videos from 2 different camera.
gst-launch-1.0 -e v4l2src device=/dev/video0 ! videoconvert! videoscale ! 'video/x-raw, width=(int)640, height=(int)480' ! tee name=c c. ! queue ! omxvp8enc bitrate=1500000 ! rtpvp8pay ! udpsink bind-port=8574 host=192.168.1.110 port=8574 loop=false c. ! queue ! omxh264enc bitrate=1500000 ! mp4mux ! queue ! filesink location=test-RightFacingCamera.mp4 v4l2src device=/dev/video1 ! videoconvert! videoscale ! 'video/x-raw, width=(int)640, height=(int)480' ! tee name=b b. ! queue ! omxvp8enc bitrate=1500000 ! rtpvp8pay ! udpsink bind-port=8564 host=192.168.1.110 port=8564 loop=false b. ! queue ! omxh264enc bitrate=1500000 ! mp4mux ! queue ! filesink location=test-LeftFacingCamera.mp4
But I couldn't fix my pipeline directly for my WebRTC project, I have to add one more v4l2src , Can you help me about it?

Related

Gstreamer multiudpsink broadcast over all subnets

Below is my actual pipeline for sender and reciever. I would like to stream over all subnets (from 192.168.1.1 to 192.168.1.255. I would like that the receiver can decode the stream whatever is ip is : 192.168.1.10 or 192.168.1.235 or...
How do I have to use multiudpsink to do that?
SENDER
appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw, format=BGRx ! nvvidconv ! omxh264enc ! video/x-h264, stream-format=byte-stream ! h264parse ! rtph264pay pt=96 config-interval=1 ! udpsink host=192.168.1.2 port=5200 sync=false
RECIEVER
udpsrc ! rtpjitterbuffer mode=0 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert !d3dvideosink sync=false

Recording multiple RTSP streams h265 format to Kinesis Video Streams using Gstreamer and Kvssink

I need to record 4 RTSP streams into a single stream of the Kinesis Video Streams.
Streams must be placed in the video like this:
---------- ----------
| | |
| STREAM 1 | STREAM 2 |
| | |
|----------|----------|
| | |
| STREAM 3 | STREAM 4 |
| | |
---------- ----------
I was able to insert a single stream and make it work perfectly, using the command below:
gst-launch-1.0 rtspsrc user-id="admin" user-pw="password" location="rtsp://admin:password#192.168.0.1:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! kvssink stream-name="test-stream" storage-size=512 access-key="access-key" secret-key="secret-key" aws-region="us-east-1"
However, my goal is to insert an array of streams into the same stream in the Kinesis Video Streams.
For this I found the example with videomixer that's below:
gst-launch-1.0 -e rtspsrc location=rtsp_url1 ! rtph264depay ! h264parse ! decodebin ! videoconvert! m.sink_0 \
rtspsrc location=rtsp_url2 ! rtph264depay ! h264parse ! decodebin ! videoconvert! m.sink_1 \
rtspsrc location=rtsp_url3 ! rtph264depay ! h264parse ! decodebin ! videoconvert! m.sink_2 \
rtspsrc location=rtsp_url4 ! rtph264depay ! h264parse ! decodebin ! videoconvert! m.sink_3 \
videomixer name=m sink_1::xpos=1280 sink_2::ypos=720 sink_3::xpos=1280 sink_3::ypos=720 ! x264enc ! mp4mux ! filesink location=./out.mp4 sync=true
I adapted the example to just two streams and made it work inside the container, using a command like the one below:
gst-launch-1.0 -e rtspsrc user-id="admin" user-pw="password" location="rtsp://password#192.168.0.1:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! m.sink_0 \
rtspsrc user-id="admin" user-pw="password" location="rtsp://password#192.168.0.2:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! m.sink_1 \
videomixer name=m sink_0::xpos=1080 sink_1::ypos=1080 ! x265enc ! h265parse ! video/x-h265, alignment=au ! kvssink stream-name="test-stream" storage-size=512 access-key="access-key" secret-key="secret-key" aws-region="us-east-1"
And in another way:
gst-launch-1.0 -e videomixer name=mix sink_0::xpos=0 sink_0::ypos=0 sink_0::alpha=0 sink_1::xpos=0 sink_1::ypos=0 \
rtspsrc user-id="admin" user-pw="password" location="rtsp://password#192.168.0.1:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! videoscale ! video/x-raw,width=1920,height=1080 ! mix.sink_0 \
rtspsrc user-id="admin" user-pw="password" location="rtsp://password#192.168.0.2:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! videoscale ! video/x-raw,width=1920,height=1080 ! mix.sink_1 \
mix. ! queue ! videoconvert ! x265enc ! queue ! kvssink stream-name="test-stream" storage-size=512 access-key="access-key" secret-key="secret-key" aws-region="us-east-1"
The container in question is from: https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp
However, when I log into Kinesis Video Streams and try to download a getClip, in both cases I get this error:
MissingCodecPrivateDataException
Missing codec private data in fragment for track 1.
Status code: 400
The logs with GST_DEBUG=1 can be found at https://gist.github.com/vbbandeira/b15ec8af6986237a4cd7e382e4ede261
And the logs with GST_DEBUG=4 can be found at https://gist.github.com/vbbandeira/6bd4b7a014a69da5f46cd036eaf32aec
Can you guys please let me know what is going on there?
Or if possible, help me find the solution to this error.
Thanks!
for those looking for the same solution, I managed to make it work by replacing the videomixer which is deprecated by the composer, below is an example of the command I used and it worked:
gst-launch-1.0 rtspsrc location="rtsp://password#192.168.0.1:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! decodebin ! videoconvert ! comp.sink_0 \
rtspsrc location="rtsp://password#192.168.0.2:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! decodebin ! videoconvert ! comp.sink_1 \
compositor name=comp sink_0::xpos=0 sink_1::xpos=1280 ! x264enc ! kvssink stream-name="test-stream" storage-size=512 access-key="access-key" secret-key="secret-key" aws-region="us-east-1"
However, I was only able to do this using h264.

Working example of rtpvrawpay in GStreamer

Can someone paste a working pair of gst-launch pipelines that use rtpvrawpay and rtpvrawdepay?
Here's my first stab at it:
gst-launch-1.0 videotestsrc ! videoconvert ! video/x-raw,width=128,height=128,format=BGR ! rtpvrawpay ! application/x-rtp,payload=96 ! udpsink host=... port=...
gst-launch-1.0 udpsrc port=9999 ! application/x-rtp,media=video,payload=96,clock-rate=90000,encoding-name=RAW,sampling=BGR,depth=16 ! rtpvrawdepay ! video/x-raw,width=128,height=128,format=BGR,framerate=30/1 ! videoconvert ! ximagesink
Pay: gst-launch-1.0 -v videotestsrc ! rtpvrawpay ! udpsink host="127.0.0.1" port="5000"
Depay: gst-launch-1.0 udpsrc port="5000" caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:0, depth=(string)8, width=(string)320, height=(string)240, colorimetry=(string)BT601-5, payload=(int)96, ssrc=(uint)1103043224, timestamp-offset=(uint)1948293153, seqnum-offset=(uint)27904" ! rtpvrawdepay ! videoconvert ! queue ! xvimagesink sync=false
Check the caps on your pipeline again.

interleaving 4 channels of audio into vorbisenc or opusenc in gstreamer

I’m trying to interleave 4 channels of audio into one audio file
I have managed to successfully save them into wav with wavenc
gst-launch-1.0 interleave name=i filesrc location=FourMICS_RR_long.wav !
decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE ! queue ! i.sink_0
filesrc location=FourMICS_CR_long.wav ! decodebin ! audioconvert !
audio/x-raw,format=(string)F32LE ! queue ! i.sink_1
filesrc location=FourMICS_CL_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE ! queue ! i.sink_2
filesrc location=FourMICS_LL_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE ! queue ! i.sink_3
i.src ! queue ! audio/x-raw,rate=48000,channels=4,format=F32LE,layout=interleaved ! queue !
wavenc ! queue ! filesink location=out2.wav
but when I save it as vorbisenc oggmux
gst-launch-1.0 interleave name=i filesrc location=FourMICS_RR_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE ! queue ! i.sink_0
filesrc location=FourMICS_CR_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE ! queue ! i.sink_1
filesrc location=FourMICS_CL_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE ! queue ! i.sink_2
filesrc location=FourMICS_LL_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE ! queue ! i.sink_3
i.src ! queue ! audio/x-raw,rate=48000,channels=4,format=F32LE,layout=interleaved ! queue !
wavenc ! queue ! wavparse ! audioconvert ! audio/x-raw,rate=48000,channels=4,format=F32LE,layout=interleaved !
vorbisenc ! oggmux ! filesink location=out2.ogg
the channels get completely messed up when I play the file, or look at it in audacity.
I have also tried using
channel-positions=GST_AUDIO_CHANNEL_POSITION_REAR_LEFT
channel-mask=(bitmask)0x4
for each channel like this>
gst-launch-1.0 interleave name=i filesrc location=FourMICS_RR_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE,channel-position=GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,channel-mask=(bitmask)0x1 ! queue ! i.
filesrc location=FourMICS_CR_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE,channels=(int)1,channel-position=GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,channel-mask=(bitmask)0x2 ! queue ! i.
filesrc location=FourMICS_CL_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE,channels=(int)1,channel-position=GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,channel-mask=(bitmask)0x3 ! queue ! i.
filesrc location=FourMICS_LL_long.wav ! decodebin ! audioconvert ! audio/x-raw,format=(string)F32LE,channels=(int)1,channel-position=GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,channel-mask=(bitmask)0x4 ! queue ! i.
i.src ! queue ! audio/x-raw,rate=48000,channels=4,format=F32LE,layout=interleaved ! queue !
wavenc ! queue ! wavparse ! audioconvert ! audio/x-raw,rate=48000,channels=4,format=F32LE,layout=interleaved !
vorbisenc ! oggmux ! filesink location=out2.ogg
Same problem
Any suggestion as of how to solve this?
I am not restricted only to vorbis, in fact I have similar issues also with opusenc.
Thanks.
Mar
So. I got it working,
gst-launch-1.0 interleave name=i filesrc location=FourMICS_RR_long.wav ! decodebin ! audioconvert ! audioresample ! audio/x-raw,rate=24000,format=F32LE ! queue ! i.sink_0
filesrc location=FourMICS_CR_long.wav ! decodebin ! audioconvert ! audioresample ! audio/x-raw,channels=(int)1,rate=24000,format=F32LE ! queue ! i.sink_1
filesrc location=FourMICS_CL_long.wav ! decodebin ! audioconvert ! audioresample ! audio/x-raw,channels=(int)1,rate=24000,format=F32LE ! queue ! i.sink_2
filesrc location=FourMICS_LL_long.wav ! decodebin ! audioconvert ! audioresample ! audio/x-raw,channels=(int)1,rate=24000,format=F32LE ! queue ! i.sink_3
i.src ! capssetter caps=audio/x-raw,channels=4,channel-mask=(bitmask)0x33 ! audioconvert ! audioresample ! vorbisenc ! oggmux ! filesink location=out2.ogg
There were two issues
1. that the caps need to be set to the interleave
2. vorbisenc bitrate could not bare with 4 channels at 48khz

gstreamer add textoverlay in c++

I am trying to add a textoverlay to an mp4 movie with gstreamer-0.10. Yes I know its old but I only need to do few changes to the mp4. I know how to do it with gst-launch-0.10:
gst-launch-0.10 filesrc location=input.mp4 name=src ! decodebin
name=demuxer demuxer. ! queue ! textoverlay text="My Text" ! x264enc !
muxer. demuxer. ! queue ! audioconvert ! voaacenc ! muxer. mp4mux
name=muxer ! filesink location=output.mp4
This creates a text overlay movie for me. But now I need to add the textoverlay in the following bin in cpp - this is my working pipeline creating an mp4:
QGst::BinPtr m_encBin = QGst::Bin::fromDescription(
"filesrc location=\""+path+"videoname.raw.mkv\" ! queue ! matroskademux name=\"demux\" "
"demux.video_00 ! queue ! ffmpegcolorspace ! queue ! x264enc ! queue ! mux.video_00 "
"demux.audio_00 ! queue ! audioconvert ! queue ! faac ! queue ! mux.audio_00 "
"mp4mux name=\"mux\" ! queue ! filesink name=\"filesink\" sync=false ",
QGst::Bin::NoGhost);
Anyone knows how I can add the textoverlay into the bin?
Cheers Fredrik
I think you should add queue and textoverlay elements to your pipeline description between ffmpegcolorspace and queue elements:
QGst::BinPtr m_encBin = QGst::Bin::fromDescription(
"filesrc location=\""+path+"videoname.raw.mkv\" ! queue ! matroskademux name=\"demux\" "
"demux.video_00 ! queue ! ffmpegcolorspace ! queue ! textoverlay text=\"My Text\" ! queue ! x264enc ! queue ! mux.video_00 "
"demux.audio_00 ! queue ! audioconvert ! queue ! faac ! queue ! mux.audio_00 "
"mp4mux name=\"mux\" ! queue ! filesink name=\"filesink\" sync=false ",
QGst::Bin::NoGhost);
I think you received downvote because you didn't try to understand GStreamer pipelines description and asked for ready-to-use solution.