0
votes

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

1
show your code and the exception that you get, so we can help you... - ahmed_khan_89
You likely have more issues than just this, but avcodec_decode_video2 is not necessarily one frame in one frame out. You may need to feed it several frames before you get one back (of flush by sending empty packets). Also, and here is the big one, what is avcodec_decode_video2 retuning? Next time, please check the error codes before asking a question. - szatmary

1 Answers

0
votes

to get one back I had to put few(10-15) packets to avcodec_decode ( so on begining frameFinished ==0) and after this I get proper frame.

The solution was setting Spacket.size = CDatagrams.size after memcpy

So after initialization minimum work that we have to do is

  1. av_init_packet
  2. fill the packet.data with data out of the socket
  3. set packet.size

And the avcodec_decode will return proper Frame

Im sorry that I asked incomplete questions(no errorcodes). Thanks