本文介绍了如何从videofile创建MediaStream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数Mediastream示例都是webCam-stream的解释。但是我需要从本地视频文件(.webm或mp4)创建MediaStream。请告诉我。

Most of the Mediastream examples are explanation by webCam-stream.but I need to create MediaStream from local videofile(.webm or mp4).Please tell me.

推荐答案

2017年5月4日更新 captureStream 现在Chrome和Firefox都支持API。

Updated at May 04, 2017: captureStream API are now supported both on Chrome and Firefox.

var stream_from_WebM_or_Mp4_File = videoTag.captureStream();
var stream_from_Canvas2D         = canvasTag.captureStream(25);

参数25是帧率。

现在,您可以使用RTCPeerConnection API或使用MediaRecorder API记录来共享结果流。

Now you can share the resulting stream using either RTCPeerConnection API or record using MediaRecorder API.

请检查类似的答案:

两种可能性:

1)captureStreamUntilEnded /

仅在Firefox上支持 mozCaptureStreamUntilEnded

It is supported only on Firefox as "mozCaptureStreamUntilEnded".

2)MediaSource API

chrome和firefox都支持MediaSource API;但是,它不是实时媒体流。

MediaSource APIs are supported both on chrome and firefox; however, it isn't a realtime media-stream.

你可以做的是读取文件块;使用WebSockets,socket.io或WebRTC数据通道等任何传输网关与其他用户共享;然后使用MediaSource API尽快播放这些块,而不是等待整个文件共享。

What you can do is read file chunks; share them with other users using any transmission gateway like WebSockets, socket.io or WebRTC datachannels; then use MediaSource API to play those chunks as soon as possible instead of waiting from entire file to be shared.

记住,关于铬和壁虎的WebRTC实现支持单一但实时的媒体源;这意味着您无法使用预先录制的媒体作为LIVE媒体源的捕获流。此外,您不能使用假的WebAudio流作为LIVE媒体源。

Remember, WebRTC implementations both on chromium and gecko supports single but "live" media source in the moment; it means that you can't use captured-stream from pre-recorded media as LIVE media source. Also, you can't use fake WebAudio stream as LIVE media source.

以下代码不适用于Firefox:

Following code will NOT work on Firefox:

preRecordedMediaStream = preRecordedMedia.mozCaptureStreamUntilEnded();
peer.addStream(preRecordedMediaStream);

您可以测试演示。

您可以使用FileReader / WebAudio API捕获预先录制的mp3 / ogg文件,并将其作为LIVE音频源共享给WebRTC对等连接,与我在 / 源代码。

You can capture pre-recorded mp3/ogg file using FileReader/WebAudio API and share as LIVE audio source to WebRTC peer connections, same as I did in this demo / source code.

这篇关于如何从videofile创建MediaStream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 00:50