AxisCommunications / media-stream-library-js

JavaScript library to handle media streams on the command line (Node.js) and in the browser.
MIT License
302 stars 101 forks source link

(Plans for) H265 support #974

Open anned20 opened 4 months ago

anned20 commented 4 months ago

Currently, we use this library to consume a RTSP stream for the camera and feed the resulting MP4 data into a ffmpeg process. This works magnificently, but only when the camera is set up to use H.264 encoding. When the camera is configured for H.265 encoding, the following error occurs:

closing TCP socket due to incoming error TypeError: Cannot read properties of undefined (reading 'parameters')
    at Object.h264Settings [as H264] (/app/node_modules/media-stream-library/dist/node.cjs:4650:37)
    at /app/node_modules/media-stream-library/dist/node.cjs:4803:50
    at Array.forEach (<anonymous>)
    at BoxBuilder.moov (/app/node_modules/media-stream-library/dist/node.cjs:4792:15)
    at Transform.transform [as _transform] (/app/node_modules/media-stream-library/dist/node.cjs:4891:35)
    at Transform._write (node:internal/streams/transform:171:8)
    at writeOrBuffer (node:internal/streams/writable:564:12)
    at _write (node:internal/streams/writable:493:10)
    at Writable.write (node:internal/streams/writable:502:10)
    at Transform.ondata (node:internal/streams/readable:1007:22)

The offending line in the source is https://github.com/AxisCommunications/media-stream-library-js/blob/6351e77108e62e1898a0f3ddf4f6f1ef7a4e0e6b/streams/src/components/mp4muxer/helpers/h264Settings.ts#L68

I know, because of previous tickets, that there has been no effort yet to support H.265, mainly through the unsupported nature of the protocol in browsers, but this is changing: https://caniuse.com/hevc

Are there any plans to support H.265?

steabert commented 3 months ago

Even though support for H.265 improves across browsers, it's currently not something that's easy to do with this library, as the stream format will depend itself on H.265. But if someone adds the necessary "depay" component(s) it's possible.

However, if you want to get MP4 data from the camera that you process anyway, isn't it easier to extract if directly as MP4 from the camera? The media.cgi supports both matroska and mp4 as container format. The only reason you would still extract RTSP and use this library is if you have an old model, or if you need to directly feed it in the browser, in which case the MP4 solution could have worse latency.