如何正确地将模拟网络摄像头视频提供给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!
});
(提供视频文件时,它总是打"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中录制的二十秒电影文件尝试了相同的操作:
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
当同样失败时,我直接去 the它提供了示例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为我提供了 exact 相同的错误.
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将会崩溃",并建议您只需替换元数据即可解决此问题.实际上,我从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.
取决于您的测试要求-这可能对您就足够了.
Depending on what your test requirements - this may be sufficient for you.
ffmpeg -i oldfile.mp4 newfile.mjpeg
然后我使用以下方法进行了测试:
then I tested using:
google-chrome --use-fake-device-for-media-stream --use-file-for-fake-video-capture=newfile.mjpeg
导航到跟踪JS 后,我可以看到正在播放的视频.
After navigating to Tracking JS I could see the video being played back.
我希望对您有用!
这篇关于如何正确地将模拟网络摄像头视频提供给Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!