sskodje / ScreenRecorderLib

A .NET library for screen recording in Windows, using native Microsoft Media Foundation for realtime encoding to h264 video or PNG images.
MIT License
414 stars 94 forks source link

How Can i use this to create videostream and push this videostream with ffmpeg to rtmp url #321

Closed Gloria-GK-406 closed 1 month ago

Gloria-GK-406 commented 1 month ago

i create a new stream class to get that lib sended data,and just push this data to ffmpeg.but it not works. i have no experience about ffmpeg and video format

    public class RtmpStream : MemoryStream
    {
        private NamedPipeServerStream _outputStream;

        public RtmpStream(NamedPipeServerStream output)
        {
            if(output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _outputStream = output;
        }

        public override void Flush()
        {
            base.Flush();
        }

        public override long Seek(long offset, SeekOrigin loc)
        {
            return base.Seek(offset, loc);
        }

        public override void SetLength(long value)
        {
            base.SetLength(value);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {          
            base.Write(buffer, offset, count);
            if(_outputStream.IsConnected)
            _outputStream.Write(buffer, offset, count);
        }

        public override void WriteTo(Stream stream)
        {
            base.WriteTo(stream);
        }
    }

here is my stream class.

            _recorder.Record(new RtmpStream(_pipServer));

this is my ffmpeg run command

-re -i \\.\pipe\rtmp_push -c:v libx264 -preset veryfast -f flv "rtmpurl"

please give me some help.thanks

sskodje commented 1 month ago

Hi, i will link a demo project.

https://github.com/sskodje/ScreenRecorderLib/tree/streaming_demo/TestConsoleAppStreaming

Gloria-GK-406 commented 1 month ago

Hi, i will link a demo project.

https://github.com/sskodje/ScreenRecorderLib/tree/streaming_demo/TestConsoleAppStreaming

thanks that works well