Haivision / srtgo

Go bindings for SRT. Advantages of SRT technology for an easy to use programming language
Mozilla Public License 2.0
185 stars 52 forks source link

How do I output the srt stream? #60

Open RLutsch opened 1 year ago

RLutsch commented 1 year ago

I can start the server and stream video to it and log the bytes but how do I get the stream to something like go-ffmpeg to convert and restream? or even just save to disk?

gissleh commented 1 year ago

Saving it to disk could be done in the same way you'd copy from any other io.Reader: open a file and use that writer to save the bytes to file. Using io.CopyBuffer with a buffer of length >= SRT chunk size could simplify the process.

As for go-ffmpeg, I cannot find a library by that name. ffmpeg-go seems to lack a way to take in a io.Reader or offer an io.Writer, so maybe a named pipe could do the trick here? If your use case is to take in one SRT stream and outputting it without any custom behavior, you could get away with building ffmpeg with libsrt enabled and use your Go application to manage these running ffmpeg instances.

RLutsch commented 1 year ago

thanks for the quick response and yes it's ffmpeg-go. guessing my two options would either be to relay the stream to an srt port that I can read using ffmpeg or alternatively write to stdout and use the pipe: method then?

RLutsch commented 1 year ago

Is it possible to publish the srt stream to localhost?

Then I could simply ffmpeg -i srt://localhost:1234 and get the stream I need to transform and send

gissleh commented 1 year ago

You could use this library to open a listener, and write to every client that it accepts, and then it should work in ffmpeg with the address in your comment.

I don't think I understand your use case, though, or if you are at the stage of your work where the issue you have is with this Go binding. You should start with a manual setup that uses srt-live-transmit and/or ffmpeg to do what you want, then start work on automating it with Go.

RLutsch commented 1 year ago

I have to send an srt stream h.265 to rtmp for distribution in h.264.

Currently I can trasnmit to srtgo listener and send the srt stream but struggling to input the stream to ffmpeg to do the transcoding to h.265 and send to rtmp endpoint. with another service the stream gets published to localhost and ffmpeg can receive input from localhost. hope that makes sense

gissleh commented 1 year ago

What is failing when you try to input the stream to ffmpeg, and does it work if you do srt-live-transmit srt://localhost:1234 file://con | ffmpeg -i -...?