Получил блок с временным кодом перед предыдущим блоком - PullRequest
0 голосов
/ 03 февраля 2019

Я пытаюсь добавить чанк в sourceBuffer, после загрузки первого чанка я просто использую sourceBuffer.appendBuffer(buf);, но возникает ошибка Got a block with a timecode before the previous block. и чанк не добавляется.

Я былпоиск по всему Интернету в течение недели, я не нашел ничего, чтобы помочь вообще!

 var videoNumber = 1;
var video = document.querySelector('video');
var assetURL = '/classes/'+class_id+'/video/';
var segmentDuration = 5;
var duration = 5 ;
var videoRequesterInterval;
// var videoRequestTimer = 0;
// Need to be specific for Blink regarding codecs
// ./mp4info frag_bunny.mp4 | grep Codec
var mimeCodec = 'video/webm; codecs="vp8, opus"';
var sourceBuffer;

var mediaSource;

if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) {
    mediaSource = new MediaSource;


    video.src = URL.createObjectURL(mediaSource);
    mediaSource.addEventListener('sourceopen', sourceOpen);
} else {
    console.error('Unsupported MIME type or codec: ', mimeCodec);
}

/**
 * @desc start when video opened
 * @param _
 */
function sourceOpen (_) {
    console.log("source opened");
    //console.log(this.readyState); // open
    sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
    appendSegmentIfExist();
    // video.addEventListener('timeupdate', checkBuffer);
    sourceBuffer.addEventListener('updateend', playVideo);
    sourceBuffer.addEventListener('error', logError);

}

var tries = 0;
function fetchVideo(videoNumber,callback = function (response) {

}) {
    console.log("fetch video number "+ videoNumber);
    var xhr = new XMLHttpRequest;
    xhr.open('get', assetURL+videoNumber);
    xhr.responseType = 'arraybuffer';
    xhr.onloadend = function() {
        if(xhr.status === 404)
        {
            console.log('tries is '+ tries);
            if(tries > 3)
            {
                mediaSource.endOfStream();
                clearInterval(videoRequesterInterval);
                return;
            }
            tries++;
            fetchVideo(videoNumber,callback);
        }
        else
        {
            tries++;
            callback(xhr.response);
        }
    };
    xhr.send();
}

function appendSegment() {
    fetchVideo(videoNumber,function(buf)
    {
        if(videoEl.currentTime === 0)
        {
            video.play();
            videoRequesterInterval = setInterval(function(){
                videoNumber++;
                appendSegment();
                }, (segmentDuration)*1000);
        }

        console.log(buf);

        sourceBuffer.timestampOffset = duration - segmentDuration;
        duration += 5;
        sourceBuffer.appendWindowStart = 0;
        // sourceBuffer.appendWindowEnd = 5;
        // console.log(sourceBuffer);
        sourceBuffer.appendBuffer(buf);
        console.log(sourceBuffer);
    });
}

function appendSegmentIfExist()
{
    console.log("check if there is video on server ");
    var xhr = new XMLHttpRequest;
    xhr.open('get', assetURL+videoNumber);
    xhr.responseType = 'arraybuffer';
    xhr.onloadend = function() {
        if(xhr.status === 404)
        {
            console.log('no video on server ');
        }
        else
        {
            appendSegment();
        }
    };
    xhr.send();
}

function playVideo() {
    console.log('update end');
    console.log(sourceBuffer.buffered);
    console.log(mediaSource.readyState);
    // mediaSource.duration = Infinity;
    console.log(mediaSource.duration);
}

function logError(e) {
    console.log("-----------");
    console.log(e);
    console.log(sourceBuffer);
    console.log(video.error.message);
}

Редактировать: Хорошо, после очень долгого следа я заметил некоторые странные вещи: 1-проблема появляется только в том случае, если вы записали носитель в Firefox, а затем добавили его в sourceBuffer в браузере Chrome, ошибка не произойдет, если вы записываете носитель с помощью Chrome.

2 - буфер массива имеет отрицательные значения

    [[Int8Array]]: Int8Array(916168) [26, 69, -33, -93, 1, 0, 0, 0, 0, 0, 0, 31, 66, -122, -127, 1, 66, -9, -127, 1, 66, -14, -127, 4, 66, -13, -127, 8, 66, -126, -124, 119, 101, 98, 109, 66, -121, -127, 2, 66, -123, -127, 2, 24, 83, -128, 103, 1, -1, -1, -1, -1, -1, -1, -1, 17, 77, -101, 116, 1, 0, 0, 0, 0, 0, 0, 0, 21, 73, -87, 102, 1, 0, 0, 0, 0, 0, 0, 73, 42, -41, -79, -125, 15, 66, 64, 68, -119, -120, 0, 0, 0, 0, 0, 0, 0, 0, 77, -128, -104, …]
