I want to write a application that had to receive udp packets by QT UdpSocket, packets consists metadata and video.
Video data is the same as from ffmpeg udp stream.
I divided this packets and selected video data, now I want to put this video data into AVpacket, decode it and display in window.
So I have Qbytearray from udp socket and don't know how to convert it to AVpacket.
(when I write this Qbytearray to file I have proper video file so data is good)
procFrame is called every time I get a UDP packet. In constructor I have codec initialization and other init stuff. Cdatagrams contains one frame of video ( key frame or differential frame). Codec is mpeg2
void myThread::procFrame()
{
findex++;
if(av_read_frame(pFormatCtx,&packet)<0)///now pFormatCtx pointing to file on disk
qDebug()<<"avreadframe failed";
Spacket.data = new uint8_t[Cdatagrams.size()];///Spacket is empty packet that I want to fill by Qbytearray Cdatagrams
memcpy(Spacket.data,Cdatagrams.data_ptr(),Cdatagrams.size());////here is the problem
int framecount;
int frameFinished;
avcodec_decode_video2(pCodecCtx,pFrame,&frameFinished,&Spacket);
qDebug()<< "framefinished " <<frameFinished;
if (frameFinished)
{
img_convert(pFrameRGB,pFrame,pCodecCtx);
int y;
QImage img = QImage(width, height, QImage::Format_RGB888);
// Write pixel data
for(y=0; y<height; y++)
memcpy(img.scanLine(y), pFramew->data[0]+y*pFramew->linesize[0], width*3);
emit frameReady(img);
}
}
In this version I have frameFinished==0 so Spacket isn't properly prepared