Shaka Player возвращает ошибку 4001 - Node.js локальный веб-сервер воспроизводит MPEG-DASH - PullRequest
0 голосов
/ 27 мая 2020

Я использовал инструмент проверки Chrome для доступа к «Консоли» и анализа происходящего. Полная информация об ошибке:

D {severity: 2, category: 4, code: 4001, data: Array(1), handled: false}
category: 4
code: 4001
data: Array(1)
0: "http://localhost:8080/dash_segmentos/video.mpd"
length: 1
__proto__: Array(0)
handled: false
severity: 2
__proto__: Object

Мой Server.js файл:

var http = require('http');
var fs = require('fs');

console.log(__dirname);

var path='dash_segmentos/video.mpd';
fs.access(path, fs.constants.R_OK | fs.constants.W_OK, (err) => {
    if (err) {
        console.log("%s doesn't exist", path);
    } else {
        console.log('can read/write %s', path);
    }
});

const PORT=8080; 

fs.readFile('./player.html', function (err, html) {

    if (err) throw err;    

    http.createServer(function(request, response) {  
        response.setHeader("Access-Control-Allow-Headers", "authorization, content-type");
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        response.writeHeader(200, {"Content-Type": "text/html"}); 
        response.write(html);  
        response.end();
    }).listen(PORT);
});

Как видите, я добавил CORS (думаю, это правильно) и console.log, чтобы увидеть если он находится в нужном месте. Кроме того, я убедился, что файл доступен с помощью fs.access, и он возвращает can read/write dash_segmentos/video.mpd По этой причине я уверен, что нахожусь на правильном пути и ссылаюсь на правильный файл.

The HTML код (player.html) предоставлен для Server.js:

<!DOCTYPE html>
<html>
 <head>
 <script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/2.5.11/shaka-player.compiled.js"></script>
 </head>
 <body>
 <div class="video">
 <video id="video" width="720" controls autoplay> </video>
 </div>

 <script>
function initApp() { 
shaka.polyfill.installAll(); 
if (shaka.Player.isBrowserSupported()) { 
 initPlayer(); 
 } else { 
 console.error('Browser not supported!');
 }}

function initPlayer() { 
var video = document.getElementById( 'video' );
var player = new shaka.Player( video );
 window.player = player; 
player.addEventListener('error', onErrorEvent); 
player.load(path).then(function (){
    console.log('Video loaded correctly');
 }).catch(onError);

function onErrorEvent(event) {
 onError(event.detail); 
 }
function onError(error) {
 console.error('Codigo de error: ', error.code, ' en ', error);
 }
}
</script>

<script>
var path='dash_segmentos/video.mpd';
//var path='https://dash.akamaized.net/dash264/TestCases/2c/qualcomm/1/MultiResMPEG2.mpd';
//the URL above is working! but it won't read my local mpd

document.addEventListener('DOMContentLoaded', initApp);

 </script>
 </body>
</html>

Я попытался изменить URL-адрес на онлайн-ресурс, и проигрыватель работает правильно.

Моя команда fluent-ffmpeg который генерирует видео:

var ffmpeg = require('fluent-ffmpeg');

var grabacion = new ffmpeg();

grabacion.addInput('0')
.inputOptions(['-y -nostdin', '-f avfoundation', '-video_size 1280x720', '-framerate 30'])
.outputOptions(['-vcodec libx264', '-keyint_min 0', '-g 100', '-map 0:v', '-b:v 1000k', '-f dash',
 '-use_template 1', '-use_timeline 0', '-init_seg_name video0-$RepresentationID$-$Number$.mp4',
 '-media_seg_name video0-$RepresentationID$-$Number$.mp4','-single_file 0', '-remove_at_exit 0', '-window_size 20', '-seg_duration 4'])
.output('/path/to/files/dash_segmentos/video.mpd')
.run();

Файл манифеста mpd:

<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:mpeg:dash:schema:mpd:2011"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
    profiles="urn:mpeg:dash:profile:isoff-live:2011"
    type="static"
    mediaPresentationDuration="PT26.7S"
    maxSegmentDuration="PT4.0S"
    minBufferTime="PT13.2S">
    <ProgramInformation>
    </ProgramInformation>
    <ServiceDescription id="0">
    </ServiceDescription>
    <Period id="0" start="PT0.0S">
        <AdaptationSet id="0" contentType="video" startWithSAP="1" segmentAlignment="true" bitstreamSwitching="true" frameRate="30000/1001" maxWidth="1280" maxHeight="720" par="16:9">
            <Representation id="0" mimeType="video/mp4" codecs="avc1.7a001f" bandwidth="1000000" width="1280" height="720" sar="1:1">
                <SegmentTemplate timescale="1000000" duration="4000000" initialization="video0-$RepresentationID$-$Number$.mp4" media="video0-$RepresentationID$-$Number$.mp4" startNumber="1">
                </SegmentTemplate>
            </Representation>
        </AdaptationSet>
    </Period>
</MPD>

Есть что-то о ffmpeg? Разрешения? Формат пикселей? Кодировка? Я пробовал использовать другой файл mpd, предоставленный моим Raspberry Pi, используя video4 linux (v4l), и он возвращает ту же ошибку!

Я знаю, что это много кода, но, возможно, вы найдете его быстрее, чем я . Я предполагаю, что это игра Shaka Player с XML, но я не могу объяснить, как ffmpeg ошибочно создает код XML.

Заранее спасибо !!

...