KallDrexx / rust-media-libs

Rust based libraries for misc media functionality
Apache License 2.0
234 stars 60 forks source link

Support for pushing MPEG-TS streams to external RTMP servers #42

Open bezaleel22 opened 1 year ago

bezaleel22 commented 1 year ago

Description: Hello! I am interested in using the rust-media-libs library for streaming MPEG-TS video content to an external RTMP server like YouTube. I have read through the documentation and searched through the examples, but I haven't found any clear instructions on how to do this.

Can you please provide guidance or an example on how to push a MPEG-TS stream to an external RTMP server using this library? It would be really helpful if you could add this functionality to the library as well.

Thank you for your hard work on this library and I appreciate any help you can provide.

Best regards, Onojeta Brown

KallDrexx commented 1 year ago

Unless I'm misunderstanding something, MPEG-TS is a container format, not a media codec. RTMP only works with media in the FLV container format.

The first thing to be aware of is that the FLV container only supports h264 video and AAC audio (it technically supports other codecs but those are really old and not used anymore). So if your MPEG-TS media is in another codec, the media will have to be transcoded before the rml_rtmp crate comes into play.

If your mpeg-ts media is h264 and AAC, then your rust code needs to read the mpeg-ts data streams (making sure to read at clock speed based on the media timestamps). Each Mpeg-ts media segment then needs to have the raw video taken from it, along with timestamp information.

The raw media byte stream then needs to be packed into an FLV packet (you can see me do that in my media server, video example and audio example).

Once you have the media wrapped in an FLV packet, you then create you can take your ClientSession which is presumably already connected to the external RTMP server as a publisher, and call publish_video_data() or publish_audio_data() with those bytes. That will publish the media to the external server, which should be able to read it as expected.

bezaleel22 commented 1 year ago

@KallDrexx Thank you so much for the detailed explanation, I'm a newby in video programming, I'm looking at building a basic app that pushes streams to YouTube RTMPS server like OBS. With your guidance, I would like to implement basic working example and show my code here to help others, Thanks for your quick response.

ehuff700 commented 1 year ago

@onos9 did you make any progress here? I'm attempting to do something similar (trying to recreate an incredibly basic version of OBS in Rust essentially). Need some guidance.

ROBERT-MCDOWELL commented 1 year ago

@KallDrexx I think people coming here think that rust-media-libs concern all kind of protocols and encoding...

KallDrexx commented 1 year ago

That was originally the intention, bu time and life has gotten in the way of it.

ROBERT-MCDOWELL commented 1 year ago

yup, as everyone trapped in this digital world we forgot the limited time we have on this Earth ;)