bash 使用终端的 VLC 屏幕截图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22084098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VLC screen capture using terminal
提问by intl
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:
我试图将我的屏幕捕获为视频,发现 VLC 可能是最好的解决方案。我要做的是使用终端捕获特定的应用程序,然后也停止捕获。现在,我可以使用终端使用以下命令进行捕获:
/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+Con the terminal to quit it. I've seen vlc://quit
online, but I'm not sure how to use that command.
太好了,它有效。问题是,如何使用终端退出录音?现在,我必须在终端上执行Control+C才能退出它。我在vlc://quit
网上看到过,但我不确定如何使用该命令。
Also, does anyone know if it's possible to capture a specific application using VLC or is the whole screen the only option?
另外,有谁知道是否可以使用 VLC 捕获特定应用程序,还是整个屏幕是唯一的选择?
回答by P??x?L?
How to NOTquit when recording
录音时如何不退出
Ctrl+Ckill process (in this case VLC) with signal SIGINT
.
Ctrl+C使用信号杀死进程(在本例中为 VLC)SIGINT
。
vlc://quit
option will not work when you capture screen because stream is never-ending source.
vlc://quit
捕获屏幕时选项将不起作用,因为流是永无止境的源。
Right way - RC (Remote Control)
正确的方式- RC([R表情C ^ONTROL)
You can connect to your VLC using a TCP socket
or a UNIX socket
.
您可以使用 aTCP socket
或 a连接到您的 VLC 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.
TCP套接字
为了能够使用 TCP 套接字(类似于 telnet 的连接)远程连接到您的 VLC,请使用--rc-host your_host:port。然后,通过连接(使用 telnet 或 netcat)到给定端口上的主机,您将获得命令外壳。
UNIX 套接字
要使用 UNIX 套接字(本地套接字,这不适用于 Windows),请使用--rc-unix /path/to/socket。然后可以使用此 UNIX 套接字传递命令。
To enable remote controlinterface for VLC you will need to add options
要为 VLC启用远程控制界面,您需要添加选项
--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
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'}}"
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)
TCP套接字
回声退出 | nc your_host 端口
UNIX 套接字
回声退出 | nc -U /path/to/socket
例子
执行 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'}}"
正常关闭 VLC
echo quit | nc localhost 8082
Python
如果您的计算机上没有nc (netcat),您也可以使用下面的代码。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.
您无法选择要录制的应用程序,但可以指定子屏幕的坐标、宽度和高度。
--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>
--screen-top integer
子屏幕的顶边坐标。默认值:0--screen-left integer
子屏幕的左边缘坐标。默认值:0--screen-width integer
子屏幕的宽度。默认值:<全屏宽度>--screen-height integer
子屏幕的高度。默认值:<全屏高度>
回答by Khalil Gharbaoui
Screen captureon terminal or iterm on Mac OS 2019:
Mac OS 2019终端或 iterm 上的屏幕截图:
Add an alias to you .bashrc
or .zshrc
for VLC:
为您.bashrc
或.zshrc
VLC添加别名:
alias vlc='/Applications/VLC.app/Contents/MacOS/VLC'
alias vlc='/Applications/VLC.app/Contents/MacOS/VLC'
Then add this function to your .bashrc
or .zshrc
:
然后将此函数添加到您的.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
打开一个新的终端会话并执行: screencapture
When done do CTRl + C
to stop the function.
完成CTRl + C
后停止该功能。
That's it find the files in your Desktop folder example:
这就是在您的桌面文件夹示例中找到文件:
Screencapture 2019-01-04 at 09.57.42.mp4
Screencapture 2019-01-04 at 09.57.42.mp4
Videos will be 1280x720 but you can customize this function however you like.
视频将为 1280x720,但您可以根据自己的喜好自定义此功能。
回答by Prashanth Adurugatla
Well there is a simple approach you don't need to deal with TCP sockets/Unix Sockets.
好吧,有一种简单的方法不需要处理TCP 套接字/Unix 套接字。
Step1:First open Vlc ->Tools ->Preferences Under Interface Tabmake sure you check "Allow only one Instance".
步骤 1:首先打开 Vlc -> 工具 ->界面选项卡下的首选项,确保选中“仅允许一个实例”。
If you don't find it using above method then search for instancein Advance Preference TabThen 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
步骤 2:要开始录制,请使用此命令
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
Step3:保存和停止现有记录使用
vlc://quit
Note: Make sure to check the path before you use this commands
注意:使用此命令前请务必检查路径
回答by NetworkSys Co. Ltd
Important if you're on windows:
重要的是,如果你在 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:
不起作用,您必须使用本地主机 ip,否则它将不起作用。使用 127.0.0.1 代替:
,... --rc-host 127.0.0.1:8082
回答by user2462619
I had to change quit command on my machine (WIN 10):
我不得不在我的机器上更改退出命令(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)