Hi again!
Scratch my last email, it's still not working with srcSLiceY=0. I am saving
the scaled frame into an AVFrame that has been initialized. Here is the code
I am using. I really don't understand why it is not working. The video
display class then access the destFrame buffer to display the video image
(which actually gives me only a green screen, still don't know why).
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;
BYTE * readBuffer = destFrame;
if (converter != NULL)
{
readBuffer = frameStore.GetPointer(ip_frame_size);
}
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(raw_ip_frame->data == NULL)
PTRACE(1, "problem with raw_ip_frame. IT'S NULL");
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_RGB32, SWS_BICUBIC, NULL,
NULL, NULL);
if(img_convert_ctx == NULL)
{
return PFalse;
}
if(img_convert_ctx == NULL)
{
PTRACE(1, "Conversion context not initialized");
return PFalse;
}
int scaled = sws_scale(img_convert_ctx, raw_ip_frame->data,
raw_ip_frame->linesize, 0, <---- THIS IS WHERE THE CRASH OCCURS
ip_codec_context->height, scaled_ip_frame->data,
scaled_ip_frame->linesize);
memcpy(destFrame, scaled_ip_frame->data, pckt.size);
}
else
{
memcpy(destFrame, pckt.data, pckt.size);
}
if (converter == NULL)
{
PTRACE(1, "converter is NULL");
if (bytesReturned != NULL)
*bytesReturned = ip_frame_size;
}
else
{
PBoolean y = converter->SetSrcFrameSize(ip_frame_width,
ip_frame_height);
if (!converter->Convert(readBuffer, destFrame,
bytesReturned))
{
PTRACE(1, "problem converting it seems");
return PFalse;
}
if (bytesReturned != NULL)
{
*bytesReturned = converter->GetMaxDstFrameBytes();
}
}
}
av_free(img_convert_ctx);
av_free_packet(&pckt);
//av_free(raw_ip_frame);
//av_free(scaled_ip_frame);
return PTrue;
}
v-user
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user