Merge pull request #30058 from wxy/20230828-Using-Your-Phone-as-Camera-and-Mic-in-Ubuntu-Linux

ATRP:published/20230828 Using Your Phone as Camera and Mic in Ubuntu Linux.md
This commit is contained in:
Xingyu.Wang 2023-09-07 15:58:10 +08:00 committed by GitHub
commit 685e82c8db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 221 additions and 232 deletions

View File

@ -0,0 +1,221 @@
[#]: subject: "Using Your Phone as Camera and Mic in Ubuntu Linux"
[#]: via: "https://itsfoss.com/ubuntu-phone-camera-mic/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lujun9972"
[#]: translator: "ChatGPT"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-16168-1.html"
将手机作为你的 Linux 桌面的摄像头和麦克风
======
![][0]
> 当你的桌面系统缺乏网络摄像头和专用麦克风时,你可以考虑使用智能手机。这里将教你如何在 Ubuntu Linux 中完成这个设置。
我和许多 Linux 用户一样,使用的是台式机。相较于笔记本电脑,并没有预装摄像头和麦克风。
若要获得与现代智能手机相媲美的画质,你可能需要购买一款高端的网络摄像头。
在此教程中,我将逐步指导你如何将你的手机用作麦克风和摄像头,这将非常适用于在线会议场景。
### Ubuntu 下使用手机的摄像头和麦克风
> 🚧 本教程采用第三方网站 <https://vdo.ninja/> 来托管音频和视频,因此,这并不是一项完全的开源方案。
我将指引你完成以下步骤:
* 安装 OBS (如果你还未安装)
* 通过 `vdo.ninja` 生成邀请链接
* 设置虚拟音频线缆(用于音频输出)
* 配置 OBS 以便从 `vdo.ninja` 重定向音视频流
首先,我们来看第一步。
> 📋 虽然本教程是在 Ubuntu 系统下完成的,但我相信,这些同样可以在其他 Linux 发行版上实现。你只需为你的发行版安装所需的包即可。你可以自行尝试,看看效果如何。
#### 1、在 Ubuntu 中安装 OBS
OBSOpen Broadcaster Software是众多用于录制和直播视频的优秀软件之一许多直播者都选择使用 OBS 在各个数字化平台进行直播。
幸运的是OBS 已经包含在 Ubuntu 的默认仓库中,你可以通过以下命令来安装:
```
sudo apt install obs-studio
```
#### 2、通过 VDO.ninja 生成直播邀请
在这一节,我将教你如何在 vdo.ninja 上生成一个直播邀请,进而从你的手机上开始直播音频和视频。
首先,访问 [VDO.ninja][1] 并点击 “<ruby>创建可重用的邀请<rt>Create Reusable Invite</rt></ruby>”:
![][2]
接下来你会看到很多选项,包括质量设置,添加视频效果等。我推荐你使用默认设置,因为高质量视频需要更快的处理速度和更多的带宽。
为了创建一个链接,你只需要点击 “<ruby>生成邀请链接<rt>GENERATE THE INVITE LINK</rt></ruby>” 按钮:
![][3]
完成后你会看到:
* 你需要用你的手机扫描的二维码(当然,你也可以选择使用链接)。
* OBS 的链接。
**稍后我会在本教程中继续介绍 OBS 配置,所以请暂时别关闭这个窗口。**
首先,用你的手机扫描二维码,它会将你跳转到 VDO.ninja 的另一个页面,此时你需要:
* 选择 “<ruby>共享你的相机<rt>Share your Camera</rt></ruby>” 选项。
* 在视频源中选择使用前置或后置摄像头(默认为前置)。
* 点击 “<ruby>开始<rt>Start</rt></ruby>” 按钮后,它将开始在 OBS 连接的页面上进行直播。
![][4]
#### 3、在 Ubuntu 上为 OBS 配置虚拟线缆
> 🚧 这种设置方法仅适用于 PulseAudio并且在重启系统后虚拟线缆将被撤销。
首先,我们来解释一下“<ruby>虚拟线缆<rt>virtual cable</rt></ruby>”的概念,以及为何我们需要它来将手机做为摄像头和麦克风使用。
虚拟线缆是一种用于将音频流从一个应用传输到另一个应用的软件。
然而遗憾的是,它只支持 Windows 和 macOS。
啥?!那我为什么还要介绍这个呢?
答案其实很简单。我找到了一种变通方法,你可以在**当前的会话**中获得与虚拟线缆类似的功能。
要设置虚拟线缆,首先需要使用以下命令加载 `module-null-sink` 模块:
```
pactl load-module module-null-sink sink_name=Source
```
然后,执行下面的命令创建一个名为 `VirtualMic` 的虚拟音源:
```
pactl load-module module-virtual-source source_name=VirtualMic master=Source.monitor
```
这两个命令将返回一些数字,但无需对其过多关注。
接下来,前往系统“<ruby>设置<rt>Settings</rt></ruby>”,找到“<ruby>声音<rt>Sound</rt></ruby>”部分的设置:
![][5]
然后进入 “<ruby>输入<rt>Input</rt></ruby>” 部分,在此你会找到选择输入设备的选项。
将 “VirtualMic” 设为输入设备:
![][6]
这样就设置完了!
不过,如我之前所述,一旦你重启电脑,虚拟音频的设置就会被撤销,如果你打算经常使用手机作为摄像头和麦克风,这可能会造成一定的不便。
为了解决这个问题,你可以为这两个命令 [创建别名][7],例如,为命令创建别名:`vc1` 和 `vc2`
完成后,你就可以像这样 [一次执行两个命令][8]`vc1 && vc2`。
#### 4、配置 OBS 从手机直播音视频
开始阶段,你需要打开我之前告诉你不要关闭的 VDO.ninja 标签页,并复制 OBS 链接:
![][9]
然后启动 OBS在 “<ruby><rt>Sources</rt></ruby>” 区域你会看到一个 “➕(加号)”按钮,点击这个按钮并选择 “<ruby>浏览<rt>Browser</rt></ruby>”。
接着会弹出一个对话框,让你创建或选择一个源,你只需按下 “OK” 按钮即可:
![][10]
最后,将已经复制的链接粘贴进 “URL” 字段:
![][11]
然后你将能看到 OBS 正在使用你手机的摄像头:
![][12]
不过为了从你的手机接收音频,还有一些额外步骤需要执行。
首先,在菜单中点击 “<ruby>文件<rt>File</rt></ruby>” 并选择 “<ruby>设置<rt>Settings</rt></ruby>”:
![][13]
在出现的设置选项中选择 “<ruby>音频<rt>Audio</rt></ruby>”,然后寻找到 “<ruby>高级<rt>Advanced</rt></ruby>” 区域。
在 “高级” 区域里,你能找到 “<ruby>监控设备<rt>Monitoring Device</rt></ruby>” 的选项,这里你需要选择 “Source Audio/Sink sink”
![][14]
点击 “<ruby>应用<rt>Apply</rt></ruby>” 保存更改。
对于大部分用户,此时音频应该已经能够正常工作了。如果你的音频依然无法工作,那么你可以按照以下步骤操作。
在 “<ruby>音频混音器<rt>Audio Mixer</rt></ruby>” 区域,可能显示的是 “<ruby>浏览<rt>Browser</rt></ruby>” 或 “<ruby>桌面音频<rt>Desktop Audio</rt></ruby>”,也可能两者都显示。
点击 “桌面音频” 或 “浏览” 旁边的三个点(在我这个例子中,是 “桌面音频”),并选择 “<ruby>高级音频属性<rt>Advanced Audio Properties</rt></ruby>”:
![][15]
然后,对于 “浏览” 和 “桌面音频”,都选择 “<ruby>监控和输出<rt>Monitor and Output</rt></ruby>”:
![][16]
这样就可以了!现在你可以从你的手机上享受摄像头和麦克风的功能了。
#### 5、测试所有设置
为了测试这个设置,我在我们读书俱乐部的周会上用我的手机做为摄像头和麦克风,效果极佳。
![][17]
你可以看到,上图显示摄像头和麦克风都在正常工作,这真的让我笑容满面 😸。
视频质量会取决于你的网络带宽,所以在开始重要的会议前,确保你有稳定的网络连接。
### 结语
作为一个没有摄像头和麦克风的台式计算机用户,我必须依靠笔记本或手机来参加工作会议,这让我感到非常烦躁。
需要注意的是,每次重启机器后,你都需要重新配置虚拟线缆,但这并不费时,因为只需要执行两条命令即可。
我已经多次使用这种解决方案,每一次都顺利运行。我真的希望你也能得到同样的结果。
*题图MJ/223b56b7-ffcc-4311-bfa6-8a25bfd5ad11*
--------------------------------------------------------------------------------
via: https://itsfoss.com/ubuntu-phone-camera-mic/
作者:[Sagar Sharma][a]
选题:[lujun9972][b]
译者ChatGPT
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lujun9972
[1]: https://vdo.ninja/
[2]: https://itsfoss.com/content/images/2023/08/Click-on-create-reusable-Invite-button.png
[3]: https://itsfoss.com/content/images/2023/08/Click-on-the-generate-invite-link-button.png
[4]: https://itsfoss.com/content/images/2023/08/setup-vdo.ninja-on-phone.png
[5]: https://itsfoss.com/content/images/2023/08/Open-sound-settings.png
[6]: https://itsfoss.com/content/images/2023/08/Choose-virtul-mic-as-an-audio-input-in-Linux-to-use-phone-s-camera-and-mic-.png
[7]: https://linuxhandbook.com/linux-alias-command/
[8]: https://linuxhandbook.com/run-multiple-commands/
[9]: https://itsfoss.com/content/images/2023/08/Copy-link-for-OBS.png
[10]: https://itsfoss.com/content/images/2023/08/Create-new-source-for-streaming-in-OBS-to-use-camera-and-mic-of-your-phone-in-Ubuntu-1.png
[11]: https://itsfoss.com/content/images/2023/08/Paste-VDO.ninja-link-in-OBS-to-use-your-phone-s-camera-and-mic-in-Ubuntu-Linux.png
[12]: https://itsfoss.com/content/images/2023/08/Stream-audio-and-video-from-your-phone-to-Ubuntu-Linux-using-OBS.png
[13]: https://itsfoss.com/content/images/2023/08/Open-settings-in-OBS.png
[14]: https://itsfoss.com/content/images/2023/08/Choose-virtual-audio-in-OBS-to-use-phone-s-mic-in-ubuntu-Linux.png
[15]: https://itsfoss.com/content/images/2023/08/Choose-advanced-option-to-use-audio-from-phone-in-Ubuntu-linux-using-OBS.png
[16]: https://itsfoss.com/content/images/2023/08/Enable-monitor-and-output-for-OBS.png
[17]: https://itsfoss.com/content/images/2023/08/Using-phone-s-camera-and-mic-in-Ubuntu-Linux.png
[0]: https://img.linux.net.cn/data/attachment/album/202309/07/155221kxjpb8j8j998xj50.jpg

View File

@ -1,232 +0,0 @@
[#]: subject: "Using Your Phone as Camera and Mic in Ubuntu Linux"
[#]: via: "https://itsfoss.com/ubuntu-phone-camera-mic/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Using Your Phone as Camera and Mic in Ubuntu Linux
======
Like many other Linux users, I use a desktop and unlike a laptop, you don't get a camera and mic pre-installed.
And you have to invest in a premium webcam to match the quality of your modern smartphone.
Well, in this tutorial, I will walk you through step-by-step how you can use your phone as a mic and camera which can be used in online meetings.
### Use the phone's camera and mic in Ubuntu
🚧
This tutorial utilizes a third-party website <https://vdo.ninja/> to host audio and video. Thus, it is not a completely open source solution.
Here, I will guide you through the following:
* Installation of OBS (if you haven't)
* Generate invite through `vdo.ninja`
* Setup virtual audio cable (for audio output)
* Configure OBS to redirect audio and video from `vdo.ninja`
So let's start with the first one.
📋
I have used Ubuntu in the tutorial. However, I believe that the same can be achieved on other distributions as well. You just have to install the needed packages for your distro and it should work. I let you experiment.
#### 1\. Install OBS in Ubuntu
OBS (Open Broadcaster Software) is one of the best software for recording and streaming videos and most streamers use OBS to live stream on digital platforms.
The good thing is OBS is available in the default repository of Ubuntu and can be installed using the following command:
```
sudo apt install obs-studio
```
#### 2\. Generate an invite through VDO.ninja
In this section, I will show you how you can generate an invite to stream your audio and video over vdo.ninja and how you can start streaming from your phone.
First, go to [VDO.ninja][1] and click on `Create Reusable Invite`:
![][2]
It will show you multiple options such as quality settings, adding video effects, etc. I recommend using the default settings as you may need faster processing and more bandwidth for high-quality videos:
And to create a link, all you have to do is click on `GENERATE THE INVITE LINK` button:
![][3]
And it will show you the following:
* A QR code that you have to scan through your phone (alternatively, you can also use the link).
* Link for the OBS.
**I will cover the OBS part later on this tutorial so please don't close the window.**
First, scan the QR code from your smartphone and it will redirect you to another page of the VDO.ninja where you have to select the following:
* Select `Share your Camera` option.
* You can choose a front or rear camera from the video source (the front will be selected by default).
* Hit the `Start` button and it will start the streaming on the OBS link.
![][4]
#### 3\. Setup a virtual cable for OBS on Ubuntu
🚧
The method will only work with the PulseAudio and the virtual cable will be flushed out once you reboot.
First, let's talk about what is virtual cable and why you need it to use your phone as a camera and mic.
The virtual cable is software used for transfering audio streams from one application to another.
But the sad part is that it is only available for Windows and macOS.
Hmmmm???? So why am I writing this?
The answer is simple. I found a workaround to this where you can have the same functionality as a virtual cable for **the current session**.
To set up a virtual cable, first, you have to load the `module-null-sink` module using the following command:
```
pactl load-module module-null-sink sink_name=Source
```
And then, execute the given command to create a virtual audio source named `VirtualMic`:
```
pactl load-module module-virtual-source source_name=VirtualMic master=Source.monitor
```
Both commands will return some numbers that you don't have to worry about.
Now, go to the system settings, and there you will find settings for sound:
![][5]
Next, go to the `Input` section and there, you will find the option to choose an input device.
Chose `VirtualMic` as an input device:
![][6]
That's it!
But as I said earlier, once you reboot the effect of virtual audio will be flushed and if you regularly want to use your phone as a camera and mic, it can be inconvenient.
To cater to this, you can [create an alias][7] for those two commands. For example, you can create aliases for both commands: vc1 and vc2.
Once done, you can [execute both commands at once][8] like this: `vc1 && vc2`.
#### 4\. Setup OBS to stream audio and video from the phone
First, open the VDO.ninja tab that I told you not to close and copy the OBS link:
![][9]
Once copied, open OBS, and under the `Sources` section, you will find a (plus) button. Click that button and select `Browser`.
It will open a little prompt to create/select a source. Simply press the `OK` button:
![][10]
Finally, paste the link in the `URL` field:
![][11]
And soon, you will see OBS using your phone's camera:
![][12]
But there are a few extra steps to get audio from your phone.
First, click on the `File` and choose `Settings`:
![][13]
There, Choose `Audio` and look for the `Advanced` section.
In the Advanced section, you will find an option for `Monitoring Device` and there you have to choose `Souce Audio/Sink sink`:
![][14]
Apply the changes.
For most users, the audio should be working by now. But if yours don't then here's how you can make it work.
In the Audio Mixer section, it will be either the `Browser` or the `Desktop Audio` , or you may also see both of them.
Click on those three dots for Desktop Audio or Browser (in my case, it's Desktop Audio) and choose `Advanced Audio Properties`:
![][15]
From there, choose `Monitor and Output` for the Browser and Desktop Audio:
![][16]
And that's it! You can enjoy the camera and mic from your phone.
#### 5\. Test the whole setup
To test this, I used my phone as a camera and mic in our book club's weekly meeting and it worked flawlessly.
![][17]
As you can see, the above image indicates a working mic and camera (which brought a smile to my face 😸).
The video quality depends on the internet bandwidth so make sure you have a good connection before starting an important meeting.
### Wrapping Up...
I'm one of those desktop users who don't have access to a camera and mic and have to rely on a laptop or mobile for office meetings and I was irritated by that.
Remember, you have to create a virtual cable every time you reboot, but it won't take much time as it takes two command executions.
Have used this solution multiple times and it worked every time I put it to the test. I really hope you will have the same output.
--------------------------------------------------------------------------------
via: https://itsfoss.com/ubuntu-phone-camera-mic/
作者:[Sagar Sharma][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lujun9972
[1]: https://vdo.ninja/
[2]: https://itsfoss.com/content/images/2023/08/Click-on-create-reusable-Invite-button.png
[3]: https://itsfoss.com/content/images/2023/08/Click-on-the-generate-invite-link-button.png
[4]: https://itsfoss.com/content/images/2023/08/setup-vdo.ninja-on-phone.png
[5]: https://itsfoss.com/content/images/2023/08/Open-sound-settings.png
[6]: https://itsfoss.com/content/images/2023/08/Choose-virtul-mic-as-an-audio-input-in-Linux-to-use-phone-s-camera-and-mic-.png
[7]: https://linuxhandbook.com/linux-alias-command/
[8]: https://linuxhandbook.com/run-multiple-commands/
[9]: https://itsfoss.com/content/images/2023/08/Copy-link-for-OBS.png
[10]: https://itsfoss.com/content/images/2023/08/Create-new-source-for-streaming-in-OBS-to-use-camera-and-mic-of-your-phone-in-Ubuntu-1.png
[11]: https://itsfoss.com/content/images/2023/08/Paste-VDO.ninja-link-in-OBS-to-use-your-phone-s-camera-and-mic-in-Ubuntu-Linux.png
[12]: https://itsfoss.com/content/images/2023/08/Stream-audio-and-video-from-your-phone-to-Ubuntu-Linux-using-OBS.png
[13]: https://itsfoss.com/content/images/2023/08/Open-settings-in-OBS.png
[14]: https://itsfoss.com/content/images/2023/08/Choose-virtual-audio-in-OBS-to-use-phone-s-mic-in-ubuntu-Linux.png
[15]: https://itsfoss.com/content/images/2023/08/Choose-advanced-option-to-use-audio-from-phone-in-Ubuntu-linux-using-OBS.png
[16]: https://itsfoss.com/content/images/2023/08/Enable-monitor-and-output-for-OBS.png
[17]: https://itsfoss.com/content/images/2023/08/Using-phone-s-camera-and-mic-in-Ubuntu-Linux.png