2014-10-03 94 views
1

我試圖寫一個非常基本的bash腳本,將完成同樣的事情,因爲這命令行:VLC在bash腳本

cvlc \ 
    'rtsp://192.168.0.66/cam/realmonitor?channel=1&subtype=0&authbasic=xxxxxxxxx?tcp' \ 
    --sout file/mp4:/mnt/recordings/camera16_2014_10_03_13.mp4 \ 
    --run-time=60 vlc://quit 

進入到這個命令行工作,我得到預期的60秒MP4文件。把它放到一個bash腳本中,我似乎無法正確地傳遞給VLC的所有參數。

#!/bin/bash 
camname="CAMERA16" 
token="_" 
ipadd="192.168.0.66" 
runtime="60" 
cvlc "rtsp://$ipadd/cam/realmonitor?channel=1&subtype=0&authbasic=xxxxxxxxx?tcp --sout file/mp4:/mnt/recordings/$camname$token$(date +$Y_%m_%d_$H_$M).mp4 --run-time=$runtime vlc://quit" 

運行此腳本將啓動VLC,而不是無頭,並忽略其他參數。它不寫入文件,它永遠不會退出。它只是將VLC連接到流並播放流。

我嘗試了幾種不同的方式來引用參數沒有成功。所有建議表示讚賞

回答

1

這些需要是cvlc命令的獨立參數。通過將它們全部放在一個大的雙引號字符串中,將它們變成單個參數,這將不起作用。把每個參數放在它自己的一組雙引號中;請勿將引號內的空格:

cvlc "rtsp://$ipadd/cam/realmonitor?channel=1&subtype=0&authbasic=xxxxxxxxx?tcp" \ 
    --sout "file/mp4:/mnt/recordings/$camname$token$(date +$Y_%m_%d_$H_$M).mp4" \ 
    --run-time="$runtime" vlc://quit 

我使用引用的換行符來分隔多行以顯示易讀性;它也可以只是一條沒有\的長線。