如何在 Linux 上录制 Skype 视频通话?

cur*_*guy 29 linux ubuntu video recording skype

我想使用 Skype 进行录制的视频采访,并且正在寻找一种可靠的工具来实现这一目标。

有什么东西不慢或不出错吗?

我正在运行(K)Ubuntu。

SHW*_*SHW 12

此命令将捕获您的完整桌面:因此,只要您想记录 Skype 对话(或其他任何内容),请使用此命令

ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg   
Run Code Online (Sandbox Code Playgroud)


小智 11

有一个软件recordMyDesktop http://recordmydesktop.sourceforge.net/about.php,你可以记录你想要的屏幕的任何部分。我用它来记录我的 Skype 会话。

sudo apt-get install recordmydesktop
Run Code Online (Sandbox Code Playgroud)

从主要渠道安装它。


lik*_*ise 9

背景

由于 ffmpeg 和可用的帮助文章数量(包括本站点),在通话期间(或在任何 X11 桌面活动期间)录制实时视频和音频并不是很困难。但是,如果您的目标是更高的质量,您将很快达到同时进行媒体抓取和压缩的简单方法的极限。因此,需要一种工具(或一组工具)能够:

  1. 将未压缩的通话记录到文件中以供进一步处理,认识到在拨打电话时我们只对音频感兴趣。
  2. 稍后以高质量压缩录制的通话。

以下 Bash 脚本(myrecmyrec-novideomyproc)是我在此任务中的尝试。我确信有更简洁的方法来编写这些脚本,但我正在学习 Bash 脚本(一旦我开始工作,我会非常满意,我可能会补充)。

先决条件

  1. ffmpeg
  2. pulseaudio
  3. skype

如果您的系统中不存在12不存在,请使用您首选的包管理器(我使用synaptic)安装它们。如需skype访问www.skype.com


录制无损视频和无损音频 - myrec

  1. 创建文本文件
  2. 将其另存为myrec(或任何适合您的名称)
  3. myrec通过发出以下命令使可执行文件:chmod +x myrec
  4. 将以下代码粘贴到其中并修改User settings部分以适合您的设置:

#!/bin/bash

echo "Record lossless audio and lossless video for further processing."
echo "Created file name always starts with temp_YYYYMMDD_HHMMSS."
echo "Syntax:"
echo "myrec [optional file description]"
echo "Optional file description is appended to the file name, with spaces replaced by underscores."
echo
echo

### User settings - adjust values to suit your system and needs

# I used to have the name of my webcam mic here, but that stopped working after a system update. "default" was the only fix I found. If you have more than one microphone connected, you may need to tell Pulseaudio which mic you want to be the default, I think pavucontrol is the utility for it.
# If you want to try supplying a name here, run pacmd, then within it the command list-sources will give you a list of possible microphones. Use the name field value without angle brackets.
microphone_audio_device="default"

# Run pacmd, within it the command list-sinks will give you a list of devices to choose from. Use the name field value without angle brackets.
speakers_audio_device="alsa_output.pci-0000_00_1b.0.analog-stereo.monitor"

# Select frame size.
# Some standard frame sizes for reference:
# wvga 852x480
# wxga 1366x768
# wsxga 1600x1024
# wuxga 1920x1200
# woxga 2560x1600
# wqsxga 3200x2048
# wquxga 3840x2400
# whsxga 6400x4096
# whuxga 7680x4800
frame_size="wsxga"

# Framerate in frames per second
framerate="30"

# Indicate which screen the video should be recorded from and an optional offset.
# For example:
# :0.0+10,20
# where 0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. 10 is the x-offset and 20 the y-offset of the frame, measured from the top left corner of the screen to the top left corner of the frame.
frame_position=":0.0"

# Include the trailing slash after target directory name.
# Expect a very large file!
target_directory="/target/directory/name/"

### End of user settings



record_command="ffmpeg -f pulse -thread_queue_size 512k -i $speakers_audio_device -f pulse -thread_queue_size 512k -i $microphone_audio_device -f x11grab -s $frame_size -r $framerate -thread_queue_size 512k -i $frame_position -map 0 -map 1 -map 2 -codec:a copy -codec:v libx264 -qp 0 -preset ultrafast"
temporary_file_prefix="temp_"

