From 9bf7b722db09a4dac809a3a944620eb9171b041b Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 19 Jul 2014 10:54:38 +0800 Subject: [PATCH] fix #119: use iformat and oformat for ffmpeg transcode. --- trunk/conf/full.conf | 12 ++++++++++++ trunk/src/app/srs_app_config.cpp | 28 ++++++++++++++++++++++++++++ trunk/src/app/srs_app_config.hpp | 8 ++++++++ trunk/src/app/srs_app_ffmpeg.cpp | 14 ++++++++++---- trunk/src/app/srs_app_ffmpeg.hpp | 4 +++- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index be6fedcf6..bce005529 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -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. diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 80d4d2ee3..03fbbb756 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -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 SrsConfig::get_engine_vfilter(SrsConfDirective* engine) { vector vfilter; @@ -2211,6 +2225,20 @@ vector 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) { diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index da510df57..461be847b 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -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 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. */ diff --git a/trunk/src/app/srs_app_ffmpeg.cpp b/trunk/src/app/srs_app_ffmpeg.cpp index 2db94a56a..134d5971b 100644 --- a/trunk/src/app/srs_app_ffmpeg.cpp +++ b/trunk/src/app/srs_app_ffmpeg.cpp @@ -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. - params.push_back("-f"); - params.push_back("flv"); + if (iformat != "off") { + params.push_back("-f"); + params.push_back(iformat); + } params.push_back("-i"); params.push_back(input); @@ -342,8 +346,10 @@ int SrsFFMPEG::start() } // output - params.push_back("-f"); - params.push_back("flv"); + if (oformat != "off") { + params.push_back("-f"); + params.push_back(oformat); + } params.push_back("-y"); params.push_back(_output); diff --git a/trunk/src/app/srs_app_ffmpeg.hpp b/trunk/src/app/srs_app_ffmpeg.hpp index 65cb06fc2..e9a50f5ce 100644 --- a/trunk/src/app/srs_app_ffmpeg.hpp +++ b/trunk/src/app/srs_app_ffmpeg.hpp @@ -51,6 +51,8 @@ private: private: std::string ffmpeg; std::string _iparams; + std::string iformat; + std::string input; std::vector vfilter; std::string vcodec; int vbitrate; @@ -66,8 +68,8 @@ private: int asample_rate; int achannels; std::vector aparams; + std::string oformat; std::string _output; - std::string input; public: SrsFFMPEG(std::string ffmpeg_bin); virtual ~SrsFFMPEG();