How can I access the H264 stream from my IP-camera with "Motion"?

What is Motion?: Motion is a deamon application which allows Linux users to record pictures of webcams and ipcams based on motion detection or time settings. A Tutorial how to set up the stable release can be found here. Here is the Motion developer website and documentation

My Setup: I'm using a cheap Hikvision 2032 IP-camera, which is set to IP 192.168.1.199. Its mainstream (H264) is:

rtsp://192.168.1.199:554/ISAPI/streaming/channels/101?auth=YWRtaW46MTIzNDU=

(It is working fine in VLC)

As I've been told Motion unfortunately doesn't supports H264 in its current stable release (3.2.12). But the latest developers build has some integration and that there is a fork which is optimized for it.

The installation of the builds is highly complicated though and I try to collect the tips I get in step-by-step instructions in my posting below:

Edit:At this stage I've downloaded the Git Version MrDave recommended me below and I think I have all dependencies. After following the steps in my collected instructions it finally works at 1080x720 resolution.

I have the problem to save files to my images folder when using 1920x1080:

nuc@nuc:/usr/local/etc$ motion
[0] [NTC] [ALL] conf_load: Processing thread 0 - config file /usr/local/etc/motion.conf
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "sdl_threadnr"
[0] [NTC] [ALL] motion_startup: Motion trunkREVUNKNOWN Started
[0] [NTC] [ALL] motion_startup: Logging to syslog
[0] [NTC] [ALL] motion_startup: Using log type (ALL) log level (NTC)
[0] [NTC] [ENC] ffmpeg_init: ffmpeg LIBAVCODEC_BUILD 3562596 LIBAVFORMAT_BUILD 3555176
[0] [NTC] [ALL] main: Thread 1 is from /usr/local/etc/motion.conf
[0] [NTC] [ALL] main: Thread 1 is device: rtsp://192.168.1.199:554/ISAPI/streaming/channels/101?auth=YWRtaW46MTIzNDU= input -1
[0] [NTC] [ALL] main: Stream port 8081
[0] [NTC] [ALL] main: Waiting for threads to finish, pid: 9028
[1] [NTC] [ALL] motion_init: Thread 1 started , motion detection Enabled
[1] [ALR] [NET] netcam_start: Network Camera thread starting... for url (rtsp://192.168.1.199:554/ISAPI/streaming/channels/101?auth=YWRtaW46MTIzNDU=)
[0] [NTC] [STR] httpd_run: motion-httpd testing : IPV4 addr: 127.0.0.1 port: 8080
[0] [NTC] [STR] httpd_run: motion-httpd Bound : IPV4 addr: 127.0.0.1 port: 8080
[0] [NTC] [STR] httpd_run: motion-httpd/trunkREVUNKNOWN running, accepting connections
[0] [NTC] [STR] httpd_run: motion-httpd: waiting for data on 127.0.0.1 port TCP 8080
[1] [NTC] [NET] netcam_rtsp_open_context: Using tcp transport
[1] [NTC] [NET] netcam_connect_rtsp: Camera connected
[1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 1 items
[1] [ALR] [NET] netcam_handler_loop: Camera handler thread [2] started
[1] [NTC] [STR] http_bindsock: motion-stream testing : IPV4 addr: 127.0.0.1 port: 8081
[1] [NTC] [STR] http_bindsock: motion-stream Bound : IPV4 addr: 127.0.0.1 port: 8081
[1] [NTC] [ALL] motion_init: Started motion-stream server in port 8081 auth Disabled
Memoryaccesserror (core image written).

The avi and jpg in full resolution are empty or not availabe if I try to open.

1

2 Answers

In order to get the rtsp and H264 support, you will need to build the application from source. The primary version of the source is at . There are however many forks of this source the implement various features including RTSP/H264. If you review the graphs / network tabs in git you can see these versions and determine which is best for your situation. If you are not familiar with building from source, basic instructions for compiling and building motion can be found in the following fork in the INSTALL file. Those instructions have been validated with 12.04 but may require slight modifications for use with 14.04.

Note that for the camera you have referenced, the command line that you reference may not be correct. The formats that I have observed for this camera are rtsp://user:pwd@ipaddress:554/streaming/channels/1 (for the primary stream) or rtsp://user:pwd@ipaddress:554/streaming/channels/2 for the secondary stream. Prior to setting up the camera in motion, you should validate the connection string with VLC or avplay. Once it is confirmed to work in either of those applications, you can copy the connect string directly over into the motion.conf file as the netcam url.

Finally, if you want to save CPU resources for this camera, it's better to have motion set up to monitor the smaller SD secondary stream and use the configuration options to trigger an external recording application to record the main HD stream in the native format when motion occurs.

17

I summarize MrDaves instruction for Ubuntu 14.04 and 15.04 in a step by step guide:

Motion needs many libraries which need to be installed before we can install Motion.:

Firstly, we have to install the required packages for Motion:

sudo apt-get install autoconf automake build-essential libtool libjpeg8-dev libzip-dev

Secondly, we have to install the LIBAV libraries:

sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev libav-tools libswscale-dev

Important: This optional third step is only needed if you haven't installed LIBAV libraries (the seconds step): Then we have to install FFMPEG libraries from source:

Goto and get the latest source for Ubuntu (via Git):

sudo apt-get install git
cd ~
git clone git:// ffmpeg

And build it from source (I haven't found any easy instructions).

Easier alternative for step 3: As written here one can use apt-get:

sudo add-apt-repository ppa:jon-severinsson/ffmpeg
sudo apt-get update
sudo apt-get install ffmpeg
sudo apt-get install frei0r-plugins

After all this we finally can install Motion via Git:

sudo apt-get install git
cd ~
git clone 

(Motion seems developed in a rather competing fashion with many forks, so you have to check which version fits best for you by looking at their development tree on Git.)

example: git clone 

change into the motion folder of your homedrive:

cd motion

Configure a basic setup:

The command by using the LIBAV route (second step) is:

./configure

And without LIBAV:

./configure --with-ffmpeg=$HOME/ffmpeg --with-ffmpeg-headers=$HOME/ffmpeg/include

Now enter:

make
sudo make install

Goto the directory of the conf file and rename the conf file:

cd /usr/local/etc
sudo mv motion-dist.conf motion.conf

Finally start motion:

motion

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like