Error while streaming MJPEG video with RTSP protocol - c++

I want to stream a MJPEG video from my ethernet camera with OpenCV and Gstreamer.
I have tried to open the stream with the following gstreamer pipeline:
std::string pipe(
"rtspsrc location=rtsp://192.168.1.219:554/video.pro1 ! application/x-rtp,encoding-name=JPEG,payload=26 ! "
"rtpjpegdepay ! jpegdec ! xvimagesink sync=false ! appsink"
);
cv::VideoCapture cap(pipe, cv::CAP_GSTREAMER);
but the previous code returns me the following error:
OpenCV Error: Unspecified error (GStreamer: cannot find appsink in manual pipeline
) in cvCaptureFromCAM_GStreamer, file /home/nvidia/Documents/CameraTests/src/opencv-3.3.0/modules/videoio/src/cap_gstreamer.cpp, line 796
VIDEOIO(cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename)): raised OpenCV exception:
/home/nvidia/Documents/CameraTests/src/opencv-3.3.0/modules/videoio/src/cap_gstreamer.cpp:796: error: (-2) GStreamer: cannot find appsink in manual pipeline
in function cvCaptureFromCAM_GStreamer
I managed to stream the the same RTSP source with H264 and H265 algorithms,
MJPEG is the only format that doesn't work, then I suppose that is a gstreamer pipeline problem..
thanks

Related

Gstreamer pipeline to convert MPEG-4 video to MPEG-TS format

I am trying to write gstreamer pipeline to convert mpeg4 video to mpegts format.
I tried below pipeline but no luck
$ gst-launch-1.0 -e filesrc location=20200818125158_00001.ts.mp4 ! qtdemux name=mdemux ! \
h264parse ! video/x-h264,stream-format=byte-stream ! mpegtsmux name=mux ! filesink location=20200818125158_00001.ts
I get below error when I execute above pipeline
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstQTDemux:mdemux: Delayed linking failed.
Additional debug info:
./grammar.y(510): gst_parse_no_more_pads (): /GstPipeline:pipeline0/GstQTDemux:mdemux:
failed delayed linking some pad of GstQTDemux named mdem
My Input format
gst-discoverer-1.0 vid.mp4
Analyzing file:///vid.mp4
Done discovering file:///vid.mp4
Topology:
container: Quicktime
video: MPEG-4 Video (Simple Profile)
Properties:
Duration: 0:00:07.267000000
Seekable: yes
Live: no
Tags:
video codec: MPEG-4 video
maximum bitrate: 8400000
bitrate: 298925
encoder: Lavf57.83.100
container format: ISO MP4/M4A
My target format
Topology:
container: MPEG-2 Transport Stream
video: H.264 (High Profile)
Properties:
Duration: 0:00:09.900164000
Seekable: yes
Live: no
Tags:
video codec: H.264
video codec: MPEG-4 video
Your video codec in the source file is MPEG-4 Video. That is different from H.264. Try mpegvideoparse instead of h264parse.
Als video/x-h264,stream-format=byte-stream caps forcing should not be required. The parser and muxer should agree on caps by themselves.
After spending multiple hours and reading more about gstreamer I figured out correct pipeline. Below pipeline works for me
gst-launch-1.0 filesrc location=vid.mp4 ! qtdemux ! avdec_mpeg4 ! X264enc ! mpegtsmux ! filesink location=vid.ts

Use gstreamer to take rtsp input and output rtmp

I'm trying to use gstreamer to go from h264 rtsp input to rtmp output to youtube without re-encoding. in ffmpeg I can simply do a codec copy, but in gstreamer, I can't my pipeline to work:
gst-launch-1.0 -e -v rtspsrc location="rtsp://rtsp/input" protocols=tcp latency=0 ! rtph264depay ! h264parse ! flvmux streamable=true ! rtmpsink sync=true async=true location='rtmp://a.rtmp.youtube.com/live2/key live=true'
I have a feeling it has to do with the audio. I'm receiving aac audio from the rtsp feed but can't figure out how to parse it into the rtmp output.

RTSP stream not understood by VLC: this bitstream does not contain Vorbis audio data

I have an audio-only RTSP stream, I can play this stream with the following pipeline:
gst-launch-1.0 rtspsrc location="rtsp://127.0.0.1:8554/test" ! rtpvorbisdepay ! decodebin ! autoaudiosink
However, when I try to open it with VLC this way:
vlc rtsp://127.0.0.1:8554/test
It doesn't play any sound (although it does identify the length of the stream and "plays") and it outputs the following to the console:
[00007f9ebc04fa80] vorbis decoder error: this bitstream does not contain Vorbis audio data
[00007f9ebc04fa80] vorbis decoder error: this bitstream does not contain Vorbis audio data
[00007f9ebc04fa80] vorbis decoder error: this bitstream does not contain Vorbis audio data
...etc
Pipeline used to play the stream:
str = g_strdup_printf ("( "
"filesrc location=%s ! oggdemux "
"! rtpvorbispay name=pay0 pt=96 " ")", argv[1]);
Help?

Compress H264 Stream Using Gstreamer

I am trying to create a GStreamer pipeline (v 1.0) in order to record and play special file format.
For recording purpose I use the following pipeline:
gst-launch-1.0 videotestsrc ! video/x-raw-yuv, format=\(fourcc\)I420, width=640, height=480 ! videoconvert ! x264enc byte-stream=1 ! queue ! appsink
In appsink (using new_sample() callback) I use a compression method to compress H264 stream and finally store in a output file.
I use the following pipeline to play the recorded file:
gst-launch-1.0 appsrc ! video/x-h264 ! avdec_h264 ! autovideosink
In appsrc I decompress H264 stream and send it to appsrc buffer (using push-buffer). The size of each buffer is 4095.
Unfortunately GStreamer after push 2 buffers print the following debug message:
Error: Internal data flow error.
Is there any way to fix the problem?
Add legacyh264parse or h264parse (depending on your version of gst components) before your decoder. You need to be able to send full frames to the decoder.
Post avdec_h264 it would be nice to have a ffmpegcolorspace to be able to convert the video format to your display requirements.

Using gst-launch to streaming video?

I want to stream a media file (video or audio). I used command:
gst-launch-0.10 filesrc location="/home/ms/GStreamerTest/test.ogg" ! vorbisenc \
! rtpvorbispay pt=96 ! udpsink host=127.0.0.1 port=5000
to stream the file test.ogg, but, I got an error:
"ERROR: from element /GstPipeline:pipeline0/GstVorbisEnc:vorbisenc0: Internal GStreamer error: negotiation problem. Please file a bug at http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer.
Additional debug info:
gstvorbisenc.c(1227): gst_vorbis_enc_chain (): /GstPipeline:pipeline0/GstVorbisEnc:vorbisenc0:
encoder not initialized (input is not audio?)
ERROR: pipeline doesn't want to preroll.
Please help me solve this problem, thanks.
You plugged an encoded and muxed bitstream into an audio encoder. That cannot possibly work.
In your case filesrc ! udpsink would send your file across the network and on the other side you have to receive it udpsrc, demux it oggdemux, decode it theoradec or vorbisdec, and pipe it into a sink autovideosink or autoaudiosink