alexmock
Posts: 2
Joined: Wed May 29, 2013 1:43 pm

raspivid -> gstreamer -> jpeg snapshots

Fri May 31, 2013 3:00 pm

Hi Pi folk.

I'm trying to use the camera module for a project. The idea is to capture a 1080p stream from the Pi's camera, watch for motion and when some is detected upload a video with 30s extra footage either side to YouTube.

To do this I'll need to use the camera for two things at once: recording the live 1080p h264 stream and grabbing a couple of stills per second for my code to use for motion detection.

For a couple of reasons (no /dev/video yet, only hardware encoding/decoding fast enough) I will need to use gstreamer with the gst-omx plugin. After a frustrating few days trying to build it by hand (I was missing the /opt/vc/include/ path) I came across fbutler's excellent script at http://www.raspberrypi.org/phpBB3/viewt ... 38#p352738 and got things working.

I've tested the individual components of my system...

Code: Select all

root@raspberrypi:~/streamtest# raspivid -n -t 1000000 -vf -b 2000000 -fps 25 -o - > testvideo.h264
root@raspberrypi:~/streamtest# ls -lh testvideo.h264
-rw-r--r-- 1 root root 1.2M May 31 14:35 testvideo.h264
root@raspberrypi:~/streamtest# file testvideo.h264
testvideo.h264: JVT NAL sequence, H.264 video @ L 40

Code: Select all

root@raspberrypi:~/streamtest# gst-inspect-1.0 | grep 'OpenMAX H.264'
omx:  omxh264dec: OpenMAX H.264 Video Decoder
omx:  omxh264enc: OpenMAX H.264 Video Encoder
Given these components I should be able to pipe the stream from raspivid into gstreamer and have it use the hardware h264 support. Indeed this seems to work.

Code: Select all

root@raspberrypi:~/streamtest# raspivid -n -t 1000000 -vf -b 2000000 -fps 25 -o - | gst-launch-1.0 fdsrc fd=0 ! decodebin ! fakesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
...
The problem I have is in getting gstreamer to split the stream into a video filesink and periodic, separate images. A little tinkering reveals it's really just the images causing the problem.

Code: Select all

root@raspberrypi:~/streamtest# raspivid -n -t 1000000 -vf -b 2000000 -fps 25 -o - |      gst-launch-1.0 fdsrc fd=0 ! decodebin ! video/x-raw, framerate=1/1 ! jpegenc ! multifilesink location=image_%04d.jpeg
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
...sticks in prerolling forever
Output from gstreamer's verbose mode at http://pastebin.com/eXtF8LFU in case it's helpful.

I've been bashing away at gstreamer pipelines for the last few days now but can't get anything to work. So my question - what am I doing wrong?

alexmock
Posts: 2
Joined: Wed May 29, 2013 1:43 pm

Re: raspivid -> gstreamer -> jpeg snapshots

Sun Jun 09, 2013 9:51 pm

We finally found a solution to this. My gstreamer pipeline was mostly right but two problems combined to stop it working:
  • - raspivid doesn't add timestamps to the h264 frames it produces
  • - recent versions of gstreamer have a bug which stop it handling untimestamped frames
Run a 1.0 build of gstreamer (be sure to build from scratch & remove all traces of previous attempts) and the problem goes away.

See http://gstreamer-devel.966125.n4.nabble ... 60254.html for the mailing list thread.

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: raspivid -> gstreamer -> jpeg snapshots

Wed Nov 13, 2013 10:16 am

Hi-

Do you know if gstreamer uses the built in JPG encoder? I ask this because i used ffmpeg to try and dump jpgs to use with mjpgstreamer but the most I got was 2~4fps and 100%cpu load. Ouch. If I could get 5fps using your method with minimal load that will be relatively excellent!

Do you know if it will work? I need to go and compile everything so I will be trying it but I have limited experience with Linux

Return to “OpenMAX”