Добрый день! Настраиваю видео наблюдение. Софт: ос ubuntu, OpenRTSP+ffmpeg+motion В виду того что motion не дружит с RTSP, пришлось прикручивать ffmpeg, реализовал это таким образом motion считывает с камеры mjpeg поток, как происходит движение, срабатывает скрипт такого содержания
#!/bin/bash
# We are using two variables
# 1 — camera name
# 2 — directory name (where file will be stored)
# Generate filename
start=cam${1}
dt=`date +%Y%m%d%H%M%S`
FILENAME="${start}-${dt}.avi"
echo $FILENAME
if [ "$1" -eq 15 ]
then
/usr/bin/openRTSP -v -t rtsp://172.168.0.${1}:554/live/ch00_0 | ffmpeg -i - -y -r 10 -s hd720 -b 512k -vcodec copy /rec/$2/$FILENAME
fi
вывод ffmpeg при записи:
root@zm:/etc/motion# sh /root/bin/recordstart.sh 13 cam13
cam13-20131220095506.avi
Opening connection to 172.168.0.13, port 554...
...remote connection opened
Sending request: OPTIONS rtsp://172.168.0.13/axis-media/media.amp RTSP/1.0
CSeq: 2
User-Agent: /usr/bin/openRTSP (LIVE555 Streaming Media v2013.01.15)
Received 143 new bytes of response data.
Received a complete OPTIONS response:
RTSP/1.0 200 OK
CSeq: 2
Public: DESCRIBE, GET_PARAMETER, PAUSE, PLAY, SETUP, SET_PARAMETER, TEARDOWN
Date: Tue, 12 Nov 2013 13:34:32 GMT
Sending request: DESCRIBE rtsp://172.168.0.13/axis-media/media.amp RTSP/1.0
CSeq: 3
User-Agent: /usr/bin/openRTSP (LIVE555 Streaming Media v2013.01.15)
Accept: application/sdp
ffmpeg version 0.8.9-6:0.8.9-0ubuntu0.13.04.1, Copyright (c) 2000-2013 the Libav developers
built on Nov 9 2013 19:15:52 with gcc 4.7.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Received 247 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 401 Unauthorized
CSeq: 3
WWW-Authenticate: Digest realm="AXIS_00408CB4BA8C", nonce="000693c9Y40013087cce03afcc7976a356a16714bcea94", stale=FALSE
WWW-Authenticate: Basic realm="AXIS_00408CB4BA8C"
Date: Tue, 12 Nov 2013 13:34:32 GMT
Resending...
Sending request: DESCRIBE rtsp://172.168.0.13/axis-media/media.amp RTSP/1.0
CSeq: 4
Authorization: Digest username="root", realm="AXIS_00408CB4BA8C", nonce="000693c9Y40013087cce03afcc7976a356a16714bcea94", uri="rtsp://172.168.0.13/axis-media/media.amp", response="8848cb32a0b245a25b5d6d567928efec"
User-Agent: /usr/bin/openRTSP (LIVE555 Streaming Media v2013.01.15)
Accept: application/sdp
Received 551 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 200 OK
CSeq: 4
Content-Type: application/sdp
Content-Base: rtsp://172.168.0.13/axis-media/media.amp/
Date: Tue, 12 Nov 2013 13:34:32 GMT
Content-Length: 377
v=0
o=- 1384263272410521 1384263272410521 IN IP4 172.168.0.13
s=Media Presentation
e=NONE
c=IN IP4 0.0.0.0
b=AS:50000
t=0 0
a=control:*
a=range:npt=0.000000-
m=video 0 RTP/AVP 96
b=AS:50000
a=framerate:30.0
a=control:trackID=1
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; profile-level-id=420029; sprop-parameter-sets=Z0IAKeKQFAe2AtwEBAaQeJEV,aM48gA==
Opened URL "rtsp://172.168.0.13/axis-media/media.amp", returning a SDP description:
v=0
o=- 1384263272410521 1384263272410521 IN IP4 172.168.0.13
s=Media Presentation
e=NONE
c=IN IP4 0.0.0.0
b=AS:50000
t=0 0
a=control:*
a=range:npt=0.000000-
m=video 0 RTP/AVP 96
b=AS:50000
a=framerate:30.0
a=control:trackID=1
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; profile-level-id=420029; sprop-parameter-sets=Z0IAKeKQFAe2AtwEBAaQeJEV,aM48gA==
Created receiver for "video/H264" subsession (client ports 36778-36779)
Sending request: SETUP rtsp://172.168.0.13/axis-media/media.amp/trackID=1 RTSP/1.0
CSeq: 5
Authorization: Digest username="root", realm="AXIS_00408CB4BA8C", nonce="000693c9Y40013087cce03afcc7976a356a16714bcea94", uri="rtsp://172.168.0.13/axis-media/media.amp/", response="a97a39f607ff0a7d5f66104c99c139f3"
User-Agent: /usr/bin/openRTSP (LIVE555 Streaming Media v2013.01.15)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
Received 170 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 5
Session: 3766C813; timeout=60
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=A92B5664;mode="PLAY"
Date: Tue, 12 Nov 2013 13:34:32 GMT
Setup "video/H264" subsession (client ports 36778-36779)
Outputting data from the "video/H264" subsession to 'stdout'
Sending request: PLAY rtsp://172.168.0.13/axis-media/media.amp/ RTSP/1.0
CSeq: 6
Authorization: Digest username="root", realm="AXIS_00408CB4BA8C", nonce="000693c9Y40013087cce03afcc7976a356a16714bcea94", uri="rtsp://172.168.0.13/axis-media/media.amp/", response="ff44e34e3559495431b2f68c12cca4da"
User-Agent: /usr/bin/openRTSP (LIVE555 Streaming Media v2013.01.15)
Session: 3766C813
Range: npt=0.000-
Received a complete PLAY response:
RTSP/1.0 200 OK
CSeq: 6
Session: 3766C813
Range: npt=0.234743-
RTP-Info: url=rtsp://172.168.0.13/axis-media/media.amp/trackID=1;seq=958;rtptime=485436852
Date: Tue, 12 Nov 2013 13:34:32 GMT
Started playing session
Receiving streamed data (signal with "kill -HUP 11720" or "kill -USR1 11720" to terminate)...
[h264 @ 0x93adc40] max_analyze_duration reached
[h264 @ 0x93adc40] Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 2400000.00 (2400000/1) -> 25.00 (25/1)
Input #0, h264, from 'pipe:':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: h264 (Baseline), yuvj420p, 640x480 [PAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 2400k tbc
Output #0, avi, to '/rec/cam13/cam13-20131220095506.avi':
Metadata:
ISFT : Lavf53.21.1
Stream #0.0: Video: H264 / 0x34363248, yuvj420p, 640x480 [PAR 1:1 DAR 4:3], q=2-31, 1200k tbn, 1200k tbc
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
^Cframe= 4891 fps= 31 q=-1.0 Lsize= 2435kB time=0.01 bitrate=1994460.8kbits/s
video:2312kB audio:0kB global headers:0kB muxing overhead 5.304205%
Received signal 2: terminating.