Add &
after the second line to put VLC
in the background like so:
#!/usr/bin/bash
vlc -vvv http://10.0.0.113:8000/stream.mjpg --sout="#std{access=file,mux=ogg,dst=/home/whsrobotics/vlc_project/first_try.mp4}" &
sleep 10
killall vlc
and it will work.
Explaination:
The shell/terminal will execute commands in the order they are listed in the script and will move to the next command only if the command before it finishes executing.
Which is not the case in your VLC
command. As long as VLC
is running, the shell/terminal will consider it still executing and will not move to the command after it but will rather wait for it to finish executing ( ie. in this case closing the VLC
window/instance ).
A workaround this is to send VLC
to the background and free the shell/terminal prompt for the next command in the script. Which can be done by adding &
after the command.
Notice:
Remove verbosity option -vvv
to avoid the script not exiting cleanly and completely.
If, however, you have to use the verbosity option -vvv
add nohup
before the second line as well like so:
#!/usr/bin/bash
nohup vlc -vvv http://10.0.0.113:8000/stream.mjpg --sout="#std{access=file,mux=ogg,dst=/home/whsrobotics/vlc_project/first_try.mp4}" &
sleep 10
killall vlc
This will append output to a file called nohup.out
in the current working directory if possible or to ~/nohup.out
otherwise and will allow the script to terminate cleanly and completely.
See man nohup for information.
Best of luck
timeout 10s
will save thesleep 10
call andkillall vlc
as well as the need for adding&
after the command. +1 for that : ) – Raffa Apr 10 '20 at 22:33