用OpenBSD做screencasting

秀秀桌面并和大家分享一下自己的经验。

版主: lionux天地乾坤

回复
头像
acheng
锌 Zn
帖子: 575
注册时间: 2011-07-07 21:52

用OpenBSD做screencasting

帖子 acheng » 2017-02-26 17:24

看到一个老外的博客上写的。自己没试过。
以前在Linux上用ffmpeg的x11grab选项来录屏。录制过程没有问题,但是后期转码的时候做出来的mp4文件体积非常大。一直没找到好的解决办法(对ffmpeg以及视频的编码解码不太熟悉)。

http://eradman.com/posts/screencasting.html
作者: Eric Radman

Screencasting with OpenBSD


USB Audio
Any USB microphone should appear as a new audio device. Here is the dmesg for my mic by ART:
uaudio0 at uhub0 port 2 configuration 1 interface 0 "M-One USB" rev 1.10/0.01 addr 2
uaudio0: audio rev 1.00, 8 mixer controls
audio1 at uaudio0
audioctl can read off all of the specific characterisitcs of this device

代码: 全选

$ audioctl -f /dev/audio1 | grep record
mode=play,record
record.rate=48000
record.channels=1
record.precision=16
record.bps=2
record.msb=1
record.encoding=slinear_le
record.pause=0
record.active=0
record.block_size=1960
record.bytes=0
record.errors=0
Now test the recording from the second audio device using aucat(1)

代码: 全选

aucat -f rsnd/1 -o file.wav
If the device also has a headset audio can be played through the same device.

代码: 全选

aucat -f rsnd/1 -i file.wav
Screen Capture using Xvfb
The rate at which a framebuffer for your video card is a feature of the hardware and software your using, and it's often very slow. x11vnc will print an estimate of the banwidth for the system your running.
x11vnc
...
09/05/2012 22:23:45 fb read rate: 7 MB/sec
This is about 4fps. We can do much better by using a virtual framebuffer. Here I'm setting up a new screen, setting the background color, starting cwm and an instance of xterm

代码: 全选

Xvfb :1 -screen 0 720x540x16 &
DISPLAY=:1 xsetroot -solid steelblue &
DISPLAY=:1 cwm &
DISPLAY=:1 xterm +sb -fa Hermit -fs 14 &
Much better! Now we're up around 20fps.

代码: 全选

x11vnc -display :1  &
...
11/05/2012 18:04:07 fb read rate: 168 MB/sec
Make a connection to this virtual screen using raw encoding to eliminate time wasted on compression.

代码: 全选

vncviewer localhost -encodings raw
A test recording with sound then looks like this

代码: 全选

ffmpeg -f sndio -i snd/1 -y -f x11grab -r 12 -s 800x600 -i :1.0 -vcodec ffv1 ~/out.avi
Note: always stop the recording and playback using q, not Ctrl-C so that audio inputs are shut down properly.

Screen Capture using Xephyr

Xephyr is perhaps the easiest way to run X with a shadow framebuffer. This solution also avoids reading from the video card's RAM, so it's reasonably fast.

代码: 全选

Xephyr -ac -br -noreset -screen 800x600 :1 &
DISPLAY=:1 xsetroot -solid steelblue &
DISPLAY=:1 cwm &
DISPLAY=:1 xrdb -load ~/.Xdefaults &
DISPLAY=:1 xterm +sb -fa "Hermit" -fs 14 &
Capture works in exactally the same way. This command tries to maintain 12fps.

代码: 全选

ffmpeg -f sndio -i snd/1 -y -f x11grab -r 12 -s 800x600 -i :1.0 -vcodec ffv1 -acodec copy ~/out.avi
To capture keyboard and mouse input press Ctrl then Shift. This is very handy for using navigating a window manager in the nested X session.

Arranging Windows

I have sometimes found it helpful to launch applications and arrange them in a specific way. This will open up a web browser listing the current directory and position windows using xdotool

代码: 全选

DISPLAY=:1 midori "file:///`pwd`" &
sleep 2
DISPLAY=:1 xdotool search --name "xterm" windowmove 0 0
DISPLAY=:1 xdotool search --class "midori" windowmove 400 0
DISPLAY=:1 xdotool search --class "midori" windowsize 400 576
This will position the window precisely so that it appears to be in a tmux window on the right.

Audio/Video Sync
If you find that the audio is way out of sync with the video, you can ajust the start using the -ss before the audio input to specify the number of seconds to delay. My final recording command line, that delays the audio by 0.5 seconds, writing 12fps

代码: 全选

ffmpeg -ss 0.5 -f sndio -i snd/1 -y -f x11grab -r 12 -s 800x600 -i :1.0 -vcodec ffv1  -acodec copy ~/out.avi
Sharring a Terminal with tmux
If you're trying to record a terminal session, tmux is able to share a session. In this way a recording of an X framebuffer can be taken without even using the screen. Start by creating the session.

代码: 全选

tmux -2 -S /tmp/tmux0
Then on the remote side connect on the same socket

代码: 全选

tmux -2 -S /tmp/tmux0 attach
Taking Screenshots
Grabbing a screenshots on Xvfb server is easily accomplished with ImageMagick's import command

代码: 全选

DISPLAY=:1 import -window root screenshot.png
Audio Processing and Video Transcoding
The first step is to ensure that the clip begins and ends where you'd like it to. The following will make a copy of the recording starting at time 00:00 and ending at 09:45

代码: 全选

ffmpeg -i interactive-sql.avi \
    -vcodec copy -acodec copy
    -ss 00:00:00 -t 00:09:45
    interactive-sql-trimmed.avi
mv interactive-sql-trimmed.avi interactive-sql.avi
Setting the gain correctly is very important with an analog mixer, but if you're using a USB mic there may not be a gain option; simply record using it's built-in settings and then adjust the levels afterwards using a utility such as normalize. First extact the audio as a raw PCM file and then run normalize

代码: 全选

ffmpeg -i interactive-sql.avi -c:a copy -vn audio.wav
normalize audio.wav
Next merge the audio back in again

代码: 全选

ffmpeg -i interactive-sql.avi -i audio.wav \
    -map 0:0 -map 1:0 -c copy interactive-sql-normalized.avi
The final step is to compress the screencast for distribution. Encoding to VP8/Vorbis is easy:

代码: 全选

ffmpeg -i interactive-sql-normalized.avi -c:v libvpx -b:v 1M
    -c:a libvorbis -q:a 6 interactive-sql.webm
H.264/AAC is tricky. For most video players the color space needs to be set to yuv420p. The -movflags puts the index data at the beginning of the file to enable streaming/partial content requests over HTTP:

代码: 全选

ffmpeg -y -i interactive-sql-normalized.avi -c:v libx264 \
    -preset slow -crf 14 -pix_fmt yuv420p -movflags +faststart \
    -c:a aac -q:a 6 interactive-sql.mp4

回复

在线用户

正浏览此版面之用户: 没有注册用户 和 1 访客