static void Main(string[] args) { //String url = "rtsp://192.168.1.128/ch1.h264"; // IPS String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=quality_h264"; // Axis //String url = "rtsp://*****:*****@192.168.1.102/onvif-media/media.amp?profile=quality_h264"; // Axis //String url = "rtsp://192.168.1.124/rtsp_tunnel?h26x=4&line=1&inst=1"; // Bosch //String url = "rtsp://192.168.1.121:8554/h264"; // Raspberry Pi RPOS using Live555 //String url = "rtsp://192.168.1.121:8554/h264m"; // Raspberry Pi RPOS using Live555 in Multicast mode //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://192.168.1.160:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin // String url = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; // MJPEG Tests (Payload 26) //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=mobile_jpeg"; // Create a RTSP Client RTSPClient c = new RTSPClient(url, RTSPClient.RTP_TRANSPORT.TCP); // Wait for user to terminate programme // Check for null which is returned when running under some IDEs Console.WriteLine("Press ENTER to exit"); String readline = null; while (readline == null) { readline = Console.ReadLine(); // Avoid maxing out CPU on systems that instantly return null for ReadLine if (readline == null) { Thread.Sleep(500); } } c.Stop(); }
static void Main(string[] args) { //String url = "rtsp://192.168.1.128/ch1.h264"; // IPS //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=quality_h264"; // Axis //String url = "rtsp://192.168.1.124/rtsp_tunnel?h26x=4&line=1&inst=1"; // Bosch //String url = "rtsp://192.168.1.121:8554/h264"; // Raspberry Pi RPOS using Live555 //String url = "rtsp://192.168.1.121:8554/h264m"; // Raspberry Pi RPOS using Live555 in Multicast mode //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin String url = "rtsp://192.168.1.160:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; // Create a RTSP Client RTSPClient c = new RTSPClient(url, RTSPClient.RTP_TRANSPORT.TCP); // Wait for user to terminate programme Console.WriteLine("Press ENTER to exit"); String dummy = Console.ReadLine(); c.Stop(); }
static void Main(string[] args) { //String url = "rtsp://192.168.1.128/ch1.h264"; // IPS //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=quality_h264"; // Axis //String url = "rtsp://*****:*****@192.168.1.102/onvif-media/media.amp?profile=quality_h264"; // Axis //String url = "rtsp://192.168.1.124/rtsp_tunnel?h26x=4&line=1&inst=1"; // Bosch //String url = "rtsp://192.168.1.33:8554/unicast"; // Raspberry Pi RPOS using Mpromonet Live555 server //String url = "rtsp://192.168.1.33:8554/h264"; // Raspberry Pi RPOS using Live555 //String url = "rtsp://192.168.1.121:8554/h264"; // Raspberry Pi RPOS using Live555 //String url = "rtsp://192.168.1.121:8554/h264m"; // Raspberry Pi RPOS using Live555 in Multicast mode //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://192.168.1.160:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; //String url = "rtsp://192.168.83.12:554"; string url = "rtsp://192.168.83.12:554/user=admin&password=&channel=1&stream=0.sdp?"; // MJPEG Tests (Payload 26) //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=mobile_jpeg"; String now = DateTime.Now.ToString("yyyyMMdd_HHmmss"); FileStream fs_v = null; // used to write the NALs to a .264 file FileStream fs_a = null; // used to write the G711 audio to a .g711 file // Create a RTSP Client RTSPClient c = new RTSPClient(); c.Received_SPS_PPS += (byte[] sps, byte[] pps) => { if (fs_v == null) { String filename = "rtsp_capture_" + now + ".264"; fs_v = new FileStream(filename, FileMode.Create); } if (fs_v != null) { fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(sps, 0, sps.Length); fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(pps, 0, pps.Length); fs_v.Flush(true); } }; c.Received_NALs += (List <byte[]> nal_units) => { if (fs_v != null) { foreach (byte[] nal_unit in nal_units) { fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(nal_unit, 0, nal_unit.Length); // Write NAL } fs_v.Flush(true); } }; c.Received_G711 += (string format, List <byte[]> g711) => { if (fs_a == null && format.Equals("PCMU")) { String filename = "rtsp_capture_" + now + ".ul"; fs_a = new FileStream(filename, FileMode.Create); } if (fs_a == null && format.Equals("PCMA")) { String filename = "rtsp_capture_" + now + ".al"; fs_a = new FileStream(filename, FileMode.Create); } if (fs_a != null) { foreach (byte[] data in g711) { fs_a.Write(data, 0, data.Length); } } }; // Connect to RTSP Server Console.WriteLine("Connecting"); c.Connect(url, RTSPClient.RTP_TRANSPORT.TCP); // Wait for user to terminate programme // Check for null which is returned when running under some IDEs // OR wait for the Streaming to Finish - eg an error on the RTSP socket Console.WriteLine("Press ENTER to exit"); String readline = null; while (readline == null && c.StreamingFinished() == false) { readline = Console.ReadLine(); // Avoid maxing out CPU on systems that instantly return null for ReadLine if (readline == null) { Thread.Sleep(500); } } c.Stop(); Console.WriteLine("Finished"); }
public async Task Snapshot(string name, string username, string password, string url) { //Stream fs_v = null; MemoryStream fs_v = null; var client = new RTSPClient(); var ts = DateTime.MaxValue; client.ParameterSetsReceived += async(byte [] sps, byte [] pps) => { if (fs_v == null) { fs_v = new MemoryStream(4 * 1024); //fs_v = new FileStream ($"{name.Replace (" ", "_")}.h264", FileMode.Create); } if (fs_v != null) { await fs_v.WriteAsync(new byte [] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code await fs_v.WriteAsync(sps, 0, sps.Length); await fs_v.WriteAsync(new byte [] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code await fs_v.WriteAsync(pps, 0, pps.Length); } }; client.FrameReceived += async(List <byte []> nal_units) => { if (fs_v != null) { foreach (byte [] nal_unit in nal_units) { await fs_v.WriteAsync(new byte [] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code await fs_v.WriteAsync(nal_unit, 0, nal_unit.Length); // Write NAL } await fs_v.FlushAsync(); if (DateTime.Now > ts) { client.Stop(); } } }; try { // Connect to RTSP Server Console.WriteLine($"Connecting {url}..."); client.Timeout = 3000; client.Connect(url, username, password); ts = DateTime.Now.AddSeconds(5); // time to capture video while (!client.IsStreamingFinished()) { await Task.Delay(100); } if (fs_v != null) { File.WriteAllBytes($"{name.Replace (" ", "_")}.h264", fs_v.ToArray()); await ExecConverter(fs_v, $"{name.Replace (" ", "_")}.jpg", 1280, 720); fs_v.Close(); fs_v.Dispose(); } else { Console.WriteLine($"Empty Streaming"); } } catch (Exception ex) { Console.WriteLine($"Message: {ex.Message}"); Console.WriteLine($"StackTrace: {ex.StackTrace}"); } }
static void Main(string[] args) { String url = "rtsp://admin:@192.168.17.92"; String now = DateTime.Now.ToString("yyyyMMdd_HHmmss"); FileStream fs_v = null; // used to write the video FileStream fs_a = null; // used to write the audio bool h264 = false; bool h265 = false; // Create a RTSP Client RTSPClient c = new RTSPClient(); // The SPS/PPS comes from the SDP data // or it is the first SPS/PPS from the H264 video stream c.Received_SPS_PPS += (byte[] sps, byte[] pps) => { h264 = true; if (fs_v == null) { String filename = "rtsp_capture_" + now + ".264"; fs_v = new FileStream(filename, FileMode.Create); } if (fs_v != null) { fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(sps, 0, sps.Length); fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(pps, 0, pps.Length); fs_v.Flush(true); } }; c.Received_VPS_SPS_PPS += (byte[] vps, byte[] sps, byte[] pps) => { h265 = true; if (fs_v == null) { String filename = "rtsp_capture_" + now + ".265"; fs_v = new FileStream(filename, FileMode.Create); } if (fs_v != null) { fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(vps, 0, vps.Length); fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(sps, 0, sps.Length); fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(pps, 0, pps.Length); fs_v.Flush(true); } }; // Video NALs. May also include the SPS and PPS in-band for H264 c.Received_NALs += (List <byte[]> nal_units) => { if (fs_v != null) { foreach (byte[] nal_unit in nal_units) { // Output some H264 stream information if (h264 && nal_unit.Length > 0) { int nal_ref_idc = (nal_unit[0] >> 5) & 0x03; int nal_unit_type = nal_unit[0] & 0x1F; String description = ""; if (nal_unit_type == 1) { description = "NON IDR NAL"; } else if (nal_unit_type == 5) { description = "IDR NAL"; } else if (nal_unit_type == 6) { description = "SEI NAL"; } else if (nal_unit_type == 7) { description = "SPS NAL"; } else if (nal_unit_type == 8) { description = "PPS NAL"; } else if (nal_unit_type == 9) { description = "ACCESS UNIT DELIMITER NAL"; } else { description = "OTHER NAL"; } Console.WriteLine("NAL Ref = " + nal_ref_idc + " NAL Type = " + nal_unit_type + " " + description); } // Output some H265 stream information if (h265 && nal_unit.Length > 0) { int nal_unit_type = (nal_unit[0] >> 1) & 0x3F; String description = ""; if (nal_unit_type == 1) { description = "NON IDR NAL"; } else if (nal_unit_type == 19) { description = "IDR NAL"; } else if (nal_unit_type == 32) { description = "VPS NAL"; } else if (nal_unit_type == 33) { description = "SPS NAL"; } else if (nal_unit_type == 34) { description = "PPS NAL"; } else if (nal_unit_type == 39) { description = "SEI NAL"; } else { description = "OTHER NAL"; } Console.WriteLine("NAL Type = " + nal_unit_type + " " + description); } fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(nal_unit, 0, nal_unit.Length); // Write NAL } fs_v.Flush(true); } }; c.Received_G711 += (string format, List <byte[]> g711) => { if (fs_a == null && format.Equals("PCMU")) { String filename = "rtsp_capture_" + now + ".ul"; fs_a = new FileStream(filename, FileMode.Create); } if (fs_a == null && format.Equals("PCMA")) { String filename = "rtsp_capture_" + now + ".al"; fs_a = new FileStream(filename, FileMode.Create); } if (fs_a != null) { foreach (byte[] data in g711) { fs_a.Write(data, 0, data.Length); } } }; c.Received_AMR += (string format, List <byte[]> amr) => { if (fs_a == null && format.Equals("AMR")) { String filename = "rtsp_capture_" + now + ".amr"; fs_a = new FileStream(filename, FileMode.Create); byte[] header = new byte[] { 0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A }; // #!AMR<0x0A> fs_a.Write(header, 0, header.Length); } if (fs_a != null) { foreach (byte[] data in amr) { fs_a.Write(data, 0, data.Length); } } }; c.Received_AAC += (string format, List <byte[]> aac, uint ObjectType, uint FrequencyIndex, uint ChannelConfiguration) => { if (fs_a == null) { String filename = "rtsp_capture_" + now + ".aac"; fs_a = new FileStream(filename, FileMode.Create); } if (fs_a != null) { foreach (byte[] data in aac) { // ASDT header format int protection_absent = 1; // int profile = 2; // Profile 2 = AAC Low Complexity (LC) // int sample_freq = 4; // 4 = 44100 Hz // int channel_config = 2; // 2 = Stereo Rtsp.BitStream bs = new Rtsp.BitStream(); bs.AddValue(0xFFF, 12); // (a) Start of data bs.AddValue(0, 1); // (b) Version ID, 0 = MPEG4 bs.AddValue(0, 2); // (c) Layer always 2 bits set to 0 bs.AddValue(protection_absent, 1); // (d) 1 = No CRC bs.AddValue((int)ObjectType - 1, 2); // (e) MPEG Object Type / Profile, minus 1 bs.AddValue((int)FrequencyIndex, 4); // (f) bs.AddValue(0, 1); // (g) private bit. Always zero bs.AddValue((int)ChannelConfiguration, 3); // (h) bs.AddValue(0, 1); // (i) originality bs.AddValue(0, 1); // (j) home bs.AddValue(0, 1); // (k) copyrighted id bs.AddValue(0, 1); // (l) copyright id start bs.AddValue(data.Length + 7, 13); // (m) AAC data + size of the ASDT header bs.AddValue(2047, 11); // (n) buffer fullness ??? int num_acc_frames = 1; bs.AddValue(num_acc_frames - 1, 1); // (o) num of AAC Frames, minus 1 // If Protection was On, there would be a 16 bit CRC if (protection_absent == 0) { bs.AddValue(0xABCD /*CRC*/, 16); // (p) } byte[] header = bs.ToArray(); fs_a.Write(header, 0, header.Length); fs_a.Write(data, 0, data.Length); } } }; // Connect to RTSP Server Console.WriteLine("Connecting"); c.Connect(url, RTSPClient.RTP_TRANSPORT.TCP); // Wait for user to terminate programme // Check for null which is returned when running under some IDEs // OR wait for the Streaming to Finish - eg an error on the RTSP socket Console.WriteLine("Press ENTER to exit"); String readline = null; while (readline == null && c.StreamingFinished() == false) { readline = Console.ReadLine(); // Avoid maxing out CPU on systems that instantly return null for ReadLine if (readline == null) { Thread.Sleep(500); } } c.Stop(); Console.WriteLine("Finished"); Console.WriteLine("Press ENTER to exit"); while (readline == null) { readline = Console.ReadLine(); // Avoid maxing out CPU on systems that instantly return null for ReadLine if (readline == null) { Thread.Sleep(500); } } }
static void Main(string[] args) { //String url = "rtsp://192.168.1.128/ch1.h264"; // IPS //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=quality_h264"; // Axis //String url = "rtsp://*****:*****@192.168.1.102/onvif-media/media.amp?profile=quality_h264"; // Axis //String url = "rtsp://192.168.1.124/rtsp_tunnel?h26x=4&line=1&inst=1"; // Bosch //String url = "rtsp://192.168.1.121:8554/h264"; // Raspberry Pi RPOS using Live555 //String url = "rtsp://192.168.1.121:8554/h264m"; // Raspberry Pi RPOS using Live555 in Multicast mode //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://192.168.1.160:8554/h264ESVideoTest"; // Live555 Cygwin //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; // Live555 Cygwin String url = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; // MJPEG Tests (Payload 26) //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=mobile_jpeg"; DateTime time_check = DateTime.Now; // Holds the time 'Play' started or the time of the last NAL StreamMode current_mode = StreamMode.Play; StreamMode requested_mode = StreamMode.Play; // Create a RTSP Client. This is created in a Task so that it can connect (and re-connect) // in parallel with the User Interface (readline) Task rtspTask = new Task(delegate { // Keep looping until want_video is false while (requested_mode != StreamMode.Stop) { RTSPClient c = new RTSPClient(url, RTSPClient.RTP_TRANSPORT.TCP); c.Received_SPS32_PPS32 += (byte[] sps32, byte[] pps32) => { Console.WriteLine("Received SPS and PPS from RTSP Client"); // Pass this data into a H264 decoder }; c.Received_NAL32 += (byte[] nal32) => { Console.WriteLine("Received NALs from RTSP Client"); time_check = DateTime.Now; // Pass this data into a H264 decoder }; time_check = DateTime.Now; current_mode = StreamMode.Play; // busy-wait loop // Check Connection Status (on RTSP Socket. // Check when last NAL arrived // Check User Intetface requests while ((c.CurrentStatus == RtspStatus.Connecting || c.CurrentStatus == RtspStatus.Connected) && requested_mode != StreamMode.Stop) { if (requested_mode == StreamMode.Play && current_mode != StreamMode.Play) { c.Play(); time_check = DateTime.Now; current_mode = StreamMode.Play; } if (requested_mode == StreamMode.Pause && current_mode != StreamMode.Pause) { c.Pause(); current_mode = StreamMode.Pause; } if (current_mode == StreamMode.Play && (DateTime.Now - time_check).TotalSeconds > 10) { // No NALs received in the last 10 seconds. Assume the stream has failed. Disconnect & Reconnect current_mode = StreamMode.Stop; c.Stop(); // Stop closes the RTSP Socket. Status will change to Disconnected } Thread.Sleep(250); } // User requested stop, or Status gives a connection error. c.Stop(); // Wait 1 second before reconnecting, if we still want video if (requested_mode != StreamMode.Stop) { Thread.Sleep(1000); } } }); rtspTask.Start(); // Wait for user to terminate programme // Check for null which is returned when running under some IDEs Console.WriteLine("Press 1 then ENTER to play"); Console.WriteLine("Press 2 then ENTER to pause"); Console.WriteLine("Press Q then ENTER to quit"); String readline = null; while (requested_mode != StreamMode.Stop) { readline = Console.ReadLine(); if (readline == null) { // Avoid maxing out CPU on systems that instantly return null for ReadLine Thread.Sleep(500); } else if (readline.Equals("1")) { requested_mode = StreamMode.Play; } else if (readline.Equals("2")) { requested_mode = StreamMode.Pause; } else if (readline.ToUpper().Equals("Q")) { requested_mode = StreamMode.Stop; } } rtspTask.Wait(); // wait for Task to complete before exiting }
static void Main(string[] args) { // Internet Test - Big Buck Bunney String url = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; // IPS IP Camera Tests //String url = "rtsp://192.168.1.128/ch1.h264"; // Axis Tests //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=quality_h264"; //String url = "rtsp://*****:*****@192.168.1.102/onvif-media/media.amp?profile=quality_h264"; // Bosch Tests //String url = "rtsp://192.168.1.124/rtsp_tunnel?h26x=4&line=1&inst=1"; // 360 Vision Tests //String url = "rtsp://192.168.1.187/h264main"; // Live555 Server Tests (ONVIF RPOS PROJECT) //String url = "rtsp://192.168.1.33:8554/unicast"; // Raspberry Pi RPOS using Mpromonet Live555 server //String url = "rtsp://192.168.1.33:8554/h264"; // Raspberry Pi RPOS using Live555 //String url = "rtsp://192.168.1.121:8554/h264"; // Raspberry Pi RPOS using Live555 //String url = "rtsp://192.168.1.121:8554/h264m"; // Raspberry Pi RPOS using Live555 in Multicast mode // Live555 Server Tests //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; //String url = "rtsp://192.168.1.160:8554/h264ESVideoTest"; //String url = "rtsp://127.0.0.1:8554/h264ESVideoTest"; //String url = "rtsp://192.168.1.79:8554/amrAudioTest"; // VLC Server Tests // String url = "rtsp://192.168.1.150:8554/test"; // MJPEG Tests (Payload 26) //String url = "rtsp://192.168.1.125/onvif-media/media.amp?profile=mobile_jpeg"; // H265 Tests String now = DateTime.Now.ToString("yyyyMMdd_HHmmss"); FileStream fs_v = null; // used to write the video FileStream fs_a = null; // used to write the audio bool h264 = false; bool h265 = false; // Create a RTSP Client RTSPClient c = new RTSPClient(); // The SPS/PPS comes from the SDP data // or it is the first SPS/PPS from the H264 video stream c.Received_SPS_PPS += (byte[] sps, byte[] pps) => { h264 = true; if (fs_v == null) { String filename = "rtsp_capture_" + now + ".264"; fs_v = new FileStream(filename, FileMode.Create); } if (fs_v != null) { fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(sps, 0, sps.Length); fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(pps, 0, pps.Length); fs_v.Flush(true); } }; c.Received_VPS_SPS_PPS += (byte[] vps, byte[] sps, byte[] pps) => { h265 = true; if (fs_v == null) { String filename = "rtsp_capture_" + now + ".265"; fs_v = new FileStream(filename, FileMode.Create); } if (fs_v != null) { fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(vps, 0, vps.Length); fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(sps, 0, sps.Length); fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(pps, 0, pps.Length); fs_v.Flush(true); } }; // Video NALs. May also include the SPS and PPS in-band for H264 c.Received_NALs += (List <byte[]> nal_units) => { if (fs_v != null) { foreach (byte[] nal_unit in nal_units) { // Output some H264 stream information if (h264 && nal_unit.Length > 0) { int nal_ref_idc = (nal_unit[0] >> 5) & 0x03; int nal_unit_type = nal_unit[0] & 0x1F; String description = ""; if (nal_unit_type == 1) { description = "NON IDR NAL"; } else if (nal_unit_type == 5) { description = "IDR NAL"; } else if (nal_unit_type == 6) { description = "SEI NAL"; } else if (nal_unit_type == 7) { description = "SPS NAL"; } else if (nal_unit_type == 8) { description = "PPS NAL"; } else if (nal_unit_type == 9) { description = "ACCESS UNIT DELIMITER NAL"; } else { description = "OTHER NAL"; } Console.WriteLine("NAL Ref = " + nal_ref_idc + " NAL Type = " + nal_unit_type + " " + description); } fs_v.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, 4); // Write Start Code fs_v.Write(nal_unit, 0, nal_unit.Length); // Write NAL } fs_v.Flush(true); } }; c.Received_G711 += (string format, List <byte[]> g711) => { if (fs_a == null && format.Equals("PCMU")) { String filename = "rtsp_capture_" + now + ".ul"; fs_a = new FileStream(filename, FileMode.Create); } if (fs_a == null && format.Equals("PCMA")) { String filename = "rtsp_capture_" + now + ".al"; fs_a = new FileStream(filename, FileMode.Create); } if (fs_a != null) { foreach (byte[] data in g711) { fs_a.Write(data, 0, data.Length); } } }; c.Received_AMR += (string format, List <byte[]> amr) => { if (fs_a == null && format.Equals("AMR")) { String filename = "rtsp_capture_" + now + ".amr"; fs_a = new FileStream(filename, FileMode.Create); byte[] header = new byte[] { 0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A }; // #!AMR<0x0A> fs_a.Write(header, 0, header.Length); } if (fs_a != null) { foreach (byte[] data in amr) { fs_a.Write(data, 0, data.Length); } } }; // Connect to RTSP Server Console.WriteLine("Connecting"); c.Connect(url, RTSPClient.RTP_TRANSPORT.TCP); // Wait for user to terminate programme // Check for null which is returned when running under some IDEs // OR wait for the Streaming to Finish - eg an error on the RTSP socket Console.WriteLine("Press ENTER to exit"); String readline = null; while (readline == null && c.StreamingFinished() == false) { readline = Console.ReadLine(); // Avoid maxing out CPU on systems that instantly return null for ReadLine if (readline == null) { Thread.Sleep(500); } } c.Stop(); Console.WriteLine("Finished"); }