tzwenn / pyh264decode

Decode H.264 packets with external avcC to YUV frames
Other
30 stars 6 forks source link

Heavy artifacts, but only in live stream #7

Open heidtn opened 7 years ago

heidtn commented 7 years ago

I'm currently reading a TCP stream from a data source that is sending h264 frames. If I take the raw data and write to a file then later read frame by frame from the same file and pass it through h264decode, it works fine. All of the frames are clear and have minimal artifacting. However, if I instead pass the data directly into an h264decode.Decoder from the live stream, there's horrible streaking and artifacting. Any ideas what could cause this?

tzwenn commented 7 years ago

Can you elaborate on what artifact you see and maybe provide a sample? Also have you tried to buffer/serialize your frames in between in some other dataformat? Do you might have some timing issues, or do the frames not arrive completely?

I've been only processing frames from a TCP stream so far and have not experienced your described behaviour.

heidtn commented 7 years ago

I've uploaded an example of the issues here: badquad

I've tried to buffer the frames as I receive them, but it doesn't seem to fix things at all. I assume the frames arrive completely as saving them to a file first then reading seems to work. Maybe it does have something to do with timing? How could I check?

Here's how I'm extracting frames:

while True:
            count +=1
            try:
                if self.decoder is not None:
                    #data is a full startframe, the first bytes are '\x0\x0\x0\x1'
                    data = pipe.recv_bytes() 
                    yuv = self.decoder.decodeFrame(data)
                    if yuv is not None:
                        #things are done with the frame here
                        #...
                        #...
                else: #this is our first frame with the avcc data
                    self.avcc = pipe.recv_bytes()
                    self.decoder = h264decode.Decoder(self.avcc)    
                    print("initialized decorder")
            except socket.timeout:
                print("error!") 

Any thoughts?