Linux下使用RecordMyDesktop进行屏幕录像
软件包的安装就不用说了。需要提及一点的是,在使用recordmydesktop之前,还需要安装pavucontrol(PulseAudio Volume Control)。否则,所得的视频只有图像而没有声音,无论怎么设置声音选项中的device都不行。pavucontrol简介如下:
PulseAudio Volume Control (pavucontrol) is a simple GTK+ based volume control tool (mixer) for the PulseAudio sound server. In contrast to classic mixer tools this one allows you to control both the volume of hardware devices and of each playback stream separately. It also allows you to redirect a playback stream to another output device without interrupting playback.
然后,运行pavucontrol,在其中的“Recording”选项卡中将声源选为“Monitor of Built-in Audio Analog Stereo”,则可以录制电脑上正在播放的音频。而若选择“Built-in Audio Analog Stereo”,则会录制由麦克风输入的声音。需注意的是,一定要先开启录音程序,这些设置选项才会出现。具体如下图所示:
接下来,就可以运行recordmydesktop命令录制屏幕了。其中所用参数的含义不言自明。需注意的是,–device选项的值为pulse。
recordmydesktop –display :0.0 -x 1728 -y 156 –width 1024 –height 768 –device pulse –overwrite -o wesnoth-under-the-burning-sun.ogv
录制bsnes游戏时,由于其默认的帧率为60,所以在下面的命令中,–fps选项也需要指定一下。同时,使用–s_quality选项设置了声音的质量为最高:
recordmydesktop –display :0.0 -x 1845 -y 278 –width 796 –height 581 –fps 60 –device pulse –s_quality 10 –overwrite -o bsnes.ogv
为了方便知晓需要被录像窗口的大小与位置,可以调用自己写的Sawfish函数display-window-paras来显示出窗口信息。该函数目前被绑定到了Super-e快捷键上。该函数的内容如下:
;; Display window position and dimension
(defun display-window-paras ()
“Display the position, dimension and group ID of the current window.”
(interactive)
(let* ((cur-win (input-focus))
(win-width (car (window-dimensions cur-win)))
(win-height (cdr (window-dimensions cur-win)))
(win-x (car (window-position cur-win)))
(win-y (cdr (window-position cur-win))))
(display-message
(concat “Name: ” (window-name cur-win) “\n”
“Dimension: ” (number->string win-width) “x” (number->string win-height) “\n”
“Position: ” (number->string win-x) “x” (number->string win-y) “\n”
“Group ID: ” (number->string (window-actual-group-id cur-win)))
alert-msg-attrib)))
(bind-keys window-keymap
“Super-e” `(display-window-paras))
执行display-window-paras后,其显示出的信息如下:
需要结束录像时,在终端窗口按Ctrl+c向recordmydesktop发现退出信号,在其保存完视频文件后便自动退出。接下来,需要将ogv格式的视频转化为常见的格式,如mp4。一个需要解决的问题是如何让声音与图像保持同步。目前是使用ffmpeg进行格式转换的(mencoder经试用后效果不好):
ffmpeg -i input_file.ogv -acodec libmp3lame -acodec ac3 -ab 128k -ac 2 -vcodec libx264 -preset slow -crf 22 -threads 4 output_file.mp4