如何向 Chrome 正确提供模拟网络摄像头视频? [英] How can I correctly provide a mock webcam video to Chrome?
问题描述
我正在尝试在 Chrome 中为需要网络摄像头馈送才能运行的产品运行端到端测试.据我了解,这意味着使用 --use-file-for-fake-video-capture="/path/to/video.y4m"
命令行参数向 Chrome 提供虚假的网络摄像头视频.然后它会将其用作网络摄像头视频.
I'm trying to run end-to-end testing in Chrome for a product that requires a webcam feed halfway through to operate. From what I understand this means providing a fake webcam video to Chrome using the --use-file-for-fake-video-capture="/path/to/video.y4m"
command line argument. It will then use that as a webcam video.
但是,无论我提供什么 y4m 文件,在这些条件下运行的 Chrome 都会出现以下错误:
However, no matter what y4m file I provide, I get the following error from Chrome running under these conditions:
DOMException: Could not start video source
{
code: 0,
message: "Could not start video source",
name: "NotReadableError"
}
值得注意的是,我可以使用 --use-file-for-fake-audio-capture
提供一个很好的音频文件,Chrome 可以很好地使用它.视频一直是我的症结所在.
Notably I can provide an audio file just fine using --use-file-for-fake-audio-capture
and Chrome will work with it well. The video has been my sticking point.
此错误来自以下简单的 mediaDevices 请求:
This error comes out of the following straightforward mediaDevices request:
navigator.mediaDevices.getUserMedia({ video: true, audio: true })
.then(data => {
// do stuff
})
.catch(err => {
// oh no!
});
(当提供视频文件时,这总是会遇到哦不!"分支.)
(This always hits the "oh no!" branch when a video file is provided.)
我一直在使用以下命令行参数运行 Chrome(为了可读性添加了换行符),并且我使用的是 Mac,因此 open
命令:
I've been running Chrome with the following command line arguments (newlines added for readability), and I'm using a Mac hence the open
command:
open -a "Google Chrome" --args
--disable-gpu
--use-fake-device-for-media-stream
--use-file-for-fake-video-capture="~/Documents/mock/webcam.y4m"
--use-file-for-fake-audio-capture="~/Documents/mock/microphone.wav"
webcam.y4m
和 microphone.wav
是从我录制的视频文件中生成的.
webcam.y4m
and microphone.wav
were generated from a video file I recorded.
我首先使用浏览器的 MediaRecorder 录制了一个 20 秒的 mp4 视频,下载了结果,并使用以下命令行命令进行了转换:
I first recorded a twenty-second mp4 video using my browser's MediaRecorder, downloaded the result, and converted it using the following command line commands:
ffmpeg -y -i original.mp4 -f wav -vn microphone.wav
ffmpeg -y -i original.mp4 webcam.y4m
当这不起作用时,我使用我在 Quicktime 中录制的 20 秒电影文件尝试了同样的方法:
When this didn't work, I tried the same using a twenty-second movie file I recorded in Quicktime:
ffmpeg -y -i original.mov -f wav -vn microphone.wav
ffmpeg -y -i original.mov webcam.y4m
当那也失败时,我直接去了解释虚假视频捕获的 Chromium 文件,转到示例 y4m 文件列表它提供,并下载了祖母文件,并将其作为命令行参数提供给 Chrome:
When that also failed, I went straight to the Chromium file that explains fake video capture, went to the example y4m file list it provided, and downloaded the grandma file and provided that as a command line argument to Chrome instead:
open -a "Google Chrome" --args
--disable-gpu
--use-fake-device-for-media-stream
--use-file-for-fake-video-capture="~/Documents/mock/grandma_qcif.y4m"
--use-file-for-fake-audio-capture="~/Documents/mock/microphone.wav"
Chrome 在所有这些情况下为我提供了完全相同的错误.
Chrome provides me with the exact same error in all of these situations.
Chrome 没有错误处理 mediaDevices 请求的唯一时间是我完全省略了视频:
The only time Chrome doesn't error out with that mediaDevices request is when I omit the video completely:
open -a "Google Chrome" --args
--disable-gpu
--use-fake-device-for-media-stream
--use-file-for-fake-audio-capture="~/Documents/mock/microphone.wav"
对 C420mpeg2 的核算
TestRTC 表明如果我给它一个 C420mpeg2<,Chrome 会崩溃"/code> 文件,并建议只需替换元数据即可解决问题.事实上,我从 ffmpeg 生成的视频文件给了我以下标题:
Accounting for C420mpeg2
TestRTC suggests Chrome will "crash" if I give it a C420mpeg2
file, and recommends that simply replacing the metadata fixes the issue. Indeed the video file I generate from ffmpeg gives me the following header:
YUV4MPEG2 W1280 H720 F30:1 Ip A1:1 C420mpeg2 XYSCSS=420MPEG2
Chrome 在使用此文件运行时实际上并未崩溃,我只是收到上述错误.如果我按照 TestRTC 的建议将视频文件编辑为以下标题,我会遇到相同的情况:
Chrome doesn't actually crash when run with this file, I just get the error above. If I edit the video file to the following header though per TestRTC's recommendations I get the same situation:
YUV4MPEG2 W1280 H720 F30:1 Ip A1:1 C420 XYSCSS=420MPEG2
在这些情况下,视频文件仍然给我上述错误.
The video file still gives me the above error in these conditions.
我应该如何为此命令行参数向 Chrome 提供视频文件?
How should I be providing a video file to Chrome for this command line argument?
我应该如何录制或创建视频文件?
How should I be recording or creating the video file?
我应该如何将其转换为 y4m?
How should I convert it to y4m?
推荐答案
阅读您提供的链接后,我注意到我们还可以提供 mjpeg.
After reading the link you provided I noticed that we can also provide an mjpeg.
取决于您的测试要求 - 这对您来说可能就足够了.作为安装了 ffmpeg 的终端命令:
Depending on what your test requirements - this may be sufficient for you. As a terminal command with ffmpeg installed:
ffmpeg -i oldfile.mp4 newfile.mjpeg
然后我通过使用以下命令从终端运行 Google Chrome 进行了测试:
then I tested by running Google Chrome from the terminal using:
google-chrome --use-fake-device-for-media-stream --use-file-for-fake-video-capture=newfile.mjpeg
导航到 Tracking JS 后,我可以看到正在播放的视频.
After navigating to Tracking JS I could see the video being played back.
希望对你有用!
这篇关于如何向 Chrome 正确提供模拟网络摄像头视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!