1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix #169, support default values for transcode. 2.0.180

This commit is contained in:
winlin 2015-07-21 12:07:26 +08:00
parent 89183c52c9
commit c85f92c229
7 changed files with 107 additions and 68 deletions

View file

@ -2976,13 +2976,15 @@ string SrsConfig::get_engine_vcodec(SrsConfDirective* engine)
int SrsConfig::get_engine_vbitrate(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vbitrate");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
@ -2990,13 +2992,15 @@ int SrsConfig::get_engine_vbitrate(SrsConfDirective* engine)
double SrsConfig::get_engine_vfps(SrsConfDirective* engine)
{
static double DEFAULT = 0;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vfps");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atof(conf->arg0().c_str());
@ -3004,13 +3008,15 @@ double SrsConfig::get_engine_vfps(SrsConfDirective* engine)
int SrsConfig::get_engine_vwidth(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vwidth");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
@ -3018,13 +3024,15 @@ int SrsConfig::get_engine_vwidth(SrsConfDirective* engine)
int SrsConfig::get_engine_vheight(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vheight");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
@ -3032,13 +3040,15 @@ int SrsConfig::get_engine_vheight(SrsConfDirective* engine)
int SrsConfig::get_engine_vthreads(SrsConfDirective* engine)
{
static int DEFAULT = 1;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vthreads");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
@ -3116,13 +3126,15 @@ string SrsConfig::get_engine_acodec(SrsConfDirective* engine)
int SrsConfig::get_engine_abitrate(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("abitrate");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
@ -3130,13 +3142,15 @@ int SrsConfig::get_engine_abitrate(SrsConfDirective* engine)
int SrsConfig::get_engine_asample_rate(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("asample_rate");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
@ -3144,13 +3158,15 @@ int SrsConfig::get_engine_asample_rate(SrsConfDirective* engine)
int SrsConfig::get_engine_achannels(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return 0;
return DEFAULT;
}
SrsConfDirective* conf = engine->get("achannels");
if (!conf) {
return 0;
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());

View file

@ -137,22 +137,22 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
SRS_RTMP_ENCODER_VCODEC, vcodec.c_str(), ret);
return ret;
}
if (vbitrate <= 0) {
if (vbitrate < 0) {
ret = ERROR_ENCODER_VBITRATE;
srs_error("invalid vbitrate: %d, ret=%d", vbitrate, ret);
return ret;
}
if (vfps <= 0) {
if (vfps < 0) {
ret = ERROR_ENCODER_VFPS;
srs_error("invalid vfps: %.2f, ret=%d", vfps, ret);
return ret;
}
if (vwidth <= 0) {
if (vwidth < 0) {
ret = ERROR_ENCODER_VWIDTH;
srs_error("invalid vwidth: %d, ret=%d", vwidth, ret);
return ret;
}
if (vheight <= 0) {
if (vheight < 0) {
ret = ERROR_ENCODER_VHEIGHT;
srs_error("invalid vheight: %d, ret=%d", vheight, ret);
return ret;
@ -176,7 +176,7 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
// @see, https://github.com/simple-rtmp-server/srs/issues/145
if (acodec == SRS_RTMP_ENCODER_LIBAACPLUS && acodec != SRS_RTMP_ENCODER_LIBFDKAAC) {
if (abitrate < 16 || abitrate > 72) {
if (abitrate != 0 && (abitrate < 16 || abitrate > 72)) {
ret = ERROR_ENCODER_ABITRATE;
srs_error("invalid abitrate for aac: %d, must in [16, 72], ret=%d", abitrate, ret);
return ret;
@ -184,17 +184,17 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
}
if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) {
if (abitrate <= 0) {
if (abitrate < 0) {
ret = ERROR_ENCODER_ABITRATE;
srs_error("invalid abitrate: %d, ret=%d", abitrate, ret);
return ret;
}
if (asample_rate <= 0) {
if (asample_rate < 0) {
ret = ERROR_ENCODER_ASAMPLE_RATE;
srs_error("invalid sample rate: %d, ret=%d", asample_rate, ret);
return ret;
}
if (achannels != 1 && achannels != 2) {
if (achannels != 0 && achannels != 1 && achannels != 2) {
ret = ERROR_ENCODER_ACHANNELS;
srs_error("invalid achannels, must be 1 or 2, actual %d, ret=%d", achannels, ret);
return ret;
@ -285,26 +285,36 @@ int SrsFFMPEG::start()
// the codec params is disabled when copy
if (vcodec != SRS_RTMP_ENCODER_COPY && vcodec != SRS_RTMP_ENCODER_NO_VIDEO) {
params.push_back("-b:v");
snprintf(tmp, sizeof(tmp), "%d", vbitrate * 1000);
params.push_back(tmp);
if (vbitrate > 0) {
params.push_back("-b:v");
snprintf(tmp, sizeof(tmp), "%d", vbitrate * 1000);
params.push_back(tmp);
}
params.push_back("-r");
snprintf(tmp, sizeof(tmp), "%.2f", vfps);
params.push_back(tmp);
if (vfps > 0) {
params.push_back("-r");
snprintf(tmp, sizeof(tmp), "%.2f", vfps);
params.push_back(tmp);
}
params.push_back("-s");
snprintf(tmp, sizeof(tmp), "%dx%d", vwidth, vheight);
params.push_back(tmp);
if (vwidth > 0 && vheight > 0) {
params.push_back("-s");
snprintf(tmp, sizeof(tmp), "%dx%d", vwidth, vheight);
params.push_back(tmp);
}
// TODO: add aspect if needed.
params.push_back("-aspect");
snprintf(tmp, sizeof(tmp), "%d:%d", vwidth, vheight);
params.push_back(tmp);
if (vwidth > 0 && vheight > 0) {
params.push_back("-aspect");
snprintf(tmp, sizeof(tmp), "%d:%d", vwidth, vheight);
params.push_back(tmp);
}
params.push_back("-threads");
snprintf(tmp, sizeof(tmp), "%d", vthreads);
params.push_back(tmp);
if (vthreads > 0) {
params.push_back("-threads");
snprintf(tmp, sizeof(tmp), "%d", vthreads);
params.push_back(tmp);
}
params.push_back("-profile:v");
params.push_back(vprofile);
@ -335,17 +345,23 @@ int SrsFFMPEG::start()
// the codec params is disabled when copy
if (acodec != SRS_RTMP_ENCODER_NO_AUDIO) {
if (acodec != SRS_RTMP_ENCODER_COPY) {
params.push_back("-b:a");
snprintf(tmp, sizeof(tmp), "%d", abitrate * 1000);
params.push_back(tmp);
if (abitrate > 0) {
params.push_back("-b:a");
snprintf(tmp, sizeof(tmp), "%d", abitrate * 1000);
params.push_back(tmp);
}
params.push_back("-ar");
snprintf(tmp, sizeof(tmp), "%d", asample_rate);
params.push_back(tmp);
if (asample_rate > 0) {
params.push_back("-ar");
snprintf(tmp, sizeof(tmp), "%d", asample_rate);
params.push_back(tmp);
}
params.push_back("-ac");
snprintf(tmp, sizeof(tmp), "%d", achannels);
params.push_back(tmp);
if (achannels > 0) {
params.push_back("-ac");
snprintf(tmp, sizeof(tmp), "%d", achannels);
params.push_back(tmp);
}
// aparams
std::vector<std::string>::iterator it;

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 179
#define VERSION_REVISION 180
// server info.
#define RTMP_SIG_SRS_KEY "SRS"