2016-01-25 132 views
3

我試圖使用MediaRecorder API爲Firefox錄製視頻/音頻文件。Firefox中視頻/音頻流控制音量增益

當我使用網絡的音頻API用於創建節點(源 - >增益 - >目的地)

所記錄的文件的輸出是僅作爲音頻從目的地節點返回流是唯一的音頻數據流參考本文檔 https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioDestinationNode

任何有關獲取目的地輸出中的音頻/視頻流以僅記錄音頻/視頻而非音頻的建議。

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; 

回答

3

你需要一個口香糖視頻軌道和你的增益修正音軌組成流。

遵循該標準,Firefox允許您使用stream.addTrackstream.removeTrack修改流中的曲目,並使用new MediaStream([tracks])構建新的流。

這可以讓你通過更換膠音軌解決你的問題,你的增益操作之一:

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]); 
}; 

這裏的小提琴(火狐44或更高版本):https://jsfiddle.net/7wd2z8rz/

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