Encoding H.264 Stream from Bitmap images

Topics: Question
Oct 1, 2015 at 12:56 PM
Hello, in my app I need to braodcast rtsp stream from bitmap images,
I do it with code like this:
            using (RtspServer server = new RtspServer())
            {
                var jpegMedia = new JPEGMedia("jpegsource", new Uri("", UriKind.Relative));
                
                server.TryAddMedia(jpegMedia);

                server.Start();
                Console.WriteLine(server.LocalEndPoint);

                while(!Console.KeyAvailable)
                {
                    Bitmap bmp = GetImage();
                    
                    jpegMedia.Packetize(bmp);

                    Thread.Sleep(50);
                }

                Console.ReadLine();
            }
it produces rtsp stream with motion-jpeg video
Is it possible to explicitly set codec to h264 with JPEGMedia and RtspServer?
Coordinator
Oct 1, 2015 at 6:55 PM
Thanks for checking out the library!

There is a layman example for H.264 encoding, see the RFC6184Media class, there is more planned but nothing I can release as of yet.
Marked as answer by juliusfriedman on 10/1/2015 at 10:55 AM
Oct 5, 2015 at 12:30 PM
Hello, Julius! Thanks, the RFC6184Media class seems to be what I need, but Ihave some troubles with it.
Packetize method always throws NotSupportedException "Only ARGB is currently supported" though
I pass a bitmap with pixelformat Format32bppArgb.
Code:
var bitmap32 = new Bitmap(_width, _height, PixelFormat.Format32bppArgb);

using (var g = Graphics.FromImage(bitmap32))
{
    g.DrawImage(myBitmap, new Rectangle(0, 0, _width, _height));
 }

rfc6148Media.Packetize(bitmap32);
Packetize uses Image.GetThumbnailImage which seems to return a bitmap of fromat PixelFormat.Format32bppPArgb
no matter of original bitmap format.

Am I missing something or doing something wrong?
Coordinator
Oct 6, 2015 at 3:44 PM
See the API for GetThumbnailImage
https://msdn.microsoft.com/en-us/library/windows/desktop/ms535394(v=vs.85).aspx

DrawImage is a better candidate function for now, I eventually have plans to add my own Image construct.
Marked as answer by juliusfriedman on 10/6/2015 at 7:44 AM
Coordinator
Mar 11, 2016 at 6:19 PM
Hey, I have started to work out the basics for raw image formats and would like to know if your still interested in this.

I would also be able to implement a small I frame only decoder as its the reverse of the encoding.

I could probably do the same for mpeg 1 / 2 as well.

Let me know if your still interested in this!
Marked as answer by juliusfriedman on 3/11/2016 at 10:19 AM