VLC screen capture using terminal

南笙酒味 提交于 2019-11-29 00:40:03

问题


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?


回答1:


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>



回答2:


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.




回答3:


Important if you're on windows:

,... --rc-host localhost:8082

Doesn't work you'Ve to use local host ip otherwise it won't work. Use 127.0.0.1 instead:

,... --rc-host 127.0.0.1:8082



回答4:


I had to change quit command on my machine (WIN 10):

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



回答5:


Well there is a simple approach you don't need to deal with TCP sockets/Unix Sockets.

Step1: First open Vlc ->Tools ->Preferences Under Interface Tab make sure you check "Allow only one Instance".

If you don't find it using above method then search for instance in Advance Preference Tab Then check Allow only one instance.

This helps you to prevent starting new recording and it allows you to keep track the existing recording.

Step2: To start Recording use this command

vlc screen:// --qt-start-minimized :screen-fps=5 :run-time=30 :quiet :sout=#transcode{vcodec=h264,vb072}:standard{access=file,mux=mp4,dst="C:\Users\**admin**\Desktop\screencast.mp4"}

Step3: To save and Stop the existing record use

vlc://quit

Note: Make sure to check the path before you use this commands



来源:https://stackoverflow.com/questions/22084098/vlc-screen-capture-using-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!