[[Int16Array]]: Int16Array(458084) [17690, -23585, 1, 0, 0, 7936, -31166, 385, -2238, 385, -3518, 1153, -3262, 2177, -32190, 30596, 25189, 17005, -32377, 16898, -32379, 6146, -32685, 359, -1, -1, -1, 4607, -25779, 372, 0, 0, 0, 5376, -22199, 358, 0, 0, 0, 10825, -20009, 3971, 16450, -30396, 136, 0, 0, 0, 19712, -26496, 21585, 30061, 27000, 26478, 28737, 19568, 25193, 25943, 19810, 12333, 12334, 12590, 16727, 20889, 30548, 26994, 26996, 26478, 28737, 19568, 25193, 25943, 19810, 12333, 12334, 12590, 21526, 27566, 1, 0, 0, -27392, 430, 0, 0, 0, -10452, 385, -14989, 25732, -32305, 9507, -30586, 22147, 14416, -32381, -31231, 22149, 22111, 14416, …]
[[Int32Array]]: Int32Array(229042) [-1545648870, 1, 520093696, 25265730, 25294658, 75625026, 142734146, 2005172802, 1114464869, 1107460487, 402817413, 23560275, -1, 301989887, 24419149, 0, 352321536, 23505225, 0, 709427200, 260288983, -1992015806, 136, 0, -1736422144, 1970099281, 1735289208, 1282437185, 1700225641, 808275298, 825110574, 1368998231, 1769109332, 1735289204, 1282437185, 1700225641, 808275298, 825110574, 1806586902, 1, -1795162112, 430, 0, 25286444, 1686422899, 623083983, 1451460742, -2122106800, 1451591169, 944789087, 480, 0, 42119176, 25344640, 110304, 0, -2116593920, -2067434750, 565692838, 1443004803, 1660978346, -1151950802, -1262222204, 1099335168, 1431326559, -1818074285, 1937076303, 1684104520, 20447489, 44100, 620756992, 1334085766, -514632368, 1, 218103808, -448755531, 32904, -2120286208, -1237115135, 373, 1879310336, 8513377, -520089437, 33039, 30912640, -2144730723, 122882, -2054879225, -2004575864, 1267073794, 1232000975, -1209806339, -142633741, -2124481665, 1257813535, 1853382398, -1459618273, -385879762, 267826162, -281960608, …]
[[Uint8Array]]: Uint8Array(916168) [26, 69, 223, 163, 1, 0, 0, 0, 0, 0, 0, 31, 66, 134

Я думаю, что это вызвало проблему!

3 - это мой журнал ошибок в Chrome:

Timestamp   Property    Value
00:00:00.000    origin_url  http://e-learning.local/
00:00:00.000    frame_url   http://e-learning.local/test
00:00:00.000    frame_title 
00:00:00.000    surface_layer_mode  kOnDemand
00:00:00.000    url blob:http://e-learning.local/86e00165-f1f1-4aec-be2e-a1f9d3171519
00:00:00.000    info    ChunkDemuxer: buffering by DTS
00:00:00.000    pipeline_state  kStarting
00:00:00.084    found_video_stream  true
00:00:00.084    video_codec_name    vp8
00:00:00.084    found_audio_stream  true
00:00:00.084    audio_codec_name    opus
00:00:00.084    error   Got a block with a timecode before the previous block.
00:00:00.084    error   Append: stream parsing failed. Data size=131072 append_window_start=0 append_window_end=inf
00:00:00.085    audio_dds   false
00:00:00.085    audio_decoder   FFmpegAudioDecoder
00:00:00.085    is_platform_audio_decoder   false
00:00:00.085    info    Selected FFmpegAudioDecoder for audio decoding, config: codec: opus, bytes_per_channel: 4, channel_layout: 2, channels: 1, samples_per_second: 48000, sample_format: 4, bytes_per_frame: 4, seek_preroll: 80000us, codec_delay: 312, has extra data: true, encryption scheme: Unencrypted, discard decoder delay: true
00:00:00.086    video_dds   false
00:00:00.086    video_decoder   FFmpegVideoDecoder
00:00:00.086    is_platform_video_decoder   false
00:00:00.086    info    Selected FFmpegVideoDecoder for video decoding, config: codec: vp8, format: PIXEL_FORMAT_I420, profile: vp8, coded size: [640,480], visible rect: [0,0,640,480], natural size: [640,480], has extra data: false, encryption scheme: Unencrypted, rotation: 0°
00:00:00.086    pipeline_state  kPlaying
00:00:00.086    audio_buffering_state   BUFFERING_HAVE_ENOUGH
00:00:00.086    video_buffering_state   BUFFERING_HAVE_ENOUGH
00:00:00.089    pipeline_error  CHUNK_DEMUXER_ERROR_APPEND_FAILED
00:00:00.089    pipeline_state  kStopping
00:00:00.099    pipeline_state  kStopped
00:00:00.084    duration    unknown

Я думаю, что Firefox генерирует отрицательный тайм-код во время записи, но Chrome отказываетсяпрочитайте видео, если у него отрицательный тайм-код!

Я также пытался использовать собственный MediaRecorder API, но Firefox по-прежнему генерирует отрицательное значение и Chrome отказывается добавлять его в видео sourceBuffer.

...