Record An IP Cam Network Stream In Linux

View previous topic View next topic Go down

Record An IP Cam Network Stream In Linux

Post by jamied_uk on Tue 22 Nov 2016 - 7:39





Code:
ffmpeg -i rtsp://192.168.241.1:62156 -acodec copy -vcodec copy output.mp4


For Linux Mint 18.1 Update:


Code:
#!/bin/bash
# recordCam.sh AKA test.sh
#
# Function Cam will also work if you have set that up!
#
# ------------
# This script saves the live video from the Foscam IP camera to a full-quality mp4 file.
# I chose to split the files every 15 minutes (900 seconds), to quickly find the time I need.
# Note: audio is not saved as my cameras don't have a microphone connected to them.
# -----------
# Author: @LucaTNT
# License: BSD

# Uncomment this line if you're having trouble with zero-sized files (tipically happens on low end cameras), thanks Eric! (https://lucatnt.com/2014/08/record-and-archive-video-from-ip-cameras/#comment-48019)
# killall -INT ffmpeg

# The file name. I use the date to make finding files easier.
name="`date +%Y-%m-%d_%H.%M`"

# Where the videos will be saved
BASEpath='/home/jay/scripts/Stream_Recorder'
RECpath=$BASEpath'/video'

# Save the streams using ffmpeg at 30 fps, stopping the capture after 900 seconds (15 minutes). Add more lines if you have more than 2 cameras
ffmpeg -i rtsp://username:password1@192.168.0.340:554 -r 30 -vcodec copy -an -t 60 $RECpath/cam01/$name.mp4
name="`date +%Y-%m-%d_%H.%M`"
#
# 9 second vid test string
# ffmpeg -i rtsp://admin:jld161@192.168.0.34:554 -r 30 -vcodec copy -an -t 9 video/cam01/$name.mp4
#
#  </dev/null >/dev/null 2>/tmp/cam01.log &
#
#ffmpeg -i rtsp://username:password@192.168.1.202:80/videoMain -r 30 -vcodec copy -an -t 900 $RECpath/cam02/$name.mp4 </dev/null >/dev/null 2>/tmp/cam02.log &


Bash RC Function


Code:
sudo gedit .bashrc




Code:
function Cam (){

sudo /home/jay/Stream_Recorder/loop_test.sh
Cam
}


Last edited by jamied_uk on Sun 30 Apr 2017 - 4:34; edited 2 times in total
avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by jamied_uk on Tue 22 Nov 2016 - 8:35

Script



Code:
#!/bin/bash
# recordCam.sh  AKA test.sh
# ------------
# This script saves the live video from the Foscam IP camera to a full-quality mp4 file.
# I chose to split the files every 15 minutes (900 seconds), to quickly find the time I need.
# Note: audio is not saved as my cameras don't have a microphone connected to them.
# -----------
# Author: @LucaTNT
# License: BSD

# Uncomment this line if you're having trouble with zero-sized files (tipically happens on low end cameras), thanks Eric! (https://lucatnt.com/2014/08/record-and-archive-video-from-ip-cameras/#comment-48019)
# killall -INT ffmpeg

# The file name. I use the date to make finding files easier.
name="`date +%Y-%m-%d_%H.%M`"

# Where the videos will be saved
BASEpath='/home/jay/scripts/Stream_Recorder'
RECpath=$BASEpath'/video'

# Save the streams using ffmpeg at 30 fps, stopping the capture after 900 seconds (15 minutes). Add more lines if you have more than 2 cameras
ffmpeg -i rtsp://admin:password@192.168.100.10:554 -r 30 -vcodec copy -an -t 900 $RECpath/cam01/$name.mp4


lucatnt.com/2014/08/record-and-archive-video-from-ip-cameras/


Last edited by jamied_uk on Tue 22 Nov 2016 - 9:55; edited 1 time in total
avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by jamied_uk on Tue 22 Nov 2016 - 9:40

Record Stream Function For Linux




Code:
function Cam (){
cd /home/jay/scripts/Stream_Recorder
sudo ./test.sh

}




add to your .bashrc file (via sudo) then start a new terminal window and type Cam


(also change to your own folder names etc! aLSO MAKE SURE FOLDER EXISTS > video/cam01

Example:
/home/jay/scripts/Stream_Recorder/video/cam01 )

After it runs once it wont run again, it has a time limit (900) with -t tag

you can use crontab or cronjobs to choose when to record Very Happy  or maybe even use a call to the function after it finishes so it loops that way Smile
avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by jamied_uk on Tue 22 Nov 2016 - 10:47

Looping



Code:
function Cam (){
cd /home/jay/scripts/Stream_Recorder

sudo ./loop_test.sh
Cam

}


and the updated example for looping 60 = seconds change to what you wish to loop must be at least 1 minute!


Code:
ffmpeg -i rtsp://admin:password@192.168.0.34:554 -r 30 -vcodec copy -an -t 60 $RECpath/cam01/$name.mp4
name="`date +%Y-%m-%d_%H.%M`"


Last edited by jamied_uk on Thu 24 Nov 2016 - 23:09; edited 1 time in total
avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by jamied_uk on Tue 22 Nov 2016 - 11:25

Motion Detection




Code:
sudo apt-get install -y gdebi-core motion




Code:
mkdir .motion



(Note: This will create a hidden folder .motion in your Home directory.)

Code:
cp /etc/motion/motion-dist.conf ~/.motion/motion.conf



(Note: This command will copy the original motion configuration file to its location.)

Now can open the configuration file for editing:

Code:
sudo nano ~/.motion/motion.conf



After you you have made all the appropriate adjustments to the configuration file, close it. Then start motion in the terminal simply by typing:

motion


Or
Code:
use Git



Code:
cd ~



Code:
git clone https://github.com/Motion-Project/motion.git

Code:
cd motion

Code:
autoreconf -fiv

Code:
./configure

Code:
make

Code:
make install

htmlpreview.github.io/?https://github.com/Motion-Project/motion/blob/master/motion_guide.html#Install_Build


lavrsen.dk/foswiki/bin/view/Motion/WebHome


Last edited by jamied_uk on Thu 24 Nov 2016 - 3:47; edited 2 times in total
avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by jamied_uk on Tue 22 Nov 2016 - 11:34

Other Alternatives
encrypted.google.com/search?q=how+to+identafie+mp4+files+that+have+movement

encrypted.google.com/search?q=how+to+detect+motion+using+linux+and+a+network+ip+cam+stream
avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by jamied_uk Today at 4:37

avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by jamied_uk Today at 8:10

Make sure the folders you need are created if you get errors that they dont exist make sure you create them Smile
avatar
jamied_uk
Admin

Posts : 2022
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Record An IP Cam Network Stream In Linux

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum