forked from mikrosimage/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoFrame.cpp
More file actions
70 lines (57 loc) · 1.86 KB
/
Copy pathVideoFrame.cpp
File metadata and controls
70 lines (57 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "VideoFrame.hpp"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/pixdesc.h>
}
#include <stdexcept>
#include <stdlib.h>
namespace avtranscoder
{
VideoFrameDesc::VideoFrameDesc( const size_t width, const size_t height, const AVPixelFormat pixelFormat )
: _width( width )
, _height( height )
, _pixelFormat( pixelFormat )
, _fps( 1.0 )
{
}
VideoFrameDesc::VideoFrameDesc( const size_t width, const size_t height, const std::string& pixelFormat )
: _width( width )
, _height( height )
, _pixelFormat( av_get_pix_fmt( pixelFormat.c_str() ) )
, _fps( 1.0 )
{
}
std::string VideoFrameDesc::getPixelFormatName() const
{
const char* formatName = av_get_pix_fmt_name( _pixelFormat );
return formatName ? std::string( formatName ) : "unknown pixel format";
}
size_t VideoFrameDesc::getDataSize() const
{
if( _pixelFormat == AV_PIX_FMT_NONE )
throw std::runtime_error( "incorrect pixel format" );
size_t size = avpicture_get_size( _pixelFormat, _width, _height );
if( size == 0 )
throw std::runtime_error( "unable to determine image buffer size" );
return size;
}
void VideoFrameDesc::setPixelFormat( const std::string& pixelFormat )
{
_pixelFormat = av_get_pix_fmt( pixelFormat.c_str() );
}
void VideoFrameDesc::setParameters( const ProfileLoader::Profile& profile )
{
// width
if( profile.count( constants::avProfileWidth ) )
setWidth( atoi( profile.find( constants::avProfileWidth )->second.c_str() ) );
// height
if( profile.count( constants::avProfileHeight ) )
setHeight( atoi( profile.find( constants::avProfileHeight )->second.c_str() ) );
// pixel format
if( profile.count( constants::avProfilePixelFormat ) )
setPixelFormat( profile.find( constants::avProfilePixelFormat )->second );
// fps
if( profile.count( constants::avProfileFrameRate ) )
setFps( atof( profile.find( constants::avProfileFrameRate )->second.c_str() ) );
}
}