# The IFS (Internal Field Separator) system variable stores the character that separates command line arguments.
# We can use it to replace spaces with underscores.
temp=$IFS
IFS='_'
description="$*"
IFS=$temp

if [ $# -eq 0 ]; then
  $record_command $target_directory$temporary_file_prefix`date +%Y%m%d_%H%M%S`.mkv
else
  $record_command $target_directory$temporary_file_prefix`date +%Y%m%d_%H%M%S`_$description.mkv
fi

Run Code Online (Sandbox Code Playgroud)

仅录制音频由以下部分中的单独脚本处理。


只录制无损音频 - myrec-novideo

  1. 创建文本文件
  2. 将其另存为myrec-novideo(或任何适合您的名称)
  3. myrec-novideo通过发出以下命令使可执行文件:chmod +x myrec-novideo
  4. 将以下代码粘贴到其中并修改User settings部分以适合您的设置:

#!/bin/bash

echo "Record lossless audio for further processing."
echo "Created file name always starts with temp_YYYYMMDD_HHMMSS."
echo "Syntax:"
echo "myrec-novideo [optional file description]"
echo "Optional file description is appended to the file name, with spaces replaced by underscores."
echo
echo


### User settings - adjust values to suit your system

# I used to have the name of my webcam mic here, but that stopped working after a system update. "default" was the only fix I found. If you have more than one microphone connected, you may need to tell Pulseaudio which mic you want to be the default, I think pavucontrol is the utility for it.
# If you want to try supplying a name here, run pacmd, then within it the command list-sources will give you a list of possible microphones. Use the name field value without angle brackets.
microphone_audio_device="default"

# Run pacmd, within it the command list-sinks will give you a list of devices to choose from. Use the name field value without angle brackets.
speakers_audio_device="alsa_output.pci-0000_00_1b.0.analog-stereo.monitor"

# Include the trailing slash after target directory name.
# Expect a large file!
target_directory="/target/directory/name/"

### End of user settings



record_command="ffmpeg -f pulse -thread_queue_size 512k -i $speakers_audio_device -f pulse -thread_queue_size 512k -i $microphone_audio_device -map 0 -map 1 -codec:a copy -codec:a copy"
temporary_file_prefix="temp_"

# The IFS (Internal Field Separator) system variable stores the character that separates command line arguments.
# We can use it to replace spaces with underscores.
temp=$IFS
IFS='_'
description="$*"
IFS=$temp

if [ $# -eq 0 ]; then
  $record_command $target_directory$temporary_file_prefix`date +%Y%m%d_%H%M%S`.mkv
else
  $record_command $target_directory$temporary_file_prefix`date +%Y%m%d_%H%M%S`_$description.mkv
fi

Run Code Online (Sandbox Code Playgroud)


处理记录的文件 - myproc

  1. 创建文本文件
  2. 将其另存为myproc(或任何适合您的名称)
  3. myproc通过发出以下命令使可执行文件:chmod +x myproc
  4. 将以下代码粘贴到其中并修改User settings部分以适合您的设置:


#!/bin/bash

echo "Compress files recorded with myrec or myrec-novideo."
echo "For files to be processed they need to reside in the storage directory and start with temp_"
echo "The two audio tracks (mic and speakers) are mixed together into one new stream, but they are also available as separate tracks in the final file."

# Mixing is because players I know cannot play two audio tracks from the same file simultaneously.
# The mic also captures sounds produced by the speakers. It has two effects:
# 1. You can use this single track to hear both yourself (the mic) and whatever came out of your speakers. Personally I did not like the degraded quality of recorded speaker sounds, hence the direct recording off the sound card and mixing that with the mic track.
# 2. Speaker sounds recorded by the mic are slightly delayed when compared to the direct recording off the sound card. The mixed track is thus hard to listen to.
# I do have echo cancellation module loaded in Pulseaudio, perhaps there is something wrong with my configuration?

### User settings

# Indicate storage directory without the trailing slash
storage_directory="/storage/directory/name"

### End of user settings

# Any temp_ file may contain 3 streams (audio, audio, video) indexed as (0, 1, 2), or just 2 streams (audio, audio) indexed as (0, 1).
# A file temp2_ contains just one stream: both audio streams from temp_ mixed.
# The step with temp2_ is necessary as the mixing option (-filter_complex) is a global option (i.e. not stream-specific). Attempts at doing it all in one go prevent the separate tracks from being copied into the final file.

for f in $storage_directory/temp_*
do
  if [ -e ${f/temp_/} ]
  then
    # Do not overwrite an existing final file. Prevents unnecessary work when the script is run regularly as a cron job.
    echo "$f: A final file (without temp_) already exists. Skipping. If you want to reencode, please delete the final file manually."
  else
    # Variable g will contain the name of the second temporary file with both audio streams mixed into one.
    g=${f/temp_/temp2_}

    # Mixing mic and sound card tracks into one stream
    ffmpeg -i "$f" -map 0:0 -map 0:1 -filter_complex amix=inputs=2:duration=longest:dropout_transition=2 -codec:a libvorbis -n "$g"

    # Create the final file: copy the mixed audio stream from temp2_, add and compress both separate audio streams from temp_, compress at high quality the video stream from temp_.
    # The question mark in -map 0:2? tells ffmpeg to ignore the error if this stream (video) is missing. Allows this same script to be used for audio-only recordings.
    ffmpeg -i "$f" -i "$g" -map 1:0 -map 0:0 -map 0:1 -map 0:2? -codec:a:0 copy -codec:a:1 libvorbis -codec:a:2 libvorbis -codec:v libx264 -qp 18 -preset slow -threads 0 -n "${g/temp2_/}"

    # Delete temp2_
    rm "$g"
  fi
done


Run Code Online (Sandbox Code Playgroud)

由于ffmpeg的灵活性,myproc可以处理可能包含或不包含视频流的文件。


如何使用脚本

  1. 决定 Skype 的视频通话窗口将在您屏幕上的位置,并将窗口大小设置为所需的尺寸。Skype 会记住这个窗口设置,所以你只需要做一次。在随后的每次调用中,窗口都会以相同的大小出现在相同的位置。记得告诉myrec你的设置。通常,尝试将视频通话窗口放在网络摄像头附近的某个位置,以便对方有机会认为您是在看着他们的眼睛。
  2. 打开一个终端窗口。每当您希望开始录制时,请使用以下命令:

    • 录制音频和视频: . myrec some description
    • 仅录制音频: . myrec-novideo some description

    some description在两个脚本中都是可选的。您可以使用Tab键扩展脚本名称以节省一些输入。 ffmpeg将开始录制到名为 的文件temp_YYYYMMDD_HHMMSS_some_description.mkv,其中YYYYMMDD_HHMMSS是录制的日期和时间。

  3. 准备好停止后q,在ffmpeg正在录制的终端窗口按。
  4. 运行. myproc以处理(压缩)文件。您可以手动执行此操作,也可以设置一份cron工作以在您离开时执行此操作。
  5. 一旦您确认压缩按预期进行,请删除该temp_文件。


问题

  1. 无法按名称指定麦克风,只能使用特殊值default。我曾经在那里有麦克风名称,但此设置在系统更新后停止工作。它可能仅限于我的设置,或仅限于pulseaudio.
  2. 麦克风音频包含我的声音和扬声器的声音。扬声器发出的声音稍微落后于直接从声卡上录制的音频流。Pulse的回声消除模块已加载,但我认为它只是为了消除我自己的声音回声。问题是,当麦克风音频与声卡音频混合时,轻微的延迟会使产生的流难以收听。有谁知道如何防止麦克风录制扬声器的声音?


最后的笔记

我希望你发现这些工具很有用。我期待听到您对改进和评论的想法。

  • 哇。如果您没有一个 git 帐户,您可能想要启动一个 git 帐户并将这些脚本保留在那里。 (2认同)

小智 5

Open Broadcaster Software (OBS) Studio 将所有这些要求整合到一个易于使用的前端中。

它是开源的,跨平台的:

对于 Ubuntu 15.04 及更高版本:

sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt-get update && sudo apt-get install obs-studio ffmpeg
Run Code Online (Sandbox Code Playgroud)

对于其他发行版/早期的 Ubuntu 版本,请查看 git wiki