HI Glen, 

It seems I have been able to fix the sws_scale problem. I have added
avpicture_fill and it no longer crashes even with srcSlice set to 0.
However, I still get only a green screen. Do you have any idea what could be
wrong with the code that I only have this result? I have attached a picture
of the screen I get if you can access it, and my code is as below. Could the
problem be outside of ffmpeg but in the implementation of opal libraries?

Thank you so much for your help!

Candice


PBoolean PVideoInputDevice_IPCamera::GetFrameDataNoDelay(BYTE *destFrame,
PINDEX * bytesReturned)
{
        int frame_finished;
        struct SwsContext *img_convert_ctx;
        av_init_packet(&pckt);
        
        m_grabCount++;

        if (!is_open)
                return PFalse;
        
        uint8_t *buffer;        // Create buffer to hold picture
        int numBytes;
        // Determine required buffer size and allocate buffer
        numBytes = avpicture_get_size(PIX_FMT_YUV420P,
ip_codec_context->width, ip_codec_context->height);
        buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t));

        // Assign appropriate parts of buffer to image planes in pFrameRGB
        avpicture_fill((AVPicture *)scaled_ip_frame, buffer,
PIX_FMT_YUV420P,
                ip_codec_context->width, ip_codec_context->height);

        int x = av_read_frame(ip_context, &pckt); // Gets the next frame in
the stream

        if(pckt.stream_index == video_stream) 
     {
                int decode = avcodec_decode_video2(ip_codec_context,
raw_ip_frame, &frame_finished, &pckt);

                if(frame_finished)
                {
                         int w = ip_codec_context->width;
                     int h = ip_codec_context->height;
                     img_convert_ctx = sws_getContext(w, h,
ip_codec_context->pix_fmt,
                                   w, h, PIX_FMT_YUV420P, SWS_BICUBIC, NULL,
NULL, NULL);
                         
                         if(img_convert_ctx == NULL)
                      {
                                 return PFalse;
                         }

                          int scaled = sws_scale(img_convert_ctx,
raw_ip_frame->data, raw_ip_frame->linesize, 0,
                                  ip_codec_context->height,
scaled_ip_frame->data, scaled_ip_frame->linesize);

                          // Copy the content of the scaled_ip_frame into
the buffer for destination frame                                         
                          //memcpy(destFrame, scaled_ip_frame, pckt.size);
                          memcpy(destFrame, buffer, pckt.size);
                }

                else
            {
                   PTRACE(1, "frame finished == 0");    
                memcpy(destFrame, pckt.data, pckt.size);
            }
        }

           // Associated with opal functions but converter is always null
for some reason
           if (converter == NULL) 
           {
                   PTRACE(1, "converter is NULL");
                   if (bytesReturned != NULL)
                           *bytesReturned = ip_frame_size;
           } 
  
           else 
       {
                   PTRACE(1, "passed if => converter is not null");
                   PBoolean y = converter->SetSrcFrameSize(ip_frame_width,
ip_frame_height);
                   PTRACE(1, "converter set source frame size = " << y);
                   PTRACE(1, "size of bytesReturnes = " << *bytesReturned);
                   if (!converter->Convert(buffer, destFrame,
bytesReturned))
                   {
                           PTRACE(1, "problem converting it seems");
                           return PFalse;
                   }

                   PTRACE(1, "converting next line");
                   
                   if (bytesReturned != NULL)
                   {
                           PTRACE(1, "bytes Returned is not null");
                   *bytesReturned = converter->GetMaxDstFrameBytes();
                           PTRACE(1, "bytes Returned is not null");
                   }
           }

           PTRACE(1, "grabCount = " << m_grabCount);
   
          
   av_free(img_convert_ctx);
   av_free_packet(&pckt);
   //av_free(raw_ip_frame);
   //av_free(scaled_ip_frame);

   return PTrue;
}

<<attachment: preview.jpg>>

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to