[Libav-user] UDP Stream Read Pixelation/Macroblock Corruption

Alex Cohn alexcohn at netvision.net.il
Tue Jun 26 16:38:11 CEST 2012


On Mon, Jun 25, 2012 at 9:59 PM, radparker <radford.parker at gmail.com> wrote:
> I have code working properly to read in a UDP stream for a couple of seconds.
> Soon after, the stream becomes severely pixelated. I have my code below and
> the output of my stream in video form below that. Has anybody seen something
> like this before? I am using libav-0.8.3 and have tried increasing my stack
> size and altering the buffer_size as an input option with the url. I should
> mention that the UDP input stream is multicast and the format is mpegts. Any
> help would be greatly appreciated. Thanks!
>
>
> http://libav-users.943685.n4.nabble.com/file/n4655270/output.mp4 output.mp4
>

while (av_read_frame(format_context, &packet) >= 0){
    // If packet is video
    if(packet.stream_index == video_stream_idx) {
      if (packet.size > 0) {
        frame_finished = 0;
        if (avcodec_decode_video2(codec_context, frame_yuv,
&frame_finished, &packet) >= 0) {
          // Did we get a video frame?
          if(frame_finished) {
            // Convert the image from its native format to RGB
            sws_scale(sws_context, frame_yuv->data, frame_yuv->linesize,
                      0, codec_context->height, frame_bgr->data,
frame_bgr->linesize);
            if(fskip == 1) {
              ptr1 = frame_bgr->data[0]+ m * frame_bgr->linesize[0];
              ptr2 = frame.data + m * frame.cols * 3;
              // Convert Frame
              for(m = 0; m < codec_context->height; ++m) {
                memcpy(ptr2, ptr1, 3 * frame.cols);
                ptr1 += frame_bgr->linesize[0];
                ptr2 += frame.cols * 3;
              }
              fskip=0;
              break;
            }
            fskip++;
          }
        }
      }
    }
  }

> --
> View this message in context: http://libav-users.943685.n4.nabble.com/UDP-Stream-Read-Pixelation-Macroblock-Corruption-tp4655270.html

Your message does not contain the code snippet when looked at from the
mail list. On nabble, I see that there is at least one problem with
your loop: you should call avcodec_decode_video2() with null packet to
extract frames that are "stuck" inside the decoder queue. Normally, we
do it when the input is empty. But maybe you should try it on packets
of size == 0?

BR,
Alex


More information about the Libav-user mailing list