mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +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
|
# whether the engine is enabled
|
||||||
# default: off.
|
# default: off.
|
||||||
enabled on;
|
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.
|
# ffmpeg filters, follows the main input.
|
||||||
vfilter {
|
vfilter {
|
||||||
# the logo input file.
|
# the logo input file.
|
||||||
|
@ -706,6 +712,12 @@ vhost all.transcode.srs.com {
|
||||||
# audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
|
# audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
|
||||||
profile:a aac_low;
|
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:
|
# output stream. variables:
|
||||||
# [vhost] the input stream vhost.
|
# [vhost] the input stream vhost.
|
||||||
# [port] the intput stream port.
|
# [port] the intput stream port.
|
||||||
|
|
|
@ -1965,6 +1965,20 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine)
|
||||||
return true;
|
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> SrsConfig::get_engine_vfilter(SrsConfDirective* engine)
|
||||||
{
|
{
|
||||||
vector<string> vfilter;
|
vector<string> vfilter;
|
||||||
|
@ -2211,6 +2225,20 @@ vector<string> SrsConfig::get_engine_aparams(SrsConfDirective* engine)
|
||||||
return aparams;
|
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)
|
string SrsConfig::get_engine_output(SrsConfDirective* engine)
|
||||||
{
|
{
|
||||||
if (!engine) {
|
if (!engine) {
|
||||||
|
|
|
@ -605,6 +605,10 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool get_engine_enabled(SrsConfDirective* engine);
|
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,
|
* get the vfilter of engine,
|
||||||
* the video filter set before the vcodec of FFMPEG.
|
* the video filter set before the vcodec of FFMPEG.
|
||||||
*/
|
*/
|
||||||
|
@ -679,6 +683,10 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual std::vector<std::string> get_engine_aparams(SrsConfDirective* engine);
|
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,
|
* 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.
|
* @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;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
iformat = _srs_config->get_engine_iformat(engine);
|
||||||
vfilter = _srs_config->get_engine_vfilter(engine);
|
vfilter = _srs_config->get_engine_vfilter(engine);
|
||||||
vcodec = _srs_config->get_engine_vcodec(engine);
|
vcodec = _srs_config->get_engine_vcodec(engine);
|
||||||
vbitrate = _srs_config->get_engine_vbitrate(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);
|
asample_rate = _srs_config->get_engine_asample_rate(engine);
|
||||||
achannels = _srs_config->get_engine_achannels(engine);
|
achannels = _srs_config->get_engine_achannels(engine);
|
||||||
aparams = _srs_config->get_engine_aparams(engine);
|
aparams = _srs_config->get_engine_aparams(engine);
|
||||||
|
oformat = _srs_config->get_engine_oformat(engine);
|
||||||
|
|
||||||
// ensure the size is even.
|
// ensure the size is even.
|
||||||
vwidth -= vwidth % 2;
|
vwidth -= vwidth % 2;
|
||||||
|
@ -241,8 +243,10 @@ int SrsFFMPEG::start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// input.
|
// input.
|
||||||
params.push_back("-f");
|
if (iformat != "off") {
|
||||||
params.push_back("flv");
|
params.push_back("-f");
|
||||||
|
params.push_back(iformat);
|
||||||
|
}
|
||||||
|
|
||||||
params.push_back("-i");
|
params.push_back("-i");
|
||||||
params.push_back(input);
|
params.push_back(input);
|
||||||
|
@ -342,8 +346,10 @@ int SrsFFMPEG::start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// output
|
// output
|
||||||
params.push_back("-f");
|
if (oformat != "off") {
|
||||||
params.push_back("flv");
|
params.push_back("-f");
|
||||||
|
params.push_back(oformat);
|
||||||
|
}
|
||||||
|
|
||||||
params.push_back("-y");
|
params.push_back("-y");
|
||||||
params.push_back(_output);
|
params.push_back(_output);
|
||||||
|
|
|
@ -51,6 +51,8 @@ private:
|
||||||
private:
|
private:
|
||||||
std::string ffmpeg;
|
std::string ffmpeg;
|
||||||
std::string _iparams;
|
std::string _iparams;
|
||||||
|
std::string iformat;
|
||||||
|
std::string input;
|
||||||
std::vector<std::string> vfilter;
|
std::vector<std::string> vfilter;
|
||||||
std::string vcodec;
|
std::string vcodec;
|
||||||
int vbitrate;
|
int vbitrate;
|
||||||
|
@ -66,8 +68,8 @@ private:
|
||||||
int asample_rate;
|
int asample_rate;
|
||||||
int achannels;
|
int achannels;
|
||||||
std::vector<std::string> aparams;
|
std::vector<std::string> aparams;
|
||||||
|
std::string oformat;
|
||||||
std::string _output;
|
std::string _output;
|
||||||
std::string input;
|
|
||||||
public:
|
public:
|
||||||
SrsFFMPEG(std::string ffmpeg_bin);
|
SrsFFMPEG(std::string ffmpeg_bin);
|
||||||
virtual ~SrsFFMPEG();
|
virtual ~SrsFFMPEG();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue