Before we had the pebble watch seizure detector, I had set up a video camera system in the house so we could keep an eye on Benjamin to see he is ok when he is up in his bedroom (he is autistic so likes to lock himself in there and doesn’t like visitors!). The current system uses a WansView network (IP) camera and some Raspberry Pi based monitors in the living room, dining room etc. to see and hear what is happening.
I have always liked the idea of having a mobile phone or tablet computer version of the monitor that we can take with us if we are in a different room, the garage, garden etc. I have had a couple of attempts at writing it, and always failed, so have been doing more investigations to see what is wrong.
There is a minimalist Android app on the OpenSeizureDetector Github repository which will open an RTSP stream from the camera and display it on screen with audio, using the Android MediaPlayer library which is part of the Android system.
The problem is that I kept getting an error:
E/MediaPlayer: Error (1,-2147483648)
which is not awfully helpful – error 1 means ‘Unspecified MediaPlayer Error‘, and all I got was a blank screen.
I tried all sorts of combinations of RTSP url’s and authentication methods, and different video stream sizes and bit rates, in the hope that that would help. See the Troubleshooting_log.txt file in the repository. Nothing Did – always got error 1 and a blank screen….
Then I remembered that I have an old Y-Cam Knight video camera in the attic. I set that up and pointed the app at its rtsp video stream (rtsp://guest:email@example.com/live_mpeg4.sdp)…and I got video and audio – success!
Rapidly decided to scrap Wansview camera and buy another Y-Cam one…But Y-Cam don’t do IP Cameras any more, just ‘Cloud Cameras’ which are apparently different and only transmit when they detect movement, which is no use for me….
So at least I know it is not my software, it is something to do with the wansview camera. As a fall back I have ordered a D-Link camera, which I have seen reports of working from someone called Josh Smith, and on which I based my minimalist test app.
But that would be giving up, so I’d like to understand what is wrong with the stream from the wansview camera.
From my experiments, Error 1 could come from an RTSP authentication fault, but I don’t think that is it, because the same URL works with openRTSP from my laptop. So another possibility is a audio/video format issue. You can use openRTSP to download the raw audio and video streams separately –
This yields a video-H264-1 and an audio-PCMA-2 file. You can now use ffmpeg to create a .mp4 container containing either the video file alone or the video and audio combined.
Just video file:
ffmpeg -f h264 -i video-H264-1 -vcodec copy wansview_video.mp4
openRTSP can create a combined audio/video one during the download with:
openRTSP -4 "rtsp://guest:firstname.lastname@example.org/12" > audio_video.mp4
But the resulting file crashes mplayer and gives an “unknown error” in vlc. So I suspect it might be the audio format that is giving the trouble – the ycam camera used amr audio format, not pcma.
A quick check confirmed that the wansview_video.mp4 file plays ok when copied into the res/raw folder of the app and the software modified to play that, rather than the RTSP stream. So, I think that Android is playing the h264 video ok (which it should according to the Supported Media Formats page. The problem is probably an issue with the PCMA audio format – PCM is supported, but this must be different to PCMA…
This means that I am not going to be able to write a nice simple App to play the audio and video using the provided Android MediaPlayer library – if I want it, I will have to be cleverer to deal with the audio. I think the options are:
- Write it all from scratch (major undertaking!)
- Use the ffmpeg library that has been ported to Android
- Use the Gstreamer library that has been ported to Android
I am a bit suspicious about trying to use ffmpeg, as this didn’t seem to like the PCMA on my laptop (although dolphin player, which is based on ffmpeg plays the openRTSP created .mp4 file ok), so maybe Gstreamer is the way to go. There is an Open Source RTSP viewer available that is based on gstreamer (rtspviewer), or possibly (rtspplayer).
So I’m going to have to learn a bit more about native apps on Android – I had hoped that making a video player would be trivial!