Streaming H264 using RaspberryPi camera
Asked Answered
S

5

8

I am working on a project to build a robot using raspberry pi that will send video to android device, and will be controlled from it.
I decided to use the RaspberryPi camera (maybe usb webcam is better?). I want the video to be in H264 format, but I got problem in getting streaming in this kind of format. I tried using gstreamer and vlc:

  1. If I use vlc I get a very delayed video, and not smooth.
  2. If I use gstreamer I get a good video, but I don't know how to set a url to put in the android app code. I can see the video by running the gstreamer command in my pc. The commands I use are:

On the RaspberryPi:

raspivid -t 999999 -h 720 -w 1080 -fps 25 -hf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse !  rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=192.168.1.102 port=5000

On my PC (to view the video):

gst-launch-1.0 -v tcpclientsrc host=192.168.1.102 port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false

So first, my question is if there is any way to set a url to catch this gstreamer stream (or any other way to catch the stream in the android app code)?
Second, If you have any other advices, such as using a different camera, different format (not mjpg), different streaming way, etc.

Sorilda answered 24/12, 2013 at 10:28 Comment(1)
I'm working on wireless streaming video as well, as far as I know, the best way is to server the stream as RTSP (in which use RTP over TCP/UDP). After that you can write an app which plays the url rtsp://ip.Michelmichelangelo
P
2

The way you have chosen is the best one I believe. Gstreamer has android examples ready to use (via NDK): http://docs.gstreamer.com/display/GstSDK/Android+tutorial+3%3A+Video

You can find sample application here: https://play.google.com/store/apps/details?id=pl.effisoft.rpicamviewer2

Pownall answered 26/11, 2014 at 15:3 Comment(0)
B
1

Sure, you can use that same PC pipeline in Android code. Take a look at GStreamer's Android Tutorial 3 to see how to run GStreamer code on Android. You can basically run that exact tutorial program on your Android device, just paste your pipeline into call to gst_parse_launch. Also, make sure to add the INTERNET permission to your Android manifest, otherwise your program won't be able to open up a socket.

The only thing is that your pipeline is using GStreamer 1.0, while the SDK tutorial example above is written for GStreamer 0.10. It's fairly easy to cross compile the GStreamer 1.0 SDK for Android using the Cerbero build system though (I have done this recently and can help you out). Or you can just stick with 0.10 on Android and use the pre-built 0.10 SDK files.

EDIT: One more thing -- you don't need both the RTP payloader and the GDP payloader, just one. RTP alone works well for me.

Broadcaster answered 31/7, 2014 at 0:45 Comment(0)
M
1

You can find a possible solution from the forum RTSP Streaming H264.

It is possible to access to the rasperry camera board through a V4L2 driver:

sudo modprobe bcm2835-v4l2

uv4l --driver raspicam --auto-video_nr

Next you can find an simple implementation of an RTSP streamer feed from an H264 V4L2 source gihub

Megalopolis answered 3/11, 2014 at 16:25 Comment(0)
P
1

Compiling gstreamer for Android can be tough sometimes. You can consider alternative solution to view your pipeline on android device. Example code below opens simple pipeline based on videotestsrc :

Intent intent = new Intent("pl.effisoft.rpicamviewer2.PREVIEW");
int camera =0;

//--------- Basic settings
intent.putExtra("full_screen", true);
intent.putExtra("name"+camera, "My pipeline name");
intent.putExtra("host"+camera, "192.168.0.1");
intent.putExtra("port"+camera, 5000);
intent.putExtra("description"+camera, "My pipeline description");
intent.putExtra("uuid"+camera, UUID.randomUUID().toString() );
intent.putExtra("aspectRatio"+camera, 1.6);
intent.putExtra("autoplay"+camera, true);

//--------- Enable advanced mode
intent.putExtra("advanced"+camera, true);
intent.putExtra("custom_pipeline"+camera, "videotestsrc ! warptv ! autovideosink");

//--------- Enable application extra features
intent.putExtra("extraFeaturesEnabled"+camera, false);

//--------- Add autoaudiosink to featured pipeline
intent.putExtra("extraFeaturesSoundEnabled"+camera, false);

//--------- Scale Video Stream option
intent.putExtra("extraResizeVideoEnabled"+camera, false);


intent.setPackage("pl.effisoft.rpicamviewer2");
startActivityForResult(intent, 0);

Full example code is here: https://github.com/pzuk/raspberry-pi-camera-viewer-embedded-example

Pownall answered 23/7, 2016 at 19:4 Comment(0)
A
0

I had a similar need and after many trials with vlc, gstreamer I solved using raspivid, nc (netcat) and the following android app:

https://github.com/ShawnBaker/RPiCameraViewer

it's probably not the best solution yest the source code is only partially open but it works and has a very short delay.

Actin answered 22/5, 2020 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.