@@ -9,6 +9,16 @@ extern "C" {
9
9
#include < stdexcept>
10
10
#include < cstdlib>
11
11
12
+
13
+ template <class T >
14
+ bool from_string (T &t,
15
+ const std::string &s,
16
+ std::ios_base & (*f)(std::ios_base&))
17
+ {
18
+ std::istringstream iss (s);
19
+ return !(iss>>f>>t).fail ();
20
+ }
21
+
12
22
namespace avtranscoder
13
23
{
14
24
@@ -59,7 +69,7 @@ void VideoEncoder::setupEncoder(const ProfileLoader::Profile& profile)
59
69
(*it).first == constants::avProfileType || (*it).first == constants::avProfileCodec ||
60
70
(*it).first == constants::avProfileWidth || (*it).first == constants::avProfileHeight ||
61
71
(*it).first == constants::avProfilePixelFormat || (*it).first == constants::avProfileFrameRate ||
62
- (*it).first == constants::avProfileThreads)
72
+ (*it).first == constants::avProfileThreads || (*it). first == constants::avProfileBitRate )
63
73
continue ;
64
74
65
75
try
@@ -80,6 +90,17 @@ void VideoEncoder::setupEncoder(const ProfileLoader::Profile& profile)
80
90
encoderFlags |= CODEC_FLAG_PSNR;
81
91
}
82
92
_codec.getAVCodecContext ().flags |= encoderFlags;
93
+
94
+ if (profile.count (constants::avProfileBitRate)) {
95
+
96
+ int64_t bitRate = 0 ;
97
+ bool bconvert = from_string<int64_t >(bitRate, profile.at (constants::avProfileBitRate), std::dec);
98
+
99
+ if (bconvert) {
100
+ _codec.getAVCodecContext ().bit_rate = bitRate;
101
+ }
102
+ }
103
+
83
104
_codec.openCodec ();
84
105
85
106
// after open encoder, set specific encoder options
@@ -89,7 +110,7 @@ void VideoEncoder::setupEncoder(const ProfileLoader::Profile& profile)
89
110
(*it).first == constants::avProfileType || (*it).first == constants::avProfileCodec ||
90
111
(*it).first == constants::avProfileWidth || (*it).first == constants::avProfileHeight ||
91
112
(*it).first == constants::avProfilePixelFormat || (*it).first == constants::avProfileFrameRate ||
92
- (*it).first == constants::avProfileThreads)
113
+ (*it).first == constants::avProfileThreads || (*it). first == constants::avProfileBitRate )
93
114
continue ;
94
115
95
116
try
0 commit comments