5

I have problem with saving MJPEG stream to file. When I stream MJPEG using such pipeline:

gst-launch filesrc location=thirdmovie640x360.mp4 ! decodebin2 name=dec \
    ! queue ! ffmpegcolorspace ! jpegenc ! queue ! avimux name=mux \
    ! udpsink host=192.168.0.2 port=5000

I am able to play this stream on my second machine using such pipeline:

gst-launch -v udpsrc port=5000 ! jpegdec ! autovideosink

However, how can I save such MJPEG stream to file (without transcoding!) which will be able to be played in some media player? Could you recommend some pipeline?


I found such pipeline to save output stream as matroska file:

gst-launch udpsrc port=5000 ! multipartdemux ! jpegparse ! jpegdec \
    ! ffmpegcolorspace ! matroskamux ! filesink location=output.mkv

How to change it to save mp4 file? Such pipeline:

gst-launch udpsrc port=5000 ! multipartdemux ! jpegparse ! jpegdec \
    ! ffmpegcolorspace ! mp4mux ! filesink location=output.mp4

does not work. Could you help me save it as mp4 contener (or avi contener) without transcoding MJPEG video.

Ahresse
  • 497
  • 4
  • 17
XMementoIT
  • 123
  • 1
  • 1
  • 7

2 Answers2

6

I solved my problem. Here are piplines which I was looking for:

Server

gst-launch filesrc location=thirdmovie640x360.mp4 ! decodebin2 name=dec
! queue ! ffmpegcolorspace ! jpegenc ! queue ! multipartmux
! udpsink host=192.168.0.4 port=5000

Client

gst-launch udpsrc port=5000 ! multipartdemux ! image/jpeg, framerate=25/1 
! jpegparse ! jpegdec ! ffmpegcolorspace ! jpegenc
! avimux ! filesink location=output.avi
Delgan
  • 18,571
  • 11
  • 90
  • 141
XMementoIT
  • 123
  • 1
  • 1
  • 7
  • 6
    good. Actually why do you decode and rencode. Why not simply feed to avimux directly from jpegparse? – av501 Oct 04 '12 at 11:44
0

MJPEG is a codec which in simple terms means that there are is a series of jpeg images. These jpegs have to be stored in a container if you want to view them as a video. MP4 is a common container to store them in.

So you can mux the jpegenc output back to a mp4mux and store it in a file. Any decent media player should be able to play it back.

av501
  • 6,645
  • 2
  • 23
  • 34
  • 1
    It looks like `mp4mux` doesn't allow to record MJPEG in MP4 file container. [https://stackoverflow.com/questions/46276014/how-to-record-image-jpeg-mjpeg-within-mp4-container-with-gstreamer] – Ahresse Sep 20 '17 at 08:54
  • Yes it seems avi does support it though – Climax Aug 17 '18 at 11:17