[FFmpeg-user] Can MJPEG be live streamed without transcoding?

Adam Nielsen a.nielsen at shikadi.net
Sat Jan 8 08:54:07 EET 2022


Hi all,

I'm trying to stream video from a USB camera plugged into a Raspberry
Pi[1], however I can't work out how to stream the camera's MJPEG data
over a network without transcoding it first[2].

If I use a command like this:

  $ ffmpeg -f v4l2 -input_format mjpeg -video_size 1280x720
    -i /dev/video1 -c:v copy -f rtp_mpegts udp://[ff01:1::1]:5004

Then it streams the data, but with this warning:

  [mpegts @ 0x6725d0] Stream 0, codec mjpeg, is muxed as a private data
  stream and may not be recognized upon reading.

I am using ffmpeg to receive the data, however I can't work out how to
tell ffmpeg to read the private data stream and use it as MJPEG data:

  $ ffmpeg -c:v mjpeg -i udp://[ff01:1::1]:5004 -map 0:v ...
  Input #0, mpegts, from 'udp://[ff01:1::1]:5004':
    Duration: N/A, start: 509.858389, bitrate: N/A
    Program 1 
      Metadata:
        service_name    : Service01
        service_provider: FFmpeg
    Stream #0:0[0x100]: Data: bin_data ([6][0][0][0] / 0x0006)
  Output #0, rtp_mpegts, to 'udp://239.0.0.1:5004':
  Output file #0 does not contain any stream

If I try to use "-map 0:v" then it tells me "Stream map '0:v' matches
no streams."

I tried using "-f rtp" instead of "-f rtp_mpegts" and that also sends
the data but again, I can't work out how to tell ffmpeg to read it as
MJPEG on the receiving end.

How can I stream the MJPEG data via UDP from one ffmpeg instance to
another?  I don't want to use pipes for this, because I suspect those
will cause the same problem[2].

Many thanks,
Adam.

[1] I am also streaming from the built in camera, but I need a second
video stream which the USB camera is for.

[2] The reason for asking is that I have discovered that the USB camera
sometimes does not return frames, which causes ffmpeg to freeze,
waiting for a frame that never arrives.  Ultimately I am using the
Raspberry Pi's hardware H264 encoder to transcode the MJPEG stream into
H264, but when ffmpeg freezes, it causes all hardware encoding on the
Pi to stop, and sometimes even causes the Pi to completely lock up
requiring a power cycle to recover from.  So to avoid this I am
thinking that if I stream the MJPEG data across the network (on
localhost) then have a second ffmpeg doing the H264 V4L2 M2M encoding,
if the first MJPEG one drops out it hopefully won't cause the second
H264 one to freeze and break the Pi.


More information about the ffmpeg-user mailing list