Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VLC save stream to file

I just stuck in creating batch file for recording stream from CCTV. Previously this works on Ubuntu server in code like this:

cvlc -d --sout "#transcode{vcodec=FLV1,vb=512,fps=3,acodec=none,sfilter=marq{marquee='АБК %d.%m.%Y %H.%M.%S',opacity=200,size=20}}:std{access=file,mux=ffmpeg{mux=flv},dst=/storage/surveillance/$date/${name[$i]}/$curdate.flv}" --ttl=127 "http://cameralogin@camerapassword@cam_ip/cgi-bin/cmd/encoder?&${analog[$i]}&GET_STREAM" --http-reconnect --http-continuous --sout-mux-caching=1500 --udp-caching=6000 --tcp-caching=6000

I got HTTP stream from camera in MJPG, which I can open from cmd using this

vlc.exe "http://cameralogin@camerapassword@cam_ip/cgi-bin/cmd/encoder?&$CHANNEL=1&GET_STREAM"

But I stuck when I trying to save it to file adding this to previous command:

--sout "#transcode{vcodec=FLV1,vb=512,fps=3,acodec=none,sfilter=marq{marquee='АБК %date% %time%',opacity=200,size=20}}:std{access=file,mux=ffmpeg{mux=flv},dst=%archive%\%name%\%date%\%time%.flv}" 

VLC is opened, but no video output and file in path. Disc F is local HDD, login and password is right to cam. Batch is opened from local admin.

Full file looks like this:

:: Set encoding for cyrillyc symvols
@chcp 866

:: Some vars for easy edit in future
:: Choosing cam
:: set analog=CHANNEL=1
set analog=CHANNEL=2
:: set analog=CHANNEL=3
:: set analog=CHANNEL=4

:: Choose folder to save
:: set name="2 этаж"
set name="1 этаж"
:: set name="Главный_вход"
:: set name="1 этаж 2"

:: Path to archive
set archive="F:\Archive\Охрана"

:: Move to vlc.exe folder
cd "c:\Program Files (x86)\VideoLAN\VLC"

:: Record Video
vlc.exe --sout "#transcode{vcodec=FLV1,vb=512,fps=3,acodec=none,sfilter=marq{marquee='АБК %date% %time%',opacity=200,size=20}}:std{access=file,mux=ffmpeg{mux=flv},dst=%archive%\%name%\%date%\%time%.flv}" --ttl=127 "http://cameralogin@camerapassword@cam_ip/cgi-bin/cmd/encoder?&$%analog%&GET_STREAM" --http-reconnect --http-continuous --sout-mux-caching=1500 --udp-caching=6000 --tcp-caching=6000
like image 350
K. Belykh Avatar asked Oct 18 '22 12:10

K. Belykh


2 Answers

Your VLC command is incorrect: it should be in "source capture - transcode" format, not vice versa. Pls follow Streaming HowTo/Command Line Examples, see also FLV support. As well, the command output depends on VLC version used. Older version VLC2.2.2 may work better from Cmd, and allows to use VLM Config file without output errors.

Generally, before trying to launch VLC from a batch, try using the same transcode options in Windows via VLC GUI, and see if it can properly capture and transcode the output, and what will be CPU load. Follow transcode command examples, more here. Consider transcoding to H264 or newer codec formats for smaller file size.

In case of high CPU load, as an alternative try latest FFMpeg Zeranoe build for Windows due to often lower CPU load and higher transcode quality compare to VLC. Look through their forum for proper transcode commands examples. Note, VLC uses FFMPEG package as well, but an older version. Windows FFMPEG builds use DirectShow to capture USB webcam input, so typical commands look different from Linux builds, but may look similar for IPCams.

For your particular IPCam model a very basic stream capture batch file run from FFMPEG\bin folder may look like this (untested, but works for my IPCam model with a modified URL string):

@echo off
ffmpeg -f mjpeg -i ^
 "http://login:password@cam_ip/cgi-bin/cmd/encoder?&$CHANNEL=1&GET_STREAM" ^
 -vcodec flv -q:v 1 -an K:\Videos\output.flv
exit /b

Another typical command example for a Foscam MJPEG IPCam capture:

ffmpeg -f mjpeg -i "http://Cam_IP:8080/videostream.cgi?user=[login]&pwd=[password]" ^
 -vcodec flv -q:v 1 -an K:\Videos\output.flv

Check Camera Connection Database for correct URL capture strings depending on your IPCam model. See also Transcoding MJPEG to FLV or MP4.

like image 80
sambul35 Avatar answered Oct 28 '22 20:10

sambul35


Thanks to @sambul35, In case someone needs help with Linux. You can use this command to record a live stream from an HTTP server and save to file:-

vlc "http://{http_server_uri}" --sout="#duplicate{dst=std{access=file,mux=avi,dst='{destination}/{filename}.avi'},dst=nodisplay}"
like image 41
sarbesh sarkar Avatar answered Oct 28 '22 20:10

sarbesh sarkar