Giter Site home page Giter Site logo

Comments (3)

FH0 avatar FH0 commented on August 15, 2024

the second linesize should be 960.

04-08 03:43:42.924 I videoFrame.planeCount: 2, format: nv12
04-08 03:43:42.924 I i: 0 linesize: 1920 height: 1080
04-08 03:43:42.926 I i: 1 linesize: 1920 height: 1080

If I copy with hard code, it will be OK.

void onFrame(AVFrame *frame) {
    if (videoSink == nullptr) {
        return;
    }

    auto        fmt = getFormat((AVPixelFormat)frame->format);
    QVideoFrame videoFrame({QSize(frame->width, frame->height), fmt});
    videoFrame.map(QVideoFrame::WriteOnly);
    memcpy(videoFrame.bits(0), frame->data[0], 1920 * 1080);
    memcpy(videoFrame.bits(1), frame->data[1], 1920 * 1080 / 2);
    videoFrame.unmap(); // TODO use drm prime

    emit videoSink->videoFrameChanged(videoFrame);
}

from ffmpeg-rockchip.

FH0 avatar FH0 commented on August 15, 2024

Finally solved by

void onFrame(AVFrame *frame) {
    if (videoSink == nullptr) {
        return;
    }

    auto        fmt = getFormat((AVPixelFormat)frame->format);
    QVideoFrame videoFrame({QSize(frame->width, frame->height), fmt});
    videoFrame.map(QVideoFrame::WriteOnly);
    for (int i = 0; i < videoFrame.planeCount(); i++) {
        memcpy(videoFrame.bits(i), frame->data[i], videoFrame.mappedBytes(i));
    }
    videoFrame.unmap(); // TODO use drm prime

    emit videoSink->videoFrameChanged(videoFrame);
}

But I still don't know how to get buffer from avframe by ffmpeg way.

from ffmpeg-rockchip.

nyanmisaka avatar nyanmisaka commented on August 15, 2024

@FH0

the second linesize should be 960.

It is a semi-planar format, U and V are interleaved, so the 2nd linesize should be 1920.

1.5: bytes_per_pixel of NV12
Y buf: 1920xAlign(1080)x1.5=3133440 (+128=3133568) //<= calc by MPP runtime
UV buf: 1920xAlign(540)x1.5=1566720

See this func for more info

static AVBufferRef *rkmpp_drm_pool_alloc(void *opaque, size_t size)

from ffmpeg-rockchip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.