How can I stream mjpeg file as rtsp

2019-08-17 19:23发布

问题:

We have an mjpeg video, obtained from the webcam and stored into *.avi file, still encoded as mjpeg.

We need to restream this file as rtsp (and stil preserve the mjpeg there, i.e. no decoding). The goal is to emulate the webcam this video was obtained from for the software that processes the video. The file can be open with vlc/ffplay with no problems. The ffmpeg behaves like it is streaming it, however, ffplay/vlc can't open this stream.

We tried to stream if with gstreamer.

1) we fount no free rtsp sink element for gstreamer pipeline. So, is there a free analogue for rtspsink to launch this pipeline with gst-launch? we need and only cast, so we don't need so advanced element as rtspsink is.

2) we also tried to build own simple rtsp server as described in http://weeklybuild.com/2013/01/creating-an-rtsp-stream-with-gstreamer/

replacing videotestsrc with filesrc; but what kind of elements we should use there? usage of an only filesrc doesn't help; we get the same problem as if we stream with ffmpeg. But what kind of lements we need there, if we dont' wan to decode/encode it, just to stream the file (to reproduce the thing what the webcam actually does).

 $ ffplay rtsp://127.0.0.1:8554/test -loglevel debug
 avplay version 0.8.5-6:0.8.5-1, Copyright (c) 2003-2012 the Libav developers
 built on Jan 13 2013 12:05:48 with gcc 4.7.2
 configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.5-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
 avutil      configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.4-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
 avcodec     configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.4-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
 avformat    configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.4-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
 swscale     configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.4-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
postproc    configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.4-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-            postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
libavutil    51. 22. 1 / 51. 22. 1
libavcodec   53. 35. 0 / 53. 35. 0
libavformat  53. 21. 1 / 53. 21. 0
libavdevice  53.  2. 0 / 53.  2. 0
libavfilter   2. 15. 0 /  2. 15. 0
libswscale    2.  1. 0 /  2.  1. 0
libpostproc  52.  0. 0 / 52.  0. 0
[rtsp @ 0x7f558c0008c0] method DESCRIBE failed: 503 Service Unavailable
[rtsp @ 0x7f558c0008c0] CSeq: 2
 Server: GStreamer RTSP server
 Date: Thu, 22 Aug 2013 07:49:30 GMT

 rtsp://127.0.0.1:8554/test: Invalid data found when processing input

And everything is okay when I try gstreamer server built as in example, i.e. using videotestsrc

回答1:

Using only a filesrc element doesn't work because it doesn't provide appropriate caps which desribe the contents of the buffers it generates. The actual elements you need to use depend on the container and codec. If e.g. the container is avi and the video codec is mjpeg, you would need such a pipeline:

filesrc location=video.avi ! avidemux ! jpegdec ! x264enc ! rtph264pay name=pay0 pt=96

There is also a universal element decodebin2, which detects the container and the codec automatically:

filesrc location=video.avi ! decodebin2 ! x264enc ! rtph264pay name=pay0 pt=96