samirkumardas / jmuxer

jMuxer - a simple javascript mp4 muxer that works in both browser and node environment.
Other
549 stars 108 forks source link

Is there any way to support raw AAC streams(Without ADTS)? #76

Closed alx696 closed 3 years ago

alx696 commented 3 years ago

I want to play video or audio from Android.

Android:

Video: Camera > MediaCodec H264(video/avc) encode > WebSocket Server

Audio: AudioRecord(PCM) > MediaCodec AAC(audio/mp4a-latm) encode > WebSocket Server

It is easy to live under android. Player just need to use MediaCodec decode data and show.

Video(raw h264 stream) works fine. But audio not. Even if add ADTS to data:

0
15:48:11.106 jmuxer.min.js:1 Initial segment generated.
15:48:11.107 jmuxer.min.js:1 put segment (audio): dts: 0 frames: 2 second: 00:00
15:48:11.140 play-android.js:22 21333
15:48:11.141 jmuxer.min.js:1 put segment (audio): dts: 66 frames: 2 second: 00:00
15:48:11.161 play-android.js:22 42666
15:48:11.161 jmuxer.min.js:1 put segment (audio): dts: 132 frames: 2 second: 00:00
15:48:11.162 play-android.js:22 64000
15:48:11.162 jmuxer.min.js:1 

Chrome crash...

JS:

    let jmuxer = new JMuxer({
        node: 'video',
        mode: 'audio',
        flushingTime: 100,
        fps: 30,
        debug: true
    });

    websocket = new WebSocket(`wss://27.17.7.86:84/v1/feed`);
    websocket.binaryType = 'arraybuffer';
    websocket.addEventListener('open', () => {
        console.debug('开始订阅');
        websocket.send('b|a');
    });
    websocket.addEventListener('message', evt => {
        // console.debug('收到订阅', evt.data);

        if (typeof evt.data === 'string') {
            console.debug(evt.data);
            return;
        }

        jmuxer.feed({
            audio: new Uint8Array(evt.data)
        });
    });
    websocket.addEventListener('close', evt => {
        console.debug('停止订阅', evt.code, evt.reason);
        if (evt.code !== 1000) {
            console.warn('异常停止订阅', evt.code, evt.reason);
        }
    });
    websocket.addEventListener('error', evt => {
        console.error(evt);
    });

It is better to support raw AAC(Without ADTS) like raw h264. Or auto add ADTS?

alx696 commented 3 years ago

Sorry! It works with ADTS. I made a mistake. ADTS packetLen wrong.