BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
706 stars 284 forks source link

Weird green green picture when save .h264 file and phantom viewed in SimpleRtspPlayer #51

Open Dimigergo opened 5 years ago

Dimigergo commented 5 years ago

Dear Kirill!

We implement this code as @fotels in #34 and save a .h264 file with frames, but as you see the attached file (Rec_20190904_123259.zip) the format has problems. The error occures with both of UDP and TCP protocol. The PacketsLostSinceLastReset property in the code does not incremented, so no packet lost.

if (recordFile != null && frame is RawH264IFrame rawH264IFrame)
{
    recordFile.Write(
        rawH264IFrame.SpsPpsSegment.Array, 
        rawH264IFrame.SpsPpsSegment.Offset, 
        rawH264IFrame.SpsPpsSegment.Count);
    firstIFrameSaved = true;
}

if (firstIFrameSaved && recordFile != null && frame is RawH264Frame)
    recordFile.Write(
        frame.FrameSegment.Array, 
        frame.FrameSegment.Offset, 
        frame.FrameSegment.Count);

What is wrong with me?

When I see the live stream in SimpleRtspPlayer it doesn't have this green picture, it is clear, but sometimes it is phantom viewed.

The ffmpeg decoder writes: nal_error

I don't know, what is my problem. Thanks in advance!

BogdanovKirill commented 5 years ago

Hello,

I'm trying to understand your problem. I played your file in VLC player for several times, but didn't see any green picture.

From your screenshot I could say that FFmpeg don't see 0 0 0 1 start code. Ensure that your NAL units start from 0 0 0 1 bytes