Skip to content

Commit 6bf8c76

Browse files
committed
Frame: fix isValid() to work with any HW-encoded frames
Sounds like FFmpeg uses data[3] as a reference to the internal HW frame ID at the same time, when data[0] still is NULL. At same time hw_frames_ctx is not a NULL. Also, add isHwFrame(). Fix #175
1 parent f90e1b1 commit 6bf8c76

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/avcpp/frame.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,16 @@ bool FrameCommon::isComplete() const { return m_isComplete; }
646646
bool FrameCommon::isValid() const {
647647
return (!isNull() &&
648648
((m_raw->data[0] && m_raw->linesize[0]) ||
649-
((m_raw->format == AV_PIX_FMT_VAAPI) && ((intptr_t)m_raw->data[3] > 0)))
650-
);
649+
((m_raw->hw_frames_ctx) && ((intptr_t)m_raw->data[3] > 0))));
651650
}
652651

653652
FrameCommon::operator bool() const { return isValid() && isComplete(); }
654653

654+
bool FrameCommon::isHwFrame() const
655+
{
656+
return !isNull() && !!m_raw->hw_frames_ctx;
657+
}
658+
655659
uint8_t *FrameCommon::data(size_t plane) {
656660
if (!m_raw || plane >= size_t(AV_NUM_DATA_POINTERS + m_raw->nb_extended_buf))
657661
return nullptr;

src/avcpp/frame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class FrameCommon : public FFWrapperPtr<AVFrame>
110110

111111
operator bool() const;
112112

113+
bool isHwFrame() const;
114+
113115
uint8_t *data(size_t plane = 0);
114116
const uint8_t *data(size_t plane = 0) const;
115117

0 commit comments

Comments
 (0)