|
5 | 5 | #include <AvTranscoder/ProfileLoader.hpp>
|
6 | 6 |
|
7 | 7 | extern "C" {
|
8 |
| -#include <libavcodec/avcodec.h> |
9 | 8 | #include <libavutil/pixfmt.h>
|
10 |
| -#include <libavutil/pixdesc.h> |
11 | 9 | }
|
12 | 10 |
|
13 |
| -#include <stdexcept> |
14 |
| -#include <stdlib.h> |
15 |
| - |
16 | 11 | namespace avtranscoder
|
17 | 12 | {
|
18 | 13 |
|
19 | 14 | class AvExport VideoFrameDesc
|
20 | 15 | {
|
21 | 16 | public:
|
22 |
| - VideoFrameDesc( const size_t width = 0, const size_t height = 0, const AVPixelFormat pixelFormat = AV_PIX_FMT_NONE ) |
23 |
| - : _width( width ) |
24 |
| - , _height( height ) |
25 |
| - , _pixelFormat( pixelFormat ) |
26 |
| - , _fps( 1.0 ) |
27 |
| - { |
28 |
| - } |
29 |
| - VideoFrameDesc( const size_t width, const size_t height, const std::string& pixelFormat ) |
30 |
| - : _width( width ) |
31 |
| - , _height( height ) |
32 |
| - , _pixelFormat( av_get_pix_fmt( pixelFormat.c_str() ) ) |
33 |
| - , _fps( 1.0 ) |
34 |
| - { |
35 |
| - } |
| 17 | + VideoFrameDesc( const size_t width = 0, const size_t height = 0, const AVPixelFormat pixelFormat = AV_PIX_FMT_NONE ); |
| 18 | + VideoFrameDesc( const size_t width, const size_t height, const std::string& pixelFormat ); |
36 | 19 |
|
37 | 20 | size_t getWidth () const { return _width; }
|
38 | 21 | size_t getHeight() const { return _height; }
|
39 | 22 | AVPixelFormat getPixelFormat() const { return _pixelFormat; }
|
40 |
| - std::string getPixelFormatName() const |
41 |
| - { |
42 |
| - const char* formatName = av_get_pix_fmt_name( _pixelFormat ); |
43 |
| - return formatName ? std::string( formatName ) : "unknown pixel format"; |
44 |
| - } |
| 23 | + std::string getPixelFormatName() const; |
45 | 24 | double getFps() const { return _fps; }
|
46 | 25 |
|
47 |
| - size_t getDataSize() const |
48 |
| - { |
49 |
| - if( _pixelFormat == AV_PIX_FMT_NONE ) |
50 |
| - throw std::runtime_error( "incorrect pixel format" ); |
51 |
| - |
52 |
| - size_t size = avpicture_get_size( _pixelFormat, _width, _height ); |
53 |
| - if( size == 0 ) |
54 |
| - throw std::runtime_error( "unable to determine image buffer size" ); |
55 |
| - |
56 |
| - return size; |
57 |
| - } |
| 26 | + size_t getDataSize() const; |
58 | 27 |
|
59 | 28 | void setWidth ( const size_t width ) { _width = width; }
|
60 | 29 | void setHeight( const size_t height ) { _height = height; }
|
61 |
| - void setPixelFormat( const std::string& pixelFormat ) { _pixelFormat = av_get_pix_fmt( pixelFormat.c_str() ); } |
| 30 | + void setPixelFormat( const std::string& pixelFormat ); |
62 | 31 | void setPixelFormat( const AVPixelFormat pixelFormat ) { _pixelFormat = pixelFormat; }
|
63 | 32 | void setFps( const double fps ) { _fps = fps; }
|
64 | 33 |
|
65 |
| - void setParameters( const ProfileLoader::Profile& profile ) |
66 |
| - { |
67 |
| - // width |
68 |
| - if( profile.count( constants::avProfileWidth ) ) |
69 |
| - setWidth( atoi( profile.find( constants::avProfileWidth )->second.c_str() ) ); |
70 |
| - // height |
71 |
| - if( profile.count( constants::avProfileHeight ) ) |
72 |
| - setHeight( atoi( profile.find( constants::avProfileHeight )->second.c_str() ) ); |
73 |
| - // pixel format |
74 |
| - if( profile.count( constants::avProfilePixelFormat ) ) |
75 |
| - setPixelFormat( profile.find( constants::avProfilePixelFormat )->second ); |
76 |
| - // fps |
77 |
| - if( profile.count( constants::avProfileFrameRate ) ) |
78 |
| - setFps( atof( profile.find( constants::avProfileFrameRate )->second.c_str() ) ); |
79 |
| - } |
| 34 | + void setParameters( const ProfileLoader::Profile& profile ); |
80 | 35 |
|
81 | 36 | private:
|
82 | 37 | size_t _width;
|
|
0 commit comments