示例#1
0
AVFrame * RtspStreamFrameFormatter::scaleFrame(AVFrame* avFrame)
{
    Q_ASSERT(avFrame->width != 0);
    Q_ASSERT(avFrame->height != 0);
    m_width = avFrame->width;
    m_height = avFrame->height;

    updateSWSContext();

    if (!m_sws_context)
        return NULL;

    int bufSize  = av_image_get_buffer_size(m_pixelFormat, m_width, m_height, 1);
    uint8_t *buf = (uint8_t*) av_malloc(bufSize);

    AVFrame *result = av_frame_alloc();

    av_image_fill_arrays(result->data, result->linesize, buf, m_pixelFormat, m_width, m_height, 1);
    sws_scale(m_sws_context, (const uint8_t**)avFrame->data, avFrame->linesize, 0, m_height,
              result->data, result->linesize);

    result->width = m_width;
    result->height = m_height;
    result->pts = avFrame->pts;

    return result;
}
AVFrame * LiveStreamFrameFormatter::scaleFrame(AVFrame* avFrame)
{
    updateSWSContext();

    int bufSize  = avpicture_get_size(m_pixelFormat, m_stream->codec->width, m_stream->codec->height);
    uint8_t *buf = (uint8_t*) av_malloc(bufSize);

    AVFrame *result = avcodec_alloc_frame();
    avpicture_fill((AVPicture*)result, buf, m_pixelFormat, m_stream->codec->width, m_stream->codec->height);
    sws_scale(m_sws_context, (const uint8_t**)avFrame->data, avFrame->linesize, 0, m_stream->codec->height,
              result->data, result->linesize);

    result->width = m_stream->codec->width;
    result->height = m_stream->codec->height;
    result->pts = avFrame->pkt_pts;

    return result;
}