Reputation: 414
I'm noobie in MS batch (bat). I need to save some streaming via VLC to file. This script working greate for me:
@echo off
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "http://STREAM" --sout=#transcode{vcodec=h264,vb=1400,scale=1,acodec=mpga,ab=192,channels=2,deinterlace}:file{dst="D:\SOMEFILE.mp4"}
But I need to stop recording after N seconds. So I think the best way is to get pid of this proccess and run
timeout /t 120 /nobreak
taskkill /t /pid %PID%
For this I found some solution:
@echo off
set "exe=C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
set "source=http://STREAM"
set "save-cmd=--sout=#transcode{vcodec=h264,vb=1400,scale=1,acodec=mpga,ab=192,channels=2,deinterlace}:file{dst="D:\SOMEFILE.mp4"}"
for /f "tokens=2 delims==; " %%a in ('wmic process call create '"%exe%" "%source%" %save-cmd%' ^| find "ProcessId"') do set PID=%%a
echo "%PID%"
timeout /t 120 /nobreak
taskkill /t /pid %PID%
I'm getting PID, But VLC openning in normal way (don't do anything), as I just run C:\Program Files (x86)\VideoLAN\VLC\vlc.exe
How can I run programm with parameters and get PID of it? Thanks!
Upvotes: 2
Views: 389
Reputation: 4085
According to the VLC forums, you can use --run-time
and --stop-time
parameters to close VLC after a specified amount of time.
For example adding --run-time 120 --stop-time=120 vlc://quit
will exit after 2 hours
Updated script:
@echo off
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "http://STREAM" --sout=#transcode{vcodec=h264,vb=1400,scale=1,acodec=mpga,ab=192,channels=2,deinterlace}:file{dst="D:\SOMEFILE.mp4"} --run-time 120 --stop-time=120 vlc://quit
Upvotes: 3