GStreamer - MJPEG stream to file

19,500

Solution 1

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.

Solution 2

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
Share:
19,500
XMementoIT
Author by

XMementoIT

XMementoIT - Professional IT Services http://XMementoIT.com http://facebook.com/XMementoIT

Updated on June 05, 2022

Comments

  • XMementoIT
    XMementoIT about 2 years

    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.

  • av501
    av501 over 11 years
    good. Actually why do you decode and rencode. Why not simply feed to avimux directly from jpegparse?
  • Ahresse
    Ahresse almost 7 years
    It looks like mp4mux doesn't allow to record MJPEG in MP4 file container. [stackoverflow.com/questions/46276014/…
  • Climax
    Climax almost 6 years
    Yes it seems avi does support it though