winlin

fix #119: use iformat and oformat for ffmpeg transcode.

@@ -649,6 +649,12 @@ vhost all.transcode.srs.com { @@ -649,6 +649,12 @@ vhost all.transcode.srs.com {
649 # whether the engine is enabled 649 # whether the engine is enabled
650 # default: off. 650 # default: off.
651 enabled on; 651 enabled on;
  652 + # input format, can be:
  653 + # off, do not specifies the format, ffmpeg will guess it.
  654 + # flv, for flv or RTMP stream.
  655 + # other format, for example, mp4/aac whatever.
  656 + # default: flv
  657 + iformat flv;
652 # ffmpeg filters, follows the main input. 658 # ffmpeg filters, follows the main input.
653 vfilter { 659 vfilter {
654 # the logo input file. 660 # the logo input file.
@@ -706,6 +712,12 @@ vhost all.transcode.srs.com { @@ -706,6 +712,12 @@ vhost all.transcode.srs.com {
706 # audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders 712 # audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
707 profile:a aac_low; 713 profile:a aac_low;
708 } 714 }
  715 + # output format, can be:
  716 + # off, do not specifies the format, ffmpeg will guess it.
  717 + # flv, for flv or RTMP stream.
  718 + # other format, for example, mp4/aac whatever.
  719 + # default: flv
  720 + oformat flv;
709 # output stream. variables: 721 # output stream. variables:
710 # [vhost] the input stream vhost. 722 # [vhost] the input stream vhost.
711 # [port] the intput stream port. 723 # [port] the intput stream port.
@@ -1965,6 +1965,20 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine) @@ -1965,6 +1965,20 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine)
1965 return true; 1965 return true;
1966 } 1966 }
1967 1967
  1968 +string SrsConfig::get_engine_iformat(SrsConfDirective* engine)
  1969 +{
  1970 + if (!engine) {
  1971 + return "flv";
  1972 + }
  1973 +
  1974 + SrsConfDirective* conf = engine->get("iformat");
  1975 + if (!conf) {
  1976 + return "flv";
  1977 + }
  1978 +
  1979 + return conf->arg0();
  1980 +}
  1981 +
1968 vector<string> SrsConfig::get_engine_vfilter(SrsConfDirective* engine) 1982 vector<string> SrsConfig::get_engine_vfilter(SrsConfDirective* engine)
1969 { 1983 {
1970 vector<string> vfilter; 1984 vector<string> vfilter;
@@ -2211,6 +2225,20 @@ vector<string> SrsConfig::get_engine_aparams(SrsConfDirective* engine) @@ -2211,6 +2225,20 @@ vector<string> SrsConfig::get_engine_aparams(SrsConfDirective* engine)
2211 return aparams; 2225 return aparams;
2212 } 2226 }
2213 2227
  2228 +string SrsConfig::get_engine_oformat(SrsConfDirective* engine)
  2229 +{
  2230 + if (!engine) {
  2231 + return "flv";
  2232 + }
  2233 +
  2234 + SrsConfDirective* conf = engine->get("oformat");
  2235 + if (!conf) {
  2236 + return "flv";
  2237 + }
  2238 +
  2239 + return conf->arg0();
  2240 +}
  2241 +
