2
votes

I am using FFMpeg To decode live video and stream it using Live555.i am able to decode video and getting the output AVPackets.
1. Convert the BGR Image to YUV422P format using FFMpeg's SWScale

// initilize a BGR To RGB converter using FFMpeg
ctx = sws_getContext(codecContext->width, codecContext->height, AV_PIX_FMT_BGR24, codecContext->width, codecContext->height, AV_PIX_FMT_YUV422P, SWS_BICUBIC, 0, 0, 0);
tempFrame = av_frame_alloc();
int num_bytes = avpicture_get_size(PIX_FMT_BGR24, codecContext->width, codecContext->height);
uint8_t* frame2_buffer = (uint8_t*)av_malloc(num_bytes*sizeof(uint8_t));
avpicture_fill((AVPicture*)tempFrame, frame2_buffer, PIX_FMT_BGR24, codecContext->width, codecContext->height);

// inside the loop of where frames are being encoded where rawFrame is a BGR image
tempFrame->data[0] = reinterpret_cast<uint8_t*>(rawFrame->_data);
sws_scale(ctx, tempFrame->data, tempFrame->linesize, 0, frame->height, frame->data, frame->linesize);

For decoding each Frame

ret = avcodec_encode_video2(codecContext, &packet, frame, &got_output);
if(ret < 0)
{
    fprintf(stderr, "Error in encoding frame\n");
    exit(1);
}

if(got_output)
{
    //printf("Received frame! pushing to queue\n");
    OutputFrame *outFrame = new OutputFrame();
    outFrame->_data = packet.buf->data;
    outFrame->_bufferSize = packet.buf->size;
    outputQueue.push_back(outFrame);
}

Till here it works fine. i am able to write these frames to file and play it using VLC. after this i have to pass the output frame to Live555.i think AVPackets i am getting here doesn't need to be a single H264 Nal unit which is required by Live555.

How to break a AVPacket into Nal units which can be passed to Live555?

1

1 Answers

1
votes

H264VideoStreamDiscreateFramer expect data without the start code '\x00\x00\x00\x01'. It is needed to remove the 4 first bytes either in your LiveDeviceSource or inserting a FramedFilter to do this job.

Perhaps you can tried to use an H264VideoStreamFramer, like the testH264VideoStreamer test program.

If it could help, you can find one of my tries with live555 implementing an RTSP server feed from V4L2 capture https://github.com/mpromonet/h264_v4l2_rtspserver