5

First of all, thanks everyone who is even reading this. I'm able to save a stream from my IP CAM into a file using the given command (although I'm getting no audio recorded to the file, if anyone can help with that would be great too)

cvlc "http://***.***.*.***:****/videostream.asf?user=admin&pwd=**&rate=12&resolution=32" --run-time=10 --sout="#std{access=file,mux=asf,dst=path\test.asf}" vlc://quit --qt-start-minimized --no-qt-notification

This gives me a 7~8 seconds long recording, but the lenght of the video I want to make will be determined by an external factor (the camera's motion detection alarm). If I remove the "--run-time" it starts recording undefinatelly, so how can I tell VLC that it's time to stop saving the stream? ps: I want to make this automatic, so I'm only using command line. ps2: I'm using Ubuntu OS.

Thank you all very much!

2 Answers2

2

I'm by no means and expert on this subject but I am also capturing a live stream to start and stop at specific times. I don't know about the audio issue but here is my code maybe it will help you out somewhat.

at 2014-05-23 10:00
cvlc "http://*My url to video stream*" --sout file/mp4:*THEFILENAMEYOUCHOOSE*.mp4 --run-time=300 --stop-time=300 vlc://quit

Essentially I use the runtime and stop time switches to make sure it stops when I need it to, 300 seconds works out to almost an hour and a half of video so that's plenty for my needs, I'm having some trouble with being able to automatically script this so at this point I'm having to type the commands in by hand to set up the recording which is less than ideal.

Hope this helps you out even a little.

1

Later but if anyone is looking for the script, this my service in Debian/Ubuntu based compact recorder:

First, I create a bash script in /bin/usr/rec.sh

Put this script there whith sudo nano /usr/bin/rec.sh:

#!/bin/bash
while :
        do
        raiz=$(date +'/logger/%Y/%m/%d/')
        saida=$(date +'/logger/%Y/%m/%d/%H%M%S.opus')
        read min sec <<<$(date +'%M %S')
        duracao=$((3600 - 10#$min*60 - 10#$sec))
        duracao=60
        echo "Starting new hour loging..."
        echo "$saida"
        echo "$duracao"
        mkdir -p "$raiz"
        vlc **your url here** --no-repeat --no-loop -I dummy --run-time="$duracao" --sout "#transcode{vcodec=none,acodec=opus,ab=64,channels=2,samplerate=48000,afilter=normvol,scodec=none}:std{access=file{no-overwrite},mux=ogg,dst='$saida'}" vlc://quit
        echo "Done a hour logged!"
        done

Make executable: sudo chmod +x /usr/bin/rec.sh

So, you need create a service Systemd for the script.

sudo nano /lib/systemd/system/rec.service 

This sample help you:

[Unit]
Description=URL logger service

[Service]
ExecStart=/usr/bin/rec.sh

[Install]
WantedBy=multi-user.target

Reload systemd:

sudo systemctl daemon-reload 

Enable and the service: sudo systemctl enable shellscript.service sudo systemctl start shellscript.service

check status:

sudo systemctl status shellscript.service 

REMINDER: cvlc don't run as root by default. Here is the trick to do this:

 sudo sed -i 's/geteuid/getppid/' /usr/bin/vlc

This service will record the url and transcode audio to OPUS in /logger directory, separated by YEAR / MONTH / DAY / HMS.opus (since record beggining). Each new file is started every hour o'clock.

I hope that help someone.

References: https://tecadmin.net/run-shell-script-as-systemd-service/ and https://www.tecmint.com/run-vlc-media-player-as-root-in-linux/

Sorry my bad English.