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

MpegTS to UDP #4

Open
yann591 opened this issue Jan 3, 2022 · 2 comments
Open

MpegTS to UDP #4

yann591 opened this issue Jan 3, 2022 · 2 comments

Comments

@yann591
Copy link

yann591 commented Jan 3, 2022

There is a way to stream MpegTS to UDP ?

@jasells
Copy link
Owner

jasells commented Jan 3, 2022

This version of code is only a protoype client (ready only) for MpegTS. That said, with some work, you could use it to take a raw H.264/5 stream and encapsulate it in a MpegTS packet stream that could be sent UDP, TCP, or to file. The use case that spurred the creation of this prototype library was to consume a UDP stream.

@yann591
Copy link
Author

yann591 commented Jan 4, 2022

By this way I send to 380 Mbit/s, how could I improve this code ?

string tsFile = @"E:\dvb\dvb_lib\27.ts";

    byte[] bytes = File.ReadAllBytes(tsFile);

    UdpClient outPutUdpClient = new UdpClient { ExclusiveAddressUse=false};

    IPAddress outPutIp = IPAddress.Parse("192.168.99.239");
    int multicastPort = 1234;

    var localEp = new IPEndPoint(outPutIp, multicastPort);

    outPutUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
    outPutUdpClient.Ttl = 3;
    outPutUdpClient.Client.Bind(localEp);

    var mcastAddr = IPAddress.Parse("239.1.1.1");

    outPutUdpClient.Connect(mcastAddr, multicastPort);            
    
    for(int i = 1316; i < bytes.Length; i+=1316) // take 7 ts packets per one UDP packet
    {
        int begin = i-1316;
        int end = i;

        var sendBytes = bytes[begin..end];

        Thread.Sleep(1); <--- NEED Delay 2641 ticks

        try
        {
            outPutUdpClient.Send(sendBytes, sendBytes.Length);                    
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }

    }

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

2 participants