|
| 1 | +using Microsoft.Extensions.Configuration; |
| 2 | +using SharpRTSPServer; |
| 3 | +using System; |
| 4 | + |
| 5 | +IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); |
| 6 | +string hostName = config["HostName"]; |
| 7 | +ushort port = ushort.Parse(config["Port"]); |
| 8 | +string userName = config["UserName"]; |
| 9 | +string password = config["Password"]; |
| 10 | + |
| 11 | +// ffmpeg.exe -re -stream_loop -1 -i C:\Git\SharpMediaCoder\src\SharpMediaPlayer\frag_bunny.mp4 -vcodec copy -an -f rtp rtp://127.0.0.1:11111 -vn -acodec copy -f rtp rtp://127.0.0.1:11113 |
| 12 | +using (var server = new RTSPServer(port, userName, password)) |
| 13 | +{ |
| 14 | + server.AddVideoTrack(new ProxyTrack(0, "rtp://127.0.0.1:11111")); |
| 15 | + server.AddAudioTrack(new ProxyTrack(1, "rtp://127.0.0.1:11113")); |
| 16 | + // original |
| 17 | + //string sdp = |
| 18 | + // "v=0\r\n" + |
| 19 | + // "o=- 0 0 IN IP4 127.0.0.1\r\n" + |
| 20 | + // "s=No Name\r\n" + |
| 21 | + // "t=0 0\r\n" + |
| 22 | + // "a=tool:libavformat 60.3.100\r\n" + |
| 23 | + // "m=video 11111 RTP/AVP 96\r\n" + |
| 24 | + // "c=IN IP4 127.0.0.1\r\n" + |
| 25 | + // "b=AS:587\r\n" + |
| 26 | + // "a=rtpmap:96 H264/90000\r\n" + |
| 27 | + // "a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAHqzZQKAv+WagwCDW4AAAAwAgAAAGAeLFssA=,aOvjyyLA; profile-level-id=64001E\r\n" + |
| 28 | + // "m=audio 11113 RTP/AVP 97\r\n" + |
| 29 | + // "c=IN IP4 127.0.0.1\r\n" + |
| 30 | + // "b=AS:69\r\n" + |
| 31 | + // "a=rtpmap:97 MPEG4-GENERIC/44100/1\r\n" + |
| 32 | + // "a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=120856E500\r\n\r\n"; |
| 33 | + |
| 34 | + string sdp = |
| 35 | + "v=0\r\n" + |
| 36 | + "o=- 0 0 IN IP4 127.0.0.1\r\n" + |
| 37 | + "s=No Name\r\n" + |
| 38 | + "t=0 0\r\n" + |
| 39 | + "a=tool:libavformat 60.3.100\r\n" + |
| 40 | + "m=video 11111 RTP/AVP 96\r\n" + |
| 41 | + "a=control:trackID=0\n" + // TODO: add this |
| 42 | + "c=IN IP4 127.0.0.1\r\n" + |
| 43 | + "b=AS:587\r\n" + |
| 44 | + "a=rtpmap:96 H264/90000\r\n" + |
| 45 | + "a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAHqzZQKAv+WagwCDW4AAAAwAgAAAGAeLFssA=,aOvjyyLA; profile-level-id=64001E\r\n" + |
| 46 | + "m=audio 11113 RTP/AVP 97\r\n" + |
| 47 | + "a=control:trackID=1\n" + // TODO: add this |
| 48 | + "c=IN IP4 127.0.0.1\r\n" + |
| 49 | + "b=AS:69\r\n" + |
| 50 | + "a=rtpmap:97 MPEG4-GENERIC/44100/1\r\n" + |
| 51 | + "a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=120856E500\r\n\r\n"; |
| 52 | + |
| 53 | + server.OverrideSDP(sdp); |
| 54 | + |
| 55 | + try |
| 56 | + { |
| 57 | + server.StartListen(); |
| 58 | + } |
| 59 | + catch (Exception ex) |
| 60 | + { |
| 61 | + Console.WriteLine(ex.ToString()); |
| 62 | + } |
| 63 | + |
| 64 | + Console.WriteLine($"RTSP URL is rtsp://{userName}:{password}@{hostName}:{port}"); |
| 65 | + |
| 66 | + Console.WriteLine("Press any key to exit"); |
| 67 | + while (!Console.KeyAvailable) |
| 68 | + { |
| 69 | + System.Threading.Thread.Sleep(250); |
| 70 | + } |
| 71 | +} |
0 commit comments