Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active January 30, 2017 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uupaa/39c400f2bbc7e9b884ba7c5691a1a79e to your computer and use it in GitHub Desktop.
Save uupaa/39c400f2bbc7e9b884ba7c5691a1a79e to your computer and use it in GitHub Desktop.
EncoderDelay in OBS Live stream

OBS から送られて来るHLSライブストリームのAACにEncoderDelay(Primary + Remainder)が含まれているか確認します。

  1. https://www.youtube.com/watch?v=Oc8cLx9MXSo をOBS で配信する
  2. PCM 再生処理の前に以下の DummaySample を挿入する
  3. leftChannelWithDummy を再生し波形を確認する
var context = new AudioContext();
var stream = new Uint8Array(...); // AAC

context.decodeAudioData(stream.buffer, function(audioBuffer) { // @arg AudioBuffer - { duration, length, numberOfChannels }
    // 無音区間が
    // PrimarySamples なのか
    // RemainderSamples なのか区別するため、ダミーデータを入れる
    // 先頭部分に new Float32Array(1024) = [1.0 .. 1.0] を挿入する

    var leftChannel = audioBuffer.getChannelData(0);
    var leftChannelWithDummy = new Float32Array(1024 + leftChannel.length);

    for (var i = 0, iz = 1024; i < iz; ++i) {
        leftChannelWithDummy[i] = 1.0;
    }
    leftChannelWithDummy.set(leftChannel, 1024);


});

この波形を見る限り、OBSから配信されるHLS経由のAACにはPrimarySampleが含まれており、RemainderSampleは含まれていない事がわかります。

またこのケースでは、PrimarySample の長さは 0.01017 ほどで、この値を (1 / 44100 = 0.00002267573696) で割ると 450 samples ほどになるようです。

0.01017 / 0.00002267573696 = 448.49 samples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment