Fixing an unmuxed image/jpeg stream from webcam using gstreamer
The problem you're having with muxing into avi is related to the fact that filesrc is providing buffers to avimux that are not properly aligned to the mjpeg frames, so avimux is creating samples with wrong alignment internally, making it harder for players to use them later during playback.
This can be fixed by using a mjpeg parser after the capsfilter (jpegparse?). Another option is to decode and reencode the samples to get them aligned and muxed properly. The following pipeline should work:
gst-launch-1.0 filesrc location=encode.mjpeg \
! 'image/jpeg,framerate=30/1,width=1280,height=720' ! decodebin ! videoconvert ! \
<some encoder> ! <some muxer> ! filesink location=outputfile
You can select the encoder and muxer you like, you can even encode them back to jpeg and mux into avi, as you wanted initially.
Edit: To attempt to mux the content into avi without decoding, try something like:
gst-launch-1.0 filesrc location=encode.mjpeg \
! 'image/jpeg,framerate=30/1,width=1280,height=720' ! jpegparse ! avimux \
! filesink location=encode.avi . -v
If jpegparse does it job very well, the ''image/jpeg,framerate=30/1,width=1280,height=720'' shouldn't be required.
nponeccop
Updated on September 18, 2022Comments
-
nponeccop almost 2 years
I made a broken footage using the following pipeline:
gst-launch-1.0 v4l2src ! filesink location=encode.mjpeg
Somehow gstreamer can still play it back:
gst-launch-1.0 filesrc location=encode.mjpeg ! jpegdec ! videoconvert ! xvimagesink
However as I by mistake didn't use any container, the stream is played back at a very fast pace
framerate=(fraction)0/1
. Is there any way to convert my broken file into an.avi
or any other container without recompression?The following trivial muxing didn't work as expected:
gst-launch-1.0 filesrc location=encode.mjpeg \ ! 'image/jpeg,framerate=30/1,width=1280,height=720' ! avimux \ ! filesink location=encode.avi . -v
Somehow gstreamer plays
encode.avi
back very slowly at ~1 FPS without consuming significant CPU. And neither Vlc` nor Adobe Aftereffects can import it - they only display a correctly decoded stipe of the first frame at the top. -
nponeccop almost 11 yearswithout recompression - recompressing with mjpeg apparently decreases quality as quantization settings are different in camera and in
jpegenc
. -
thiagoss almost 11 yearsIf remuxing without decompressing still doesn't work you can try looking at jpegenc quality property by doing: gst-inspect-1.0 jpegenc and setting it to a higher level to see if it improves your situation. In gst-launch you set properties after the element with: jpegenc quality=<somevalue>