Search code examples
bashterminalvlcscreen-capture

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?


Solution

  • 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>