Skip to content

Commit ce46e1a

Browse files
get ImageDesc from VideoDesc
1 parent 3451a7c commit ce46e1a

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/AvTranscoder/DatasStructures/Pixel.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,44 @@ extern "C" {
1414
namespace avtranscoder
1515
{
1616

17+
Pixel::Pixel( const AVPixelFormat avpixelFormat )
18+
: m_pixelSize ( 24 )
19+
, m_components ( 3 )
20+
, m_componentType ( eComponentYuv )
21+
, m_subsamplingType ( eSubsamplingNone )
22+
, m_endianess ( false )
23+
, m_withAlpha ( false )
24+
, m_planar ( true )
25+
{
26+
const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get( avpixelFormat );
27+
setBitsPerPixel ( av_get_bits_per_pixel( pix_desc ) );
28+
setBigEndian ( pix_desc->flags & PIX_FMT_BE );
29+
setComponents ( pix_desc->nb_components );
30+
setAlpha ( pix_desc->flags & PIX_FMT_ALPHA );
31+
setPlanar ( ( pix_desc->flags & PIX_FMT_PLANAR ) != 0 );
32+
33+
if( pix_desc->nb_components == 1 )
34+
setColorComponents( eComponentGray );
35+
36+
if( pix_desc->flags & PIX_FMT_RGB )
37+
setColorComponents( eComponentRgb );
38+
else
39+
setColorComponents( eComponentYuv );
40+
41+
setSubsampling( eSubsamplingNone );
42+
43+
if( ( pix_desc->log2_chroma_w == true ) &&
44+
( pix_desc->log2_chroma_h == false ) )
45+
{
46+
setSubsampling( eSubsampling422 );
47+
}
48+
if( ( pix_desc->log2_chroma_w == true ) &&
49+
( pix_desc->log2_chroma_h == true ) )
50+
{
51+
setSubsampling( eSubsampling420 );
52+
}
53+
}
54+
1755
AVPixelFormat Pixel::findPixel() const
1856
{
1957
//av_register_all();

src/AvTranscoder/DatasStructures/Pixel.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class Pixel
4444
, m_planar ( true )
4545
{ }
4646

47+
Pixel( const AVPixelFormat avpixelFormat );
48+
4749
void setBitsPerPixel ( const size_t pixelSize ) { m_pixelSize = pixelSize; }
4850
void setBigEndian ( const bool endianess ) { m_endianess = endianess; }
4951
void setComponents ( const size_t components ) { m_components = components; }

src/AvTranscoder/DatasStructures/VideoDesc.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,16 @@ void VideoDesc::set( const std::string& key, const std::string& value )
218218
}
219219
}
220220

221+
ImageDesc VideoDesc::getImageDesc() const
222+
{
223+
ImageDesc imageDesc;
224+
Pixel pixel( m_codecContext->pix_fmt );
225+
226+
imageDesc.setWidth ( m_codecContext->width );
227+
imageDesc.setHeight( m_codecContext->height );
228+
imageDesc.setPixel ( pixel );
229+
imageDesc.setDar ( m_codecContext->height, m_codecContext->width );
230+
return imageDesc;
231+
}
232+
221233
}

src/AvTranscoder/DatasStructures/VideoDesc.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extern "C" {
1616
#include <libavcodec/avcodec.h>
1717
}
1818

19+
#include <AvTranscoder/DatasStructures/Image.hpp>
20+
1921
namespace avtranscoder
2022
{
2123

@@ -50,6 +52,8 @@ class AvExport VideoDesc
5052
AVCodecContext* getCodecContext() const { return m_codecContext; }
5153
#endif
5254

55+
ImageDesc getImageDesc() const;
56+
5357
private:
5458
void initCodecContext( );
5559

0 commit comments

Comments
 (0)