歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下使用RecordMyDesktop進行屏幕錄像

Linux下使用RecordMyDesktop進行屏幕錄像

日期:2017/2/28 13:57:19   编辑:Linux教程

屏幕錄像的功能對於分享游戲攻略、演示電腦軟件的操作是必不可少的。在Windows下可能一般的用戶就下載盜版的商業軟件來做了。而在GNU/Linux操作系統下,則有現成的自由軟件可供使用,只不過沒有圖形界面罷了,但也同樣方便有效。更何況,這一點對於已經入門的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

Copyright © Linux教程網 All Rights Reserved