-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server-side video stream encryption for client-side decrypt and playback #2334
Comments
Interesting and challenging things you are working on @jcalfee, but to me it appears this has nothing to do with this music-metadata project. But streams you usually use to flow or transform data chunks (bunch of bytes). That In principal Node.js has a Web Stream API, maybe minor differences in implementation, but it should bot be necessary to shim. The whole point of Web Stream API as that this part of the ECMAScript, which should result in code which can work both in browser and in Node.js. I can confirm that working with the Web Stream API can be very tricky. |
Thanks for the clarification. I saw MP4 format support here and was not sure and, of course, streams. I had only 2 days to put this together so I really was not sure. Looks like I need to take a few more days to explore other possible high-level encoding methods then dig in to the data in the stream itself, like you say, with different APIs. There are other players that I can explore, even native wasm compiled ones which may have fall-back optimizations so video is still fast. That is probably going to be more modern and simple. I was considering do the processing in a chrome engine like Fantastic, thank you for the feedback. If anyone else has experience please let me know or let me know if you want me to post some answers when I have them. |
And, what project is on topic if you know? ;) |
You raised an issue on the music-metadata project, and that happen also to be the appropriate project to discuss. For most users that is obvious. For generic help for implementation challenges I can advise you raise your questions at https://codereview.stackexchange.com/. |
Has the question been asked before?
Question
I'm trying to encrypt files in Nodejs (on the server) for play back in the browser. If your curious, this has to do will role based security where some servers have access to certain videos and backup and encrypt with a public key then distribute that to less trusted servers that stream the files. The client gets authenticated and use the decryption key in the browser without the less trusted servers ever having access. This is pretty portable to a plugin or an electron app.
So, on the web side of things, there is a great example from webrts whereby insertable-streams/endtoend-encryption/js/worker.js is using a Streams API TransformStream to setup the streams for some week XOR encryption / decryption (not shown here yet, this is just how it sets it up):
Something very helpful, the encode function logs the first 30 frames:
It gets complex though. I see this is not simply straight data. It is the audio and video streams in separate frames with metadata. I'm not even sure if the size of these frames will be predictable and consistent (something I need to know for strong AES CTR encryption). I would rather encrypt and decrypt on the entire stream and not break it down like this, however, there does not seem be a way to do this and still feed it into
<video srcObject={stream}.../>
. Keep in mind, the<video ../>
element will interact with the stream to get Content-Range blocks of data so the user can fast-forward and re-wind in what is typically a very large stream. So, I need to work with this element and give it what it needs. This is also probably the main way to get decent GPU and hardware support for rendering. Do you think I really have to break the stream up like this on server and get inside and encrypt each frame? If so, it looks like I'll probably need to do this exactly like the browser is going to do this: read and dissemble the stream and encrypt / decrypt each frame. This is just what their example does, except it is browser to browser instead of node to browser. So, in node, I probably should be able to create a "dump" just like the one I'm seeing in the web browser or at least some thing like it so I can debug this and figure out what is going on.Here is the node example I have so far:
The dump is the same (so far):
I want this output from node, but this is only from the browser (so far):
So, I start down this path using 'node:stream/web' but I'm finding it does not provide the
getMetadata()
function:Do you know, did I miss something or is this just not available in node? Maybe
new ReadableStream()
the wrong thing to use? Or, perhaps I need some sort of shim so node acts more like the Web Stream API. Or, better yet, I just need to know more about these streams so I can handle them correctly. Any help is appreciated. Thank you!The text was updated successfully, but these errors were encountered: