Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VLC screen capture using terminal

I'm attempting to capture my screen as video and found VLC to probably be the best solution. What I have to do is capture a specific application using terminal and then stop the capture as well. Right now, I can capture using terminal with the following command:

/Applications/VLC.app/Contents/MacOS/VLC -I dummy screen:// --screen-fps=25 --quiet --sout "#transcode{vcodec=h264,vb072}:standard{access=file,mux=mp4,dst="Desktop/vlc-output-terminal.mp4"}"

That's great, it works. The question is, how do I quit the recording using terminal? Right now, I'm having to do Control+C on the terminal to quit it. I've seen vlc://quit online, but I'm not sure how to use that command.

Also, does anyone know if it's possible to capture a specific application using VLC or is the whole screen the only option?

like image 838
intl Avatar asked Feb 28 '14 00:02

intl


2 Answers

How to NOT quit when recording

Ctrl+C kill process (in this case VLC) with signal SIGINT.

vlc://quit option will not work when you capture screen because stream is never-ending source.


Right way - RC (Remote Control)

You can connect to your VLC using a TCP socket or a UNIX socket.

  • TCP socket

    To be able to remote connect to your VLC using a TCP socket (telnet-like connetion), use --rc-host your_host:port. Then, by connecting (using telnet or netcat) to the host on the given port, you will get the command shell.

  • UNIX socket

    To use a UNIX socket (local socket, this does not work for Windows), use --rc-unix /path/to/socket. Commands can then be passed using this UNIX socket.

To enable remote control interface for VLC you will need to add options

--extraintf rc --rc-quiet


How to quit

  • TCP socket

    echo quit | nc your_host port

  • UNIX socket

    echo quit | nc -U /path/to/socket


    Example

    1. Execute VLC

      vlc \
      screen:// --one-instance \
      -I dummy --dummy-quiet \
      --extraintf rc \
      --rc-host localhost:8082 \
      --rc-quiet \
      --screen-follow-mouse \
      --screen-mouse-image="mouse_pointer.png" \
      --screen-left=0 --screen-top=0 --screen-width=800 --screen-height=600 \
      --no-video :screen-fps=15 :screen-caching=300 \
      --sout "#transcode{vcodec=h264,vb=800,fps=5,scale=1,acodec=none}:duplicate{dst=std{access=file,mux=mp4,dst='/Videos/screen.mp4'}}"
    2. Gracefully shutdown VLC

      echo quit | nc localhost 8082

      You can also use Python code below if you do not have nc (netcat) on your computer.

      import socket
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.connect(('localhost', 8082))
      s.sendall('quit\n')
      s.shutdown(socket.SHUT_WR)


How to capture specific application

You can't select which application to record but you can specify coordinate, width and height of the subscreen.

Options

  • --screen-top integer The top edge coordinate of the subscreen. Default value: 0
  • --screen-left integer The left edge coordinate of the subscreen. Default value: 0
  • --screen-width integer The width of the subscreen. Default value: <full screen width>
  • --screen-height integer The height of the subscreen. Default value: <full screen height>
like image 134
P̲̳x͓L̳ Avatar answered Oct 13 '22 00:10

P̲̳x͓L̳


Screen capture on terminal or iterm on Mac OS 2019:

Add an alias to you .bashrc or .zshrc for VLC:

alias vlc='/Applications/VLC.app/Contents/MacOS/VLC'

Then add this function to your .bashrc or .zshrc:

screencapture(){
vlc \
-I dummy screen://\
--dummy-quiet \
--screen-follow-mouse \
--screen-mouse-image="/Users/YOUR_HOME_DIR/Desktop/awesome.jpg" \
--screen-left=0 --screen-top=0 --screen-width=1280 --screen-height=720 \
--no-video :screen-fps=15 :screen-caching=300 \
--sout "#transcode{vcodec=h264,vb=800,fps=5,scale=1,acodec=none}:duplicate{dst=std{access=file,mux=mp4,dst='/Users/YOUR_HOME_DIR/Desktop/Screencapture $(date +%Y-%m-%d) at $(date +%H.%M.%S).mp4'}}"
}

Open a new terminal session and do: screencapture

When done do CTRl + C to stop the function.

That's it find the files in your Desktop folder example:

Screencapture 2019-01-04 at 09.57.42.mp4

Videos will be 1280x720 but you can customize this function however you like.

like image 25
Khalil Gharbaoui Avatar answered Oct 13 '22 00:10

Khalil Gharbaoui