fix #169, support default values for transcode. 2.0.180

pull/499/head
winlin 10 years ago
parent 89183c52c9
commit c85f92c229

@ -344,6 +344,7 @@ Remark:
### SRS 2.0 history
* v2.0, 2015-07-21, for [#169](https://github.com/simple-rtmp-server/srs/issues/169) support default values for transcode. 2.0.180
* v2.0, 2015-07-21, fix [#435](https://github.com/simple-rtmp-server/srs/issues/435) add pageUrl for HTTP callback on_play.
* v2.0, 2015-07-20, refine the hls, ignore packet when no sequence header. 2.0.179
* v2.0, 2015-07-16, for [#441](https://github.com/simple-rtmp-server/srs/issues/441) use 30s timeout for first msg. 2.0.178

@ -13,19 +13,12 @@ vhost __defaultVhost__ {
vfilter {
}
vcodec libx264;
vbitrate 500;
vfps 25;
vwidth 768;
vheight 320;
vthreads 12;
vthreads 4;
vprofile main;
vpreset medium;
vparams {
}
acodec libfdk_aac;
abitrate 70;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];

@ -918,14 +918,23 @@ vhost example.transcode.srs.com {
# vn: disable video output.
vcodec libx264;
# video bitrate, in kbps
# @remark 0 to use source video bitrate.
# default: 0
vbitrate 1500;
# video framerate.
# @remark 0 to use source video fps.
# default: 0
vfps 25;
# video width, must be even numbers.
# @remark 0 to use source video width.
# default: 0
vwidth 768;
# video height, must be even numbers.
# @remark 0 to use source video height.
# default: 0
vheight 320;
# the max threads for ffmpeg to used.
# default: 1
vthreads 12;
# x264 profile, @see x264 -help, can be:
# high,main,baseline
@ -950,17 +959,24 @@ vhost example.transcode.srs.com {
# an: disable audio output.
acodec libfdk_aac;
# audio bitrate, in kbps. [16, 72] for libfdk_aac.
# @remark 0 to use source audio bitrate.
# default: 0
abitrate 70;
# audio sample rate. for flv/rtmp, it must be:
# 44100,22050,11025,5512
# @remark 0 to use source audio sample rate.
# default: 0
asample_rate 44100;
# audio channel, 1 for mono, 2 for stereo.
# @remark 0 to use source audio channels.
# default: 0
achannels 2;
# other ffmpeg audio params
aparams {
# audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
# @remark SRS supported aac profile for HLS is: aac_low, aac_he, aac_he_v2
profile:a aac_low;
bsf:a aac_adtstoasc;
}
# output format, can be:
# off, do not specifies the format, ffmpeg will guess it.

@ -20,9 +20,6 @@ vhost __defaultVhost__ {
enabled on;
vcodec copy;
acodec libfdk_aac;
abitrate 45;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];

@ -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());

@ -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;

@ -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"

Loading…
Cancel
Save