Skip to content
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

Switch file source in ffmpeg #53

Open
Naihan opened this issue Mar 15, 2023 · 4 comments
Open

Switch file source in ffmpeg #53

Naihan opened this issue Mar 15, 2023 · 4 comments

Comments

@Naihan
Copy link

Naihan commented Mar 15, 2023

I have an algorithm that manipulate a jpeg image that comes out of a camera and I want to send it to webRTCservice.

I was able to use one of the code samples to create a mock app but with a single static file.

private static Task<RTCPeerConnection> CreatePeerConnection()
        {
            RTCConfiguration config = new RTCConfiguration
            {
                iceServers = new List<RTCIceServer> { new RTCIceServer { urls = STUN_URL } }
            };

            _peerConnection = new RTCPeerConnection(config);

            SIPSorceryMedia.FFmpeg.FFmpegFileSource fileSource = new SIPSorceryMedia.FFmpeg.FFmpegFileSource("path to file.jpg", true, null, 960, true);

           
            _videoSource = fileSource as IVideoSource;

            _videoSource.RestrictFormats(x => x.Codec == _videoCodec);
            MediaStreamTrack videoTrack = new MediaStreamTrack(_videoSource.GetVideoSourceFormats(), MediaStreamStatusEnum.SendRecv);

            _peerConnection.addTrack(videoTrack);
            _videoSource.OnVideoSourceEncodedSample += _peerConnection.SendVideo;
            _peerConnection.OnVideoFormatsNegotiated += (videoFormats) => _videoSource.SetVideoSourceFormat(videoFormats.First());

            

            return Task.FromResult(_peerConnection);
}

My question is how do I change the file once I receive the next image from my algo service, or if there is a smarter way to do that like using a stream

Thanks :-)

@ChristopheI
Copy link
Collaborator

  • Store the video format used in the connection
  • stop / dispose correctly your previous _videoSource
  • create your new _videoSource and use SetVideoSourceFormat and OnVideoSourceEncodedSample as you already did

@Naihan
Copy link
Author

Naihan commented Mar 15, 2023

What if the jpeg image I receive from my algo is a byte[] ?

@inbargoldman
Copy link

  • Store the video format used in the connection
  • stop / dispose correctly your previous _videoSource
  • create your new _videoSource and use SetVideoSourceFormat and OnVideoSourceEncodedSample as you already did

Hi,
I have the same problem
I want to send the data to webRTCservice as byte[]

the byte array is dynamically changed
Is there as way to send data as dynamically byte[]?

Thanks

@ha-ves
Copy link
Contributor

ha-ves commented Jul 26, 2023

@Naihan
What if the jpeg image I receive from my algo is a byte[] ?

We're not sure what you mean by that, are you using your own implementation to do the JPEG to be sent via RTP? if so this repo is not the right place.

Then to also answer this,

@inbargoldman

  • Store the video format used in the connection
  • stop / dispose correctly your previous _videoSource
  • create your new _videoSource and use SetVideoSourceFormat and OnVideoSourceEncodedSample as you already did

Hi, I have the same problem I want to send the data to webRTCservice as byte[]

the byte array is dynamically changed Is there as way to send data as dynamically byte[]?

Thanks

If you meant sending byte[] via Data Channel, you can head to the main sipsorcery repo to find example for sending data using DataChannel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants