【发布时间】:2014-01-22 00:26:50
【问题描述】:
我正在使用 FFMpeg 解码实时视频并使用 Live555 进行流式传输。我能够解码视频并获取输出 AVPackets。
1.使用FFMpeg的SWScale将BGR Image转为YUV422P格式
// 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);
用于解码每一帧
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);
}
到这里它工作正常。我能够将这些帧写入文件并使用 VLC 播放。在此之后,我必须将输出帧传递给 Live555。我认为我到达这里的 AVPackets 不需要是 Live555 所需的单个 H264 Nal 单元。
如何将 AVPacket 分解为 Nal 单元,然后传递给 Live555?
【问题讨论】: