控制Firefox中视频/音频流的音量增益 [英] Control volume gain for Video/Audio stream in Firefox

查看:1171
本文介绍了控制Firefox中视频/音频流的音量增益的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我使用网络音频API创建节点时(源码 - >音频文件)增益 - >目的地)

记录文件的输出只有Audio,因为目的节点的返回流是Audio stream,只能引用这个文档
< a href =https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioDestinationNode =nofollow> https://developer.mozilla.org/zh-CN/docs/Web/ API / MediaStreamAudioDestinationNode



任何有关在目标输出中获取音频/视频流的建议,只能记录音频/视频而不是音频。 b


  var mediastream; 

var ctx = new AudioContext();

var mediaStreamSource = ctx.createMediaStreamSource(mediaStream);

var destination = ctx.createMediaStreamDestination();

ObjectStore.VolumeGainNode = ctx.createGain();
ObjectStore.VolumeGainNode.gain.value = 0.5;

mediaStreamSource.connect(ObjectStore.VolumeGainNode);

ObjectStore.VolumeGainNode.connect(destination);

mediaStream = destination.stream;



解决方案

您可以使用流来修改音轨中的音轨。 .addTrack stream.removeTrack ,以及使用新MediaStream([tracks])组合新流。



这可以让你解决你的问题,用你的增益控制的音轨取代gUM音轨:

  var constraints = {video:true,audio:true}; 

var start =()=> (e => console.error(e));或者,如果使用了一个或多个控制字符串,

var modifyGain =(stream,gainValue)=> {
var audioTrack = stream.getAudioTracks()[0];
var ctx = new AudioContext();
var src = ctx.createMediaStreamSource(new MediaStream([audioTrack]));
var dst = ctx.createMediaStreamDestination();
var gainNode = ctx.createGain();
gainNode.gain.value = gainValue;
[src,gainNode,dst] .reduce((a,b)=>& a.connect(b));
stream.removeTrack(audioTrack);
stream.addTrack(dst.stream.getAudioTracks()[0]);
};

下面是小提琴(Firefox 44或更新版本): https://jsfiddle.net/7wd2z8rz/

再次使用MediaRecorder: https://jsfiddle.net/j33xmkcq/


I'm trying to record Video/Audio files using MediaRecorder API for Firefox.

When I'm using web Audio API for creating the nodes (source -> Gain -> Destination)

The output of the recorded file is only Audio as the return stream from the destination node is Audio stream only referring to this documentation https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioDestinationNode

Any suggestion for getting Audio/video stream in the destination output to record audio/video not audio only.

    var mediastream;

    var ctx = new AudioContext();

    var mediaStreamSource = ctx.createMediaStreamSource(mediaStream); 

    var destination = ctx.createMediaStreamDestination();

    ObjectStore.VolumeGainNode = ctx.createGain();
    ObjectStore.VolumeGainNode.gain.value = 0.5;

    mediaStreamSource.connect(ObjectStore.VolumeGainNode);

    ObjectStore.VolumeGainNode.connect(destination);

    mediaStream = destination.stream;

解决方案

You need a stream composed of the gUM video track and your gain-modified audio track.

Following the standard, Firefox lets you modify tracks in a stream using stream.addTrack and stream.removeTrack, as well as compose new streams out of tracks with new MediaStream([tracks]).

This lets you solve your problem by replacing the gUM audio track with your gain-manipulated one:

var constraints = { video: true, audio: true };

var start = () => navigator.mediaDevices.getUserMedia(constraints)
  .then(stream => modifyGain(video.srcObject = stream, 0.5))
  .catch(e => console.error(e));

var modifyGain = (stream, gainValue) => {
    var audioTrack = stream.getAudioTracks()[0];
    var ctx = new AudioContext();
    var src = ctx.createMediaStreamSource(new MediaStream([audioTrack]));
    var dst = ctx.createMediaStreamDestination();
    var gainNode = ctx.createGain();
    gainNode.gain.value = gainValue;
    [src, gainNode, dst].reduce((a, b) => a && a.connect(b));
    stream.removeTrack(audioTrack);
    stream.addTrack(dst.stream.getAudioTracks()[0]);
};

Here's the fiddle (Firefox 44 or newer): https://jsfiddle.net/7wd2z8rz/

Again with MediaRecorder: https://jsfiddle.net/j33xmkcq/

这篇关于控制Firefox中视频/音频流的音量增益的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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