This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM5728: lossless encoding video stream via gstreamer

Part Number: AM5728

Tool/software: Linux

I'm trying to compress video stream from camera module via gstreamer-1.0 on am5728 evm.
I found that ducati codecs, provided with sitara linux sdk is lossy, but I need in lossless video codes. As I know mjpeg is that I need
I write small program on gstreamer, that encodes stream via avenc_mjpeg and save it as avi file. But there is two problems:

1. Saved video is faster, than real situation, recording on the camera module.
2. I've checked output avi file and found, that mjpeg in libav is lossy too (mediainfo checking is attached below).


What am I supposed to do to fix those problems?

I found avenc_ljpeg, as I understand it is a lossless jpeg encoder for video, but it doesn't work in my pipeline. I's very strange because it nearly all the same that a avenc_mjpeg:
There is same src templates, and sink templates differs only one supporting format.
Working pipeline with avenc_mjpeg: gst-launch-1.0 v4l2src num-buffers=100 device=/dev/video1 ! videoconvert  ! avenc_mjpeg  ! avimux ! filesink location=./mjpeg-test.avi
Doesn't working pipeline with avenc_ljpeg:  gst-launch-1.0 v4l2src num-buffers=100 device=/dev/video1 ! videoconvert  ! avenc_ljpeg  ! avimux ! filesink location=./mjpeg-test.avi

I'm also attaching result of gst-launch ljpeg pipeline.

3582.log.txt
 

  • Hello,

    The both codec that you are referring are software codecs (not  TI elements).

    Ilya Kravchuk said:
    1. Saved video is faster, than real situation, recording on the camera module.

    Could you try to set ....! filesink location=.... sync=true ?

    Ilya Kravchuk said:
    Doesn't working pipeline with avenc_ljpeg:  gst-launch-1.0 v4l2src num-buffers=100 device=/dev/video1 ! videoconvert  ! avenc_ljpeg  ! avimux ! filesink location=./mjpeg-test.avi

    I would recommend:

    1.try with videotestsrc element instead of v4l2src.

    2.set the formats(in caps) before and after videoconvert element.

    3. make sure what are the colorformat that avenc_ljpeg supports. You could check this with gst-inspect avenc_ljpeg.

    BR
    Margarita

  • I know that this codecs are not TI elements. I can't use TI codecs, provided by ducati plugin, because this codecs are lossy.
    When I'm trying pipeline with videotestsrc and sync=true or sync=false param in filesink, it's okay, video isn't accelerated:

            gst-launch-1.0 videotestsrc num-buffers=50 ! videoconvert  ! avenc_mjpeg  ! avimux ! filesink location=./mjpeg-sync.avi sync =true 

    When I'm trying to do it with v4l2src and sync=true or false, output video file is faster than it should be:

            gst-launch-1.0 v4l2src device=/dev/video1 num-buffers=50 ! videoconvert ! avenc_mjpeg ! avimux ! filesink location=./mjpeg-sync-v4l.avi sync =true

    When I'm trying to do it with ljpeg and playing outputfile, appears only black screen. As I've seen in gst-inspect, ljpeg is all the same that mjpeg. Only one difference is that ljpeg can works with BGR, BGRA, I420, Y444, Y42B src, when mjpeg can works with I420, Y444, Y42B src only, and nothing else. 

    When I'm trying to set caps before and after videoconvert it throws an error, because it sets BGR format on src and sink, when it is linked with ljpeg and I420, when it is linked with mjpeg:

    gst-launch-1.0 videotestsrc -v num-buffers=500 ! capsfilter caps=video/x-raw,format=YUY2 ! videoconvert ! capsfilter caps=video/x-raw,format=I420 ! avenc_ljpeg ! avimux ! filesink location=./mjpeg-caps-sync.avi sync =true
    Setting pipeline to PAUSED ...
    Pipeline is PREROLLING ...
    /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = "video/x-raw\,\ format\=\(string\)YUY2\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = "video/x-raw\,\ format\=\(string\)YUY2\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = "video/x-raw\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive\,\ format\=\(string\)I420"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:src: caps = "video/x-raw\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive\,\ format\=\(string\)I420"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:sink: caps = "video/x-raw\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive\,\ format\=\(string\)I420"
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:sink: caps = "video/x-raw\,\ format\=\(string\)YUY2\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = "video/x-raw\,\ format\=\(string\)YUY2\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
    ERROR: from element /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0: Internal data flow error.
    Additional debug info:
    ../../../../gstreamer-1.6.3/libs/gst/base/gstbasesrc.c(2943): gst_base_src_loop (): /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0:
    streaming task paused, reason not-negotiated (-4)
    ERROR: pipeline doesn't want to preroll.
    Setting pipeline to NULL ...
    /GstPipeline:pipeline0/GstAviMux:avimux0.GstPad:src: caps = video/x-msvideo
    /GstPipeline:pipeline0/GstAviMux:avimux0.GstPad:src: caps = "NULL"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:src: caps = "NULL"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:sink: caps = "NULL"
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = "NULL"
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:sink: caps = "NULL"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = "NULL"
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = "NULL"
    /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = "NULL"
    Freeing pipeline ...


     

  • Hello,

    I would recommend you to add --gst-debug=3 to the pipeline.

    BR
    Margarita
  • Hello,

    Could you try to run the pipeline with avenc_ljpeg on PC with gstreamer 1.6 version?
    I tried on PC with gstreamer 1.2 version but it seems like format I420 is not supported in ljpegenc ( libav :0:: colorspace not supported in LJPEG).

    BR
    Margarita
  • I fixed problem with acceleration. On board camera framerate is 100/1, I convert it to 25/1 via videorate GstElement:
    gst-launch-1.0 -v v4l2src device=/dev/video1 num-buffers=573 io-mode=4 ! videoscale ! video/x-raw,width=720, height=576 ! videorate ! video/x-raw,framerate=25/1 ! videoconvert ! capsfilter caps=video/x-raw,format=GRAY8 ! avimux ! filesink location=./"raw_grey(720*576).avi" sync=true
  • On my PC pipeline with ljpeg leads to the same result:
    Setting pipeline to PAUSED ...
    Pipeline is PREROLLING ...
    /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = video/x-raw, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, format=(string)I420
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:src: caps = video/x-raw, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, format=(string)I420
    /GstPipeline:pipeline0/avenc_ljpeg:avenc_ljpeg0.GstPad:sink: caps = video/x-raw, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, format=(string)I420
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:sink: caps = video/x-raw, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, format=(string)I420
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:sink: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
    ERROR: from element /GstPipeline:pipeline0/avenc_ljpeg:avenc_ljpeg0: GStreamer error: negotiation problem.
    Additional debug info:
    gstvideoencoder.c(1368): gst_video_encoder_chain (): /GstPipeline:pipeline0/avenc_ljpeg:avenc_ljpeg0:
    encoder not initialized
    ERROR: pipeline doesn't want to preroll.
    Setting pipeline to NULL ...
    /GstPipeline:pipeline0/avenc_ljpeg:avenc_ljpeg0.GstPad:sink: caps = NULL
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:src: caps = NULL
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter1.GstPad:sink: caps = NULL
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = NULL
    /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:sink: caps = NULL
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = NULL
    /GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = NULL
    /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = NULL
    Freeing pipeline ...
    ilya@ubuntu:~/Videos$ gst-launch-1.0 videotestsrc num-buffers=50 ! videoconvert ! avenc_ljpeg ! avimux ! filesink location=./ljpeg.aviSetting pipeline to PAUSED ...
    Pipeline is PREROLLING ...
    ERROR: from element /GstPipeline:pipeline0/avenc_ljpeg:avenc_ljpeg0: GStreamer error: negotiation problem.
    Additional debug info:
    gstvideoencoder.c(1368): gst_video_encoder_chain (): /GstPipeline:pipeline0/avenc_ljpeg:avenc_ljpeg0:
    encoder not initialized
    ERROR: pipeline doesn't want to preroll.
    Setting pipeline to NULL ...
    Freeing pipeline ...
    ilya@ubuntu:~/Videos$ gs
  • Hello,

    It seems like format issue with ljpeg enc.
    I found this issue with avenc_mjpeg, it seems same issue like for avenc_ljpeg.
    lists.freedesktop.org/.../149457.html

    BR
    Margarita
  • also I've tried huffyuv codec, It correctly works on my pc, but on board it throws very strange result:

    gst-launch-1.0 videotestsrc num-buffers=500 ! videoconvert ! avenc_huffyuv ! avimux ! filesink location=./huff.avi sync=true


    Same pipeline, playing on my PC with gstreamer 1.2.4



  • Hello,

    I am sorry for the delay. It seems like color issue.
    I would recommend you to try to connect one more videoconvert element after the encoder and set caps.

    On the board you have version 1.6 gstreamer, on PC you have version 1.2 I would recommend you to try on the PC with gstreamer version 1.6(not 1.2).

    BR
    Margarita
  • Thanks for your reply, but this codec already is unsuitable, because it doesn't give enough compressing for grayscale image.

  • Hello,

    I am closing this thread then.

    BR
    Margarita