0

I use ffmpeg transform mp4 to m3u8; And it keep the same codec value. And when I use fetch to get an ts buffer and append it to MSE instance. So badly. It doesn't work.

Some Code here:

function sourceOpen(e) {
    URL.revokeObjectURL(video.src);
    // var mime = 'video/mp4; codecs="avc1.42c015, mp4a.40.5"';avc1.42001e"
    var mime = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
    var mediaSource = e.target;
    sourceBuffer = mediaSource.addSourceBuffer(mime);
    var videoUrl = './video/' + playManifest.segments[index]['uri'];
    log('.js-log-m3u8', 'Fetch Segment ~' + videoUrl);
    fetch(videoUrl, {
        // headers: { range: 'bytes=0-5671398' }
    })
        .then(function (response) {
            return response.arrayBuffer();
        })
        .then(function (arrayBuffer) {
            sourceBuffer.appendBuffer(arrayBuffer);
            sourceBuffer.addEventListener('updateend', updateEnd);
        });
}

Entire Code

Online test page: http://events.jackpu.com/media-source/

Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
Jack Pu
  • 524
  • 3
  • 11
  • Were you able to find the full codec value "avc1.42E01E, mp4a.40.2 " from segments or the full video? This is required at the frontend side while creating the web player and I am unable to fetch the 42E01E value using ffmpeg /ffprobe. Any help will be useful as I am also making something that you have asked – Inder Preet Feb 19 '22 at 08:25
  • https://medium.com/@JackPu/how-js-get-video-codec-548a33cf7454 – Jack Pu Feb 23 '22 at 07:23
  • That was for a normal file! I was able to do it on the fly with an RTSP url! Thanks anyway! – Inder Preet Feb 25 '22 at 11:06

1 Answers1

0

You are setting the mime type to video/mp4 but attempting to append transport stream segments to the source buffer. As a result, the appends are failing and no data is being buffered.

You call play once all the segments have been fetched, without checking if any data has been buffered, and the Promise rejects.

You would need to create a SourceBuffer with the correct mime type, assuming your user agent is capable of doing so.

Anonymous Coward
  • 1,096
  • 11
  • 22
  • any tool get the codec value like avc1.42E01E, mp4a.40.2 – Jack Pu Mar 02 '18 at 05:43
  • It's the container format, not the codec type that's the issue. You are creating a SourceBuffer of type `video/mp4`, but appending transport stream segments. You either need to repackage your transport stream segments into MP4 segments, or create a SourceBuffer with mime type `video/mp2t` (assuming you can find a user agent which will let you do this). – Anonymous Coward Mar 02 '18 at 14:02