VLC screen capture using terminal

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.


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>