Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume QAVFrame with QGraphicsVideoItem #482

Closed
kimvnhung opened this issue Jun 11, 2024 · 11 comments
Closed

Consume QAVFrame with QGraphicsVideoItem #482

kimvnhung opened this issue Jun 11, 2024 · 11 comments

Comments

@kimvnhung
Copy link
Contributor

kimvnhung commented Jun 11, 2024

I tried widget_video sample and run successfully. But while I try to use QGraphicsVideoItem to show video inside a QGraphicsView, the app crashed.

This is the debug mode last point before crashing
1 QAVVideoFrame::formatName qavvideoframe.cpp 140 0x7ff7b1429978
2 VideoBuffer_D3D11::handle qavhwdevice_d3d11.cpp 325 0x7ff7b14c9fc2
3 QAVVideoFrame::handle qavvideoframe.cpp 123 0x7ff7b142990e
4 PlanarVideoBuffer::mapTextures qavvideoframe.cpp 312 0x7ff7b142f527

This is how I use QGraphicsVideoItem to show video

GraphicsVideoItem *item = new GraphicsVideoItem();
QGraphicsScene *sence = new QGraphicsScene(this);
QGraphicsView *view = new QGraphicsView(sence);

sence->addItem(item);


setLayout(new QGridLayout(this));
layout()->addWidget(view);
player->addVideoOutput(item);
player->setSource("rtsp://admin:[email protected]:554/Streaming/Channels/101/", {
                                                                                                 {"rtsp_transport","tcp"},
                                                                                                 {"preset","ultrafast"},
                                                                                                 });
QPushButton *playBtn = new QPushButton("Play");
connect(playBtn, &QPushButton::clicked, [this]
        {
    player->play();
});
layout()->addWidget(playBtn);
@valbok
Copy link
Owner

valbok commented Jun 11, 2024

Thanks for the report.

Does it mean that frame() returns nullptr there?

Could you test
https://github.com/valbok/QtAVPlayer/blob/master/src/QtAVPlayer/qavhwdevice_d3d11.cpp#L324

if (!frame().frame())
    return {};

@kimvnhung
Copy link
Contributor Author

I tried your test but frame() is not nullptr,
The problem occurred on this line:
return QLatin1String(av_pix_fmt_desc_get(QAVVideoFrame::format())->name);
And I saw that QAVVideoFrame::format() return -1 at that.

I tried 2 simillar samples with QVideoWidget and QGraphicsVideoItem, It both contains a videoSink.
The sample with QVideoWidget worked fine, But the sample with QGraphicsVideoItem crashed on the line above after call to play()

@valbok
Copy link
Owner

valbok commented Jun 12, 2024

could you qDebug() << frame().frame()->format; ?

Is it -1?

@kimvnhung
Copy link
Contributor Author

kimvnhung commented Jun 12, 2024

Yes, It prints -1, but with the QVideoWidget, It prints 172.
I think It has some difference between QVideoSink in QVideoWidget and in QGraphicsVideoItem. But I'm not sure

Note: I used the same rtsp link with both case

@valbok
Copy link
Owner

valbok commented Jun 12, 2024

Forgot to ask, static_cast<bool>(frame()) should be false there?

Meant that the frame is invalid and should be skipped

@kimvnhung
Copy link
Contributor Author

Sorry, I dont know where is the "static_cast(frame())" you mentioned
I'm using Qt 6.6.2 which has a defined for handling

@valbok
Copy link
Owner

valbok commented Jun 12, 2024

meant to check like
if (!frame()) qDebug() <<"empty frame";

@kimvnhung
Copy link
Contributor Author

kimvnhung commented Jun 12, 2024

It's empty frame...

image

log
image

@valbok
Copy link
Owner

valbok commented Jun 12, 2024

so could you please just skip it?

if (!frame())
    return {};

And check if some correct video frames will be sent? Also could you provide std output? Maybe it could not find a codec...

@kimvnhung
Copy link
Contributor Author

Oh, ok, It works fine now with QGraphicsVideoItem.
Thanks for your support

@kimvnhung kimvnhung reopened this Jun 12, 2024
@kimvnhung
Copy link
Contributor Author

#483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants