如何正确向 Chrome 提供模拟网络摄像头视频? [英] How can I correctly provide a mock webcam video to Chrome?

查看:74
本文介绍了如何正确向 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.y4mmicrophone.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 文件,转到 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 会崩溃"/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