2214 string SrsConfig::get_engine_output(SrsConfDirective* engine) 2242 string SrsConfig::get_engine_output(SrsConfDirective* engine)
2215 { 2243 {
2216 if (!engine) { 2244 if (!engine) {
@@ -605,6 +605,10 @@ public: @@ -605,6 +605,10 @@ public:
605 */ 605 */
606 virtual bool get_engine_enabled(SrsConfDirective* engine); 606 virtual bool get_engine_enabled(SrsConfDirective* engine);
607 /** 607 /**
  608 + * get the iformat of engine
  609 + */
  610 + virtual std::string get_engine_iformat(SrsConfDirective* engine);
  611 + /**
608 * get the vfilter of engine, 612 * get the vfilter of engine,
609 * the video filter set before the vcodec of FFMPEG. 613 * the video filter set before the vcodec of FFMPEG.
610 */ 614 */
@@ -679,6 +683,10 @@ public: @@ -679,6 +683,10 @@ public:
679 */ 683 */
680 virtual std::vector<std::string> get_engine_aparams(SrsConfDirective* engine); 684 virtual std::vector<std::string> get_engine_aparams(SrsConfDirective* engine);
681 /** 685 /**
  686 + * get the oformat of engine
  687 + */
  688 + virtual std::string get_engine_oformat(SrsConfDirective* engine);
  689 + /**
682 * get the output of engine, for example, rtmp://127.0.0.1/live/livestream, 690 * get the output of engine, for example, rtmp://127.0.0.1/live/livestream,
683 * @remark, we will use some variable, for instance, [vhost] to substitude with vhost. 691 * @remark, we will use some variable, for instance, [vhost] to substitude with vhost.
684 */ 692 */
@@ -96,6 +96,7 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) @@ -96,6 +96,7 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
96 { 96 {
97 int ret = ERROR_SUCCESS; 97 int ret = ERROR_SUCCESS;
98 98
  99 + iformat = _srs_config->get_engine_iformat(engine);
99 vfilter = _srs_config->get_engine_vfilter(engine); 100 vfilter = _srs_config->get_engine_vfilter(engine);
100 vcodec = _srs_config->get_engine_vcodec(engine); 101 vcodec = _srs_config->get_engine_vcodec(engine);
101 vbitrate = _srs_config->get_engine_vbitrate(engine); 102 vbitrate = _srs_config->get_engine_vbitrate(engine);
@@ -111,6 +112,7 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) @@ -111,6 +112,7 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
111 asample_rate = _srs_config->get_engine_asample_rate(engine); 112 asample_rate = _srs_config->get_engine_asample_rate(engine);
112 achannels = _srs_config->get_engine_achannels(engine); 113 achannels = _srs_config->get_engine_achannels(engine);
113 aparams = _srs_config->get_engine_aparams(engine); 114 aparams = _srs_config->get_engine_aparams(engine);
  115 + oformat = _srs_config->get_engine_oformat(engine);
114 116
115 // ensure the size is even. 117 // ensure the size is even.
116 vwidth -= vwidth % 2; 118 vwidth -= vwidth % 2;
@@ -241,8 +243,10 @@ int SrsFFMPEG::start() @@ -241,8 +243,10 @@ int SrsFFMPEG::start()
241 } 243 }
242 244
243 // input. 245 // input.
  246 + if (iformat != "off") {
244 params.push_back("-f"); 247 params.push_back("-f");
245 - params.push_back("flv"); 248 + params.push_back(iformat);
  249 + }
246 250
247 params.push_back("-i"); 251 params.push_back("-i");
248 params.push_back(input); 252 params.push_back(input);
@@ -342,8 +346,10 @@ int SrsFFMPEG::start() @@ -342,8 +346,10 @@ int SrsFFMPEG::start()
342 } 346 }
343 347
344 // output 348 // output
  349 + if (oformat != "off") {
345 params.push_back("-f"); 350 params.push_back("-f");
346 - params.push_back("flv"); 351 + params.push_back(oformat);
  352 + }
347 353
348 params.push_back("-y"); 354 params.push_back("-y");
349 params.push_back(_output); 355 params.push_back(_output);
@@ -51,6 +51,8 @@ private: @@ -51,6 +51,8 @@ private:
51 private: 51 private:
52 std::string ffmpeg; 52 std::string ffmpeg;
53 std::string _iparams; 53 std::string _iparams;
  54 + std::string iformat;
  55 + std::string input;
54 std::vector<std::string> vfilter; 56 std::vector<std::string> vfilter;
55 std::string vcodec; 57 std::string vcodec;
56 int vbitrate; 58 int vbitrate;
@@ -66,8 +68,8 @@ private: @@ -66,8 +68,8 @@ private:
66 int asample_rate; 68 int asample_rate;
67 int achannels; 69 int achannels;
68 std::vector<std::string> aparams; 70 std::vector<std::string> aparams;
  71 + std::string oformat;
69 std::string _output; 72 std::string _output;
70 - std::string input;  
71 public: 73 public:
72 SrsFFMPEG(std::string ffmpeg_bin); 74 SrsFFMPEG(std::string ffmpeg_bin);
73 virtual ~SrsFFMPEG(); 75 virtual ~SrsFFMPEG();