Skip to content

Commit b9a97bf

Browse files
author
Dogancan Ozturk
committed
Merge branch 'develop' of https://github.com/ReferenceType/H264Sharp into develop
2 parents 83e06e0 + 21b2dd8 commit b9a97bf

File tree

1 file changed

+48
-53
lines changed

1 file changed

+48
-53
lines changed

README.md

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
# H264Sharp
2+
23
Cisco's OpenH264 Native facade/wrapper for .Net with highly optimised SIMD color format conversion support. It is very suitable for realtime streaming over network.
34

45
SIMD color format converters are up to 2.9x faster than OpenCV implementation.
56

67
- Cross Platform
78
- Plug&Play
89
- Tested on .NetFramework and Net(up to 8), Windows & Linux & Android (x86 and Arm).
10+
911
- No memory leaks or GC pressure.
1012
- Compatible with OpenCV.(i.e. OpenCVsharp)
1113

1214
Cisco Openh264 is chosen for its unbeatible performance compared to other available software encoders. A paper involving performance metrics can be found here:
1315
<br>https://iopscience.iop.org/article/10.1088/1757-899X/1172/1/012036/pdf</br>
1416

17+
1518
Library consist of native dll which acts as OpenH264 wrapper/facade and color format converter (YUV <-> RGB,BGR,RGBA,BGRA)
16-
<br/>Converters are vectorised(AVX2 or SSE for x86, Neon for Arm) and can be configured for parallelisation.
19+
1720

1821
C# library is .Net standard wrapper library for this dll and performs PInvoke to handle transcoding.
1922
## Nuget
20-
Install the nuget package and its ready to go. All native dependencies are automatically installed and will apepear on your executable directory.
21-
Binaries also provided on release section.
23+
24+
25+
Install the NuGet package. All native dependencies should be automatically installed and resolved.
26+
- Tested on Windows, Linux, Linux ARM, Android MAUI app(x86 on emulator, Arm64 on Pixel phone).
27+
28+
Binaries also provided on [Relases](https://github.com/ReferenceType/H264Sharp/releases).
2229

2330
H264Sharp
2431
<br>[![NuGet](https://img.shields.io/nuget/v/H264Sharp)](https://www.nuget.org/packages/H264Sharp)
2532

33+
2634
H264SharpBitmapExtentions
2735
<br>[![NuGet](https://img.shields.io/nuget/v/H264SharpBitmapExtentions)](https://www.nuget.org/packages/H264SharpBitmapExtentions)
2836

@@ -34,9 +42,11 @@ Defines.CiscoDllName64bit = "{YourPath}/openh264-2.4.0-win64.dll";
3442
## Example
3543
Examples can be found on examples directroy.
3644

37-
Following code shows encoder and decoder in action, commented lines are for hints.
38-
``` c#
45+
Following code shows minimalist example of encoder and decoder in action.
46+
47+
<ins>For detailed information and documentation please check out [Wiki](https://github.com/ReferenceType/H264Sharp/wiki) page</ins>
3948

49+
``` csharp
4050
static void Main(string[] args)
4151
{
4252
var img = System.Drawing.Image.FromFile("ocean 1920x1080.jpg");
@@ -53,48 +63,28 @@ static void Main(string[] args)
5363
RgbImage rgbIn = bitmap.ToRgbImage();
5464
RgbImage rgbOut = new RgbImage(H264Sharp.ImageFormat.Rgb, w, h);
5565

56-
for (int j = 0; j < 1; j++)
66+
for (int j = 0; j < 100; j++)
5767
{
68+
// Encode
69+
if (!encoder.Encode(rgbIn, out var encodedFrames))
70+
continue;//skipped
5871
59-
if (!encoder.Encode(rgbIn, out EncodedData[] ec))
60-
{
61-
Console.WriteLine("skipped");
62-
continue;
63-
}
64-
65-
/* You can manupulate encoder settings on runtime. */
66-
//encoder.ForceIntraFrame();
67-
//encoder.SetMaxBitrate(2000000);
68-
//encoder.SetTargetFps(16.9f);
69-
70-
foreach (var encoded in ec)
72+
// Decode
73+
foreach (var encoded in encodedFrames)
7174
{
72-
bool keyframe = encoded.FrameType == FrameType.I
73-
|| encoded.FrameType == FrameType.IDR;
74-
75-
/* You can extract the bytes */
76-
//encoded.GetBytes();
77-
//encoded.CopyTo(buffer,offset);
78-
79-
8075
if (decoder.Decode(encoded, noDelay: true, out DecodingState ds, ref rgbOut))
8176
{
82-
//Console.WriteLine($"F:{encoded.FrameType} size: {encoded.Length}");
83-
//var result = rgbOut.ToBitmap();
84-
//result.Save("OUT2.bmp");
85-
77+
// Process rgbOut
8678
}
87-
8879
}
89-
}
80+
}
9081
}
91-
92-
encoder.Dispose();
93-
decoder.Dispose();
9482
```
9583
Bitmaps are not included on library to keep it cross platform.
9684
An extention library is provided for windows.
97-
<br/>For the bitmaps and other image container types, an extention library is provided.
85+
86+
For the bitmaps and other image container types, an extention library is provided.
87+
9888
``` c#
9989
RgbImage rgb = new RgbImage(H264Sharp.ImageFormat.Rgb, w, h);
10090
Bitmap bmp = rgb.ToBitmap();
@@ -104,7 +94,8 @@ And to extract bitmap data:
10494
Bitmap bitmap;// some bitmap
10595
RgbImage rgb = bitmap.ToRgbImage();
10696
```
107-
# Info & Tips
97+
## Quick Tips
98+
For detailed information and documentation please check out [Wiki](https://github.com/ReferenceType/H264Sharp/wiki) page
10899
### Data
109100
Data classes can use existing memory or allocate one for you
110101
```c#
@@ -147,7 +138,7 @@ ec.CopyAllTo(buffer,offset);
147138

148139
```
149140
On single layer(standard use case) for IDR frames you get more than one EncodedData, the first frame is a metadata and it will produce neither an image nor an error when decoded.<br/>
150-
Decoder can work with both frame by frame or merged. I personally merge the encoded frames into single array and decode them on single shot.
141+
Decoder can work with both frame by frame or merged.
151142

152143
### Decoder
153144
Decoder has the API:
@@ -165,11 +156,12 @@ API Where:<br/>
165156

166157
If methods return false means there is no image and you need to check DecodingState.
167158
Otherwise there is an image but, on lossy link you still need to check DecodingState for error and perform necessary action(i.e. perform IDR refresh request to encoder).
168-
### Tips
159+
#### Tips
169160
- Raw image bytes are large, avoid allocating new ones and try to reuse same RgbImage or YuvImage or pool them in something like concurrent bag.
170161

171-
# Advanced Configuration & Features
172-
## Advanced Setup
162+
For more information refer to [Tutorial](https://github.com/ReferenceType/H264Sharp/wiki/Tutorial)
163+
## Advanced Configuration & Features
164+
### Advanced Setup
173165
If you want to initialise your encoder and able to control everything, you can use provided API which is identical to Ciso C++ Release.
174166
```c#
175167
encoder = new H264Encoder();
@@ -246,15 +238,18 @@ Neon is only active on arm and does nothing on x86 systems.
246238

247239
```c#
248240
var config = Converter.GetCurrentConfig();
241+
249242
config.EnableSSE = 1;
250243
config.EnableNeon = 1;
251244
config.EnableAvx2 = 1;
252245
config.NumThreads = 4;
246+
253247
config.EnableCustomThreadPool = 1;
254248
Converter.SetConfig(config);
255249

256250
// Or like..
257251
Converter.SetOption(ConverterOption.NumThreads, 8);
252+
258253
```
259254
#### Converter Bechmarks
260255
H264Sharp conversion operations are up to 2.9x faster than OpenCV implementations.
@@ -281,29 +276,29 @@ Intel i7 10600U Laptop CPU
281276
## Options
282277
You can get and set options to decoder and encoder on runtime. All options API is implemented 1-1 with cisco api.
283278

284-
```c#
279+
```csharp
285280
encoder.SetOption(ENCODER_OPTION.ENCODER_OPTION_IDR_INTERVAL, 600);
286281
encoder.GetOption(ENCODER_OPTION.ENCODER_OPTION_IDR_INTERVAL, out int idrPeriod);
287282
decoder.GetOption(DECODER_OPTION.DECODER_OPTION_FRAME_NUM, out tempInt);
288-
...
283+
284+
// If you want to reuse your option structs for efficiency:
285+
SEncoderStatistics ss;
286+
SDecoderStatistics ss1;
287+
encoder.GetOptionRef(ENCODER_OPTION.ENCODER_OPTION_GET_STATISTICS, ref ss);
288+
decoder.GetOptionRef(DECODER_OPTION.DECODER_OPTION_GET_STATISTICS, ref ss1);
289289
```
290290

291291
There are many possible options and they are commented on the enum fields as well as required types. If you want more detail, search as general H264 options.
292-
<br/>Because you wont find any documentation on cisco side RTFC(Read the F. code) pinciple.
292+
<br/>Because you wont find any documentation on cisco side.
293+
293294

294-
If you want to reuse your option structs for efficiency, you can use this method:
295-
```c#
296-
SEncoderStatistics ss;
297-
SDecoderStatistics ss1;
298-
encoder.GetOptionRef(ENCODER_OPTION.ENCODER_OPTION_GET_STATISTICS, ref ss);
299-
decoder.GetOptionRef(DECODER_OPTION.DECODER_OPTION_GET_STATISTICS, ref ss1);
300-
```
301295
# Example App
302-
A simple example WPF application(quick & dirty) is provided. This app emulates advanced use cases for the lossy transfers.
296+
297+
A simple example WPF application is provided. This app emulates advanced use cases for the lossy transfers(loss&jitter) leveraging LTR references.
298+
303299
here you can explore:
304300
- Advanced Setup and their effects.
305301
- Using LTR references and loss recovery.
306-
- Recording audio and video.
307302
<img src="https://github.com/ReferenceType/H264Sharp/assets/109621184/e530be0b-30df-4937-b5e5-6a5e970c81ba" width=50% height=50%>
308303

309304

0 commit comments

Comments
 (0)