mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
fix #119: use iformat and oformat for ffmpeg transcode.
This commit is contained in:
parent
2f0a72d7d1
commit
9bf7b722db
5 changed files with 61 additions and 5 deletions
|
@ -649,6 +649,12 @@ vhost all.transcode.srs.com {
|
|||
# whether the engine is enabled
|
||||
# default: off.
|
||||
enabled on;
|
||||
# input format, can be:
|
||||
# off, do not specifies the format, ffmpeg will guess it.
|
||||
# flv, for flv or RTMP stream.
|
||||
# other format, for example, mp4/aac whatever.
|
||||
# default: flv
|
||||
iformat flv;
|
||||
# ffmpeg filters, follows the main input.
|
||||
vfilter {
|
||||
# the logo input file.
|
||||
|
@ -706,6 +712,12 @@ vhost all.transcode.srs.com {
|
|||
# audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
|
||||
profile:a aac_low;
|
||||
}
|
||||
# output format, can be:
|
||||
# off, do not specifies the format, ffmpeg will guess it.
|
||||
# flv, for flv or RTMP stream.
|
||||
# other format, for example, mp4/aac whatever.
|
||||
# default: flv
|
||||
oformat flv;
|
||||
# output stream. variables:
|
||||
# [vhost] the input stream vhost.
|
||||
# [port] the intput stream port.
|
||||
|
|
|
@ -1965,6 +1965,20 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine)
|
|||
return true;
|
||||
}
|
||||
|
||||
string SrsConfig::get_engine_iformat(SrsConfDirective* engine)
|
||||
{
|
||||
if (!engine) {
|
||||
return "flv";
|
||||
}
|
||||
|
||||
SrsConfDirective* conf = engine->get("iformat");
|
||||
if (!conf) {
|
||||
return "flv";
|
||||
}
|
||||
|
||||
return conf->arg0();
|
||||
}
|
||||
|
||||
vector<string> SrsConfig::get_engine_vfilter(SrsConfDirective* engine)
|
||||
{
|
||||
vector<string> vfilter;
|
||||
|
@ -2211,6 +2225,20 @@ vector<string> SrsConfig::get_engine_aparams(SrsConfDirective* engine)
|
|||
return aparams;
|
||||
}
|
||||
|
||||
string SrsConfig::get_engine_oformat(SrsConfDirective* engine)
|
||||
{
|
||||
if (!engine) {
|
||||
return "flv";
|
||||
}
|
||||
|
||||
SrsConfDirective* conf = engine->get("oformat");
|
||||
if (!conf) {
|
||||
return "flv";
|
||||
}
|
||||
|
||||
return conf->arg0();
|
||||
}
|
||||
|
||||
string SrsConfig::get_engine_output(SrsConfDirective* engine)
|
||||
{
|
||||
if (!engine) {
|
||||
|
|
|
@ -605,6 +605,10 @@ public:
|
|||
*/
|
||||
virtual bool get_engine_enabled(SrsConfDirective* engine);
|
||||
/**
|
||||
* get the iformat of engine
|
||||
*/
|
||||
virtual std::string get_engine_iformat(SrsConfDirective* engine);
|
||||
/**
|
||||
* get the vfilter of engine,
|
||||
* the video filter set before the vcodec of FFMPEG.
|
||||
*/
|
||||
|
@ -679,6 +683,10 @@ public:
|
|||
*/
|
||||
virtual std::vector<std::string> get_engine_aparams(SrsConfDirective* engine);
|
||||
/**
|
||||
* get the oformat of engine
|
||||
*/
|
||||
virtual std::string get_engine_oformat(SrsConfDirective* engine);
|
||||
/**
|
||||
* get the output of engine, for example, rtmp://127.0.0.1/live/livestream,
|
||||
* @remark, we will use some variable, for instance, [vhost] to substitude with vhost.
|
||||
*/
|
||||
|
|
|
@ -96,6 +96,7 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
iformat = _srs_config->get_engine_iformat(engine);
|
||||
vfilter = _srs_config->get_engine_vfilter(engine);
|
||||
vcodec = _srs_config->get_engine_vcodec(engine);
|
||||
vbitrate = _srs_config->get_engine_vbitrate(engine);
|
||||
|
@ -111,6 +112,7 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
|
|||
asample_rate = _srs_config->get_engine_asample_rate(engine);
|
||||
achannels = _srs_config->get_engine_achannels(engine);
|
||||
aparams = _srs_config->get_engine_aparams(engine);
|
||||
oformat = _srs_config->get_engine_oformat(engine);
|
||||
|
||||
// ensure the size is even.
|
||||
vwidth -= vwidth % 2;
|
||||
|
@ -241,8 +243,10 @@ int SrsFFMPEG::start()
|
|||
}
|
||||
|
||||
// input.
|
||||
if (iformat != "off") {
|
||||
params.push_back("-f");
|
||||
params.push_back("flv");
|
||||
params.push_back(iformat);
|
||||
}
|
||||
|
||||
params.push_back("-i");
|
||||
params.push_back(input);
|
||||
|
@ -342,8 +346,10 @@ int SrsFFMPEG::start()
|
|||
}
|
||||
|
||||
// output
|
||||
if (oformat != "off") {
|
||||
params.push_back("-f");
|
||||
params.push_back("flv");
|
||||
params.push_back(oformat);
|
||||
}
|
||||
|
||||
params.push_back("-y");
|
||||
params.push_back(_output);
|
||||
|
|
|
@ -51,6 +51,8 @@ private:
|
|||
private:
|
||||
std::string ffmpeg;
|
||||
std::string _iparams;
|
||||
std::string iformat;
|
||||
std::string input;
|
||||
std::vector<std::string> vfilter;
|
||||
std::string vcodec;
|
||||
int vbitrate;
|
||||
|
@ -66,8 +68,8 @@ private:
|
|||
int asample_rate;
|
||||
int achannels;
|
||||
std::vector<std::string> aparams;
|
||||
std::string oformat;
|
||||
std::string _output;
|
||||
std::string input;
|
||||
public:
|
||||
SrsFFMPEG(std::string ffmpeg_bin);
|
||||
virtual ~SrsFFMPEG();
|
||||
|
|
Loading…
Reference in a new issue