Freescale / gstreamer-imx

GStreamer 1.0 plugins for i.MX platforms
Other
184 stars 127 forks source link

gstreamer-imx video streaming and encoding #269

Closed bernardlee99 closed 4 years ago

bernardlee99 commented 4 years ago

I am currently using an Nitrogen 6 Max development board. I am attempting to retrieve video from my webcam through v4l2src so that the feed back be streamed and encoded to be saved.

This is the pipeline, and it works:

  v4l2src device="/dev/video2" ! tee name=t
      t. ! queue ! x264enc ! mp4mux ! filesink location=test.mp4
      t. ! queue ! videoconvert ! autovideosink

Then I attempted to use the imx-gstreamer library. I spent time looking around and found that this works:

   gst-launch-1.0 -e videotestsrc num-buffers=1000 ! \
       video/x-raw,width=640,height=480,framerate=30/1 ! imxvpuenc_h264 ! \
       h264parse !  avdec_h264 ! filesink location=cx1.mp4

However, when I attempt to use "tee" to split up the video source, it just freezes and my terminal session locks up.

   gst-launch-1.0 -e videotestsrc num-buffers=1000 ! autovideoconvert ! tee name=t \
       t. ! video/x-raw,width=640,height=480,framerate=30/1 ! imxvpuenc_h264 ! h264parse ! avdec_h264 ! filesink location=cx1.mp4 \
       t. ! video/x-raw,width=640,height=480,framerate=30/1 ! autovideosink

I tried isolating the issue by encoding through tee, and realize that this it runs, but the video file that it generates is corrupted:

   gst-launch-1.0 -e videotestsrc num-buffers=1000 ! tee name=t \
       t. ! video/x-raw,width=640,height=480,framerate=30/1 ! imxvpuenc_h264 ! \
       h264parse !  avdec_h264 ! filesink location=cx1.mp4

I tried using queues, videoconvert, but it does not seem to work and yield a corrupted mp4 file.

Sometimes, the command fails. By setting DEBUG to level 4, this was the last few line before the error happened:

0:00:00.686495508  1488  0x23e9400 INFO              GST_STATES gstelement.c:2579:_priv_gst_element_state_changed:<videotestsrc0> notifying about state-changed READY to PAUSED (VOID_PENDING pending)
0:00:00.686594840  1488  0x23e9400 INFO              GST_STATES gstbin.c:2954:gst_bin_change_state_func:<pipeline0> child 'videotestsrc0' changed state to 3(PAUSED) successfully
Pipeline is PREROLLING ...
0:00:00.686697838  1488  0x2565af0 INFO        GST_ELEMENT_PADS gstelement.c:917:gst_element_get_static_pad: no such pad 'sink' in element "videotestsrc0"
0:00:00.686910836  1488  0x2565af0 FIXME                default gstutils.c:3981:gst_pad_create_stream_id_internal:<videotestsrc0:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.688988143  1488  0x2565af0 INFO               GST_EVENT gstevent.c:814:gst_event_new_caps: creating caps event video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
0:00:00.689833466  1488  0x2565af0 INFO           basetransform gstbasetransform.c:1308:gst_base_transform_setcaps:<capsfilter0> reuse caps
0:00:00.689948131  1488  0x2565af0 INFO               GST_EVENT gstevent.c:814:gst_event_new_caps: creating caps event video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
0:00:00.690664456  1488  0x2565af0 INFO       imxvpuencoderbase encoder_base.c:378:gst_imx_vpu_encoder_base_set_format:<imxvpuencoderh264-0> setting encoder format
0:00:00.690738455  1488  0x2565af0 INFO       imxvpuencoderbase encoder_base.c:418:gst_imx_vpu_encoder_base_set_format:<imxvpuencoderh264-0> setting bitrate to 0 kbps and GOP size to 16
0:00:00.691136117  1488  0x2565af0 INFO          imxvpuenc_h264 encoder_h264.c:234:gst_imx_vpu_encoder_h264_set_open_params:<imxvpuencoderh264-0> produce h.264 access units: yes
[INFO]  ringBufferEnable 0, chromaInterleave 0, mapType 0, linear2TiledEnable 1
0:00:00.700848997  1488  0x2565af0 INFO     imxphysmemallocator phys_mem_allocator.c:174:gst_imx_phys_mem_allocator_alloc:<imxvpuallocator0> allocated memory block 0x6f705150 at phys addr 0x6da00000 with 537601 bytes
0:00:00.704786281  1488  0x2565af0 INFO     imxphysmemallocator phys_mem_allocator.c:174:gst_imx_phys_mem_allocator_alloc:<imxvpuallocator0> allocated memory block 0x6f7051a0 at phys addr 0x6db00000 with 537601 bytes
0:00:00.709409224  1488  0x2565af0 INFO     imxphysmemallocator phys_mem_allocator.c:174:gst_imx_phys_mem_allocator_alloc:<imxvpuallocator0> allocated memory block 0x6f7051f0 at phys addr 0x6dc00000 with 537601 bytes
0:00:00.713479507  1488  0x2565af0 INFO     imxphysmemallocator phys_mem_allocator.c:174:gst_imx_phys_mem_allocator_alloc:<imxvpuallocator0> allocated memory block 0x6f705240 at phys addr 0x6dd00000 with 537601 bytes
Caught SIGSEGV
exec gdb failed: No such file or directory
Spinning.  Please run 'gdb gst-launch-1.0 1488' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.

Also, another question here. I am new to GstElement capabilities, which is what decides which element can be linked (i.e, a v4l2src video/x-raw capability includes I420, that's why I can link this element to imxvpuenc_h264). However, for the element tee, does it split and replicate the capability of the src?

I am new to gstreamer, and I can't seem to work around this issue. Can someone help me out here?