|
21 | 21 | TrakBox audioTrackBox = null; |
22 | 22 | TrakBox videoTrackBox = null; |
23 | 23 | AudioSampleEntryBox audioSampleEntry = null; |
24 | | - double videoFrameRate = 24; |
| 24 | + double videoFrameRate = 0; |
| 25 | + int audioSamplingRate = 0; |
25 | 26 |
|
26 | 27 | // frag_bunny.mp4 audio is not playable in VLC on Windows 11 (works on MacOS) |
27 | 28 | using (Stream fs = new BufferedStream(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))) |
|
37 | 38 | { |
38 | 39 | videoTrackId = fmp4.FindVideoTrackID().First(); |
39 | 40 | videoFrameRate = fmp4.CalculateFrameRate(videoTrackBox); |
| 41 | + |
| 42 | + var h264VisualSample = videoTrackBox.GetMdia().GetMinf().GetStbl().GetStsd().Children.FirstOrDefault(x => x.Type == VisualSampleEntryBox.TYPE3 || x.Type == VisualSampleEntryBox.TYPE4) as VisualSampleEntryBox; |
| 43 | + if (h264VisualSample != null) |
| 44 | + { |
| 45 | + var avcC = (h264VisualSample.Children.First(x => x.Type == AvcConfigurationBox.TYPE) as AvcConfigurationBox).AvcDecoderConfigurationRecord; |
| 46 | + server.VideoTrack = new SharpRTSPServer.H264Track(avcC.AvcProfileIndication, 0, avcC.AvcLevelIndication); |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + var h265VisualSample = videoTrackBox.GetMdia().GetMinf().GetStbl().GetStsd().Children.FirstOrDefault(x => x.Type == VisualSampleEntryBox.TYPE6 || x.Type == VisualSampleEntryBox.TYPE7) as VisualSampleEntryBox; |
| 51 | + if(h265VisualSample != null) |
| 52 | + { |
| 53 | + server.VideoTrack = new SharpRTSPServer.H265Track(); |
| 54 | + } |
| 55 | + else |
| 56 | + { |
| 57 | + throw new NotSupportedException("No supported video found!"); |
| 58 | + } |
| 59 | + } |
40 | 60 | } |
41 | 61 |
|
42 | 62 | if (audioTrackBox != null) |
43 | 63 | { |
44 | 64 | audioTrackId = fmp4.FindAudioTrackID().First(); |
45 | 65 | audioSampleEntry = audioTrackBox.GetAudioSampleEntryBox(); |
| 66 | + |
| 67 | + var aac = audioTrackBox.GetMdia().GetMinf().GetStbl().GetStsd().Children.FirstOrDefault(x => x.Type == AudioSampleEntryBox.TYPE3) as AudioSampleEntryBox; |
| 68 | + if (aac != null) |
| 69 | + { |
| 70 | + var audioConfigDescriptor = audioSampleEntry.GetAudioSpecificConfigDescriptor(); |
| 71 | + audioSamplingRate = audioConfigDescriptor.GetSamplingFrequency(); |
| 72 | + server.AudioTrack = new SharpRTSPServer.AACTrack(await audioConfigDescriptor.ToBytes(), audioSamplingRate, audioConfigDescriptor.ChannelConfiguration); |
| 73 | + } |
46 | 74 | } |
47 | 75 | } |
48 | 76 | } |
|
56 | 84 | { |
57 | 85 | var videoSamplingRate = SharpRTSPServer.H264Track.DEFAULT_CLOCK; |
58 | 86 | var videoSampleDuration = videoSamplingRate / videoFrameRate; |
59 | | - var videoTrack = parsedMDAT[videoTrackId]; |
60 | | - var rtspVideoTrack = new SharpRTSPServer.H264Track(); |
61 | | - server.VideoTrack = rtspVideoTrack; |
| 87 | + var videoTrack = parsedMDAT[videoTrackId]; |
62 | 88 | videoTimer = new Timer(videoSampleDuration * 1000 / videoSamplingRate); |
63 | 89 | videoTimer.Elapsed += (s, e) => |
64 | 90 | { |
65 | 91 | if (videoIndex == 0) |
66 | 92 | { |
67 | | - rtspVideoTrack.SetParameterSets(videoTrack[0][0], videoTrack[0][1]); |
| 93 | + if (server.VideoTrack is SharpRTSPServer.H264Track h264VideoTrack) |
| 94 | + { |
| 95 | + h264VideoTrack.SetParameterSets(videoTrack[0][0], videoTrack[0][1]); |
| 96 | + } |
| 97 | + else if (server.VideoTrack is SharpRTSPServer.H265Track h265VideoTrack) |
| 98 | + { |
| 99 | + h265VideoTrack.SetParameterSets(videoTrack[0][0], videoTrack[0][1], videoTrack[0][2]); |
| 100 | + } |
68 | 101 | videoIndex++; |
69 | 102 | } |
70 | 103 |
|
|
81 | 114 | { |
82 | 115 | var audioSampleDuration = SharpMp4.AACTrack.AAC_SAMPLE_SIZE; |
83 | 116 | var audioTrack = parsedMDAT[audioTrackId]; |
84 | | - var audioConfigDescriptor = audioSampleEntry.GetAudioSpecificConfigDescriptor(); |
85 | | - var audioSamplingRate = audioConfigDescriptor.GetSamplingFrequency(); |
86 | | - var rtspAudioTrack = new SharpRTSPServer.AACTrack(audioSamplingRate, audioConfigDescriptor.ChannelConfiguration); |
87 | | - rtspAudioTrack.SetConfigDescriptor(await audioConfigDescriptor.ToBytes()); |
88 | | - server.AudioTrack = rtspAudioTrack; |
89 | 117 | audioTimer = new Timer(audioSampleDuration * 1000 / audioSamplingRate); |
90 | 118 | audioTimer.Elapsed += (s, e) => |
91 | 119 | { |
|
0 commit